Raspberry Pi can be used for multiple purpose but this one of the most interesting: transform Raspberry PI to stream radio channel and use Android phone/tablet as a remote with the RS_player APP that you can download from here.
You can understand how to use RS_player APP from this post.
I suggest to use raspberry PI zero 2 w
with mini HDMI to HDMI adapter
and the HDMI to VGA adapter (with audio output)
the follow procedure is important to install in Raspberry all necessary SWs (from mac operative system):
install raspberryPI lite: 20xx-x-x-raspbian-stretch-lite.img. Download from this link: https://www.raspberrypi.org/downloads/raspbian/
flash the img in the SD card: Format before the card with Fat32 with disk utility
Use Etcher to flash the img in the sd card. Free download on
https://www.balena.io/etcherput the SD card in raspberry PI and connect with a HDMI monitor or using the VGA adapter to a regular monitor with VGA output
login using default user: pi and default password: raspberry
from terminal: sudo raspi-config
select "Interfacing Options" and Natigate and select SSH, choose yes
always in raspi-config, boot option, B1 Desktop / CLI, Console autologin
always in raspi-config, in network Options and after wi-fi, provide SSID and password of the home wifi
reboot raspberry and control if wlan is assigned using the command "ifconfig", after try to ping a webpage e.g. ping www.google.com to see if it is working
sudo apt-get
updade
, sudo apt-get upgradeafter try to connect with raspberry with ssh: ssh pi@192.168.X.XXX where 192.168.X.XXX is the IP address assigned to raspberry
(that you can get with command"ifconfig"
)if you have the follow error "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" write ssh-keygen -R 192.168.X.XXX
install FTP server with the follow istruction (from the file)
- sudo apt-get update
- sudo apt-get install vsftpd
- sudo nano /etc/vsftpd.conf and inside the file find uncomment:
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
and write at the end of the file:
user_sub_token=$USER
local_root=/home/$USER/ftp
save the file: CTRL-X, Y and ENTER.
- sudo service vsftpd restartuse filezilla to enter in raspberry and save files
sudo apt-get install vlc
sudo apt-get --purge --reinstall install pulseaudio
using ssh test the play with vlc:
cvlc http://dashitradio-de-hz-fal-stream06-cluster01.radiohost.de/dashitradio_128
sudo apt-get install python3-pip python2.7-dev
sudo pip install tornado
using FTP client (e.g.) FileZilla upload the folder "radioExec" in the folder /home/pi in raspberry. This folder is located here.
You need to unzip before
from ssh: add the follow line "/home/pi/radioExec/execRadio.sh &" at the end of the .bashrc (located in the /home/pi). You can use for example nano (or vim) in ssh or update the modified file using ftp
reboot raspberry
Once this procedure is fulfilled, raspberry PI is ready to play radio streaming and activate server to receive commands from RS_player APP.
This is the main part of the code in raspberry pi to allow playing music and connection with android app with web-sockets commands
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.websocket
import time
import threading
import subprocess, os
import signal
class LedHandler(tornado.websocket.WebSocketHandler):
def check_origin(self, origin):
return True
def open(self):
print("Connection opened from: {}".format(self.request.remote_ip))
self.write_message("Connection opened")
def on_close(self):
print("Connection closed")
def on_message(self, message):
global run
if run ==1:
print("Message received {}".format(message))
if str(message[:10]) != "Connection":
if str(message[:4]) == "cvlc":
subprocess.Popen("/home/pi/radioExec/findkill_channel.sh", stdout=subprocess.PIPE, shell=True,preexec_fn=os.setsid)
time.sleep(2)
print(str(message))
subprocess.Popen(str(message), stdout=subprocess.PIPE, shell=True,preexec_fn=os.setsid)
def socketloop():
global io_loop
global server
try:
tornado.options.parse_command_line()
app = tornado.web.Application(handlers=[(r"/", LedHandler)])
server = tornado.httpserver.HTTPServer(app)
server.listen(8000)
io_loop = tornado.ioloop.IOLoop.instance()
io_loop.start()
except RuntimeError:
print("server already on")
if __name__ == "__main__":
global io_loop
global server
global run
try:
run = 0
while True :
if run == 0:
print(" Started")
run = 1
try:
server.stop()
io_loop.stop()
except:
print("Thread was already off")
our_thread = threading.Thread(target=socketloop)
our_thread.start()
except KeyboardInterrupt:
print(" Quit")