How to cast radios using Raspberry PI and use the phone as a remote

RS_player APP icon

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):

  1. install raspberryPI lite: 20xx-x-x-raspbian-stretch-lite.img. Download from this link:
  2. flash the img in the SD card: Format before the card with Fat32 with disk utility
  3. Use Etcher to flash the img in the sd card. Free download on
  4. put the SD card in raspberry PI and connect with a HDMI monitor or using the VGA adapter to a regular monitor with VGA output
  5. login using default user: pi and default password: raspberry
  6. from terminal: sudo raspi-config
  7. select "Interfacing Options" and Natigate and select SSH, choose yes
  8. always in raspi-config, boot option, B1 Desktop / CLI, Console autologin
  9. always in raspi-config, in network Options and after wi-fi, provide SSID and password of the home wifi
  10. reboot raspberry and control if wlan is assigned using the command "ifconfig", after try to ping a webpage e.g. ping to see if it is working
  11. sudo apt-get updade, sudo apt-get upgrade
  12. after 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")
  13. if you have the follow error "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" write ssh-keygen -R 192.168.X.XXX
  14. 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:
    and write at the end of the file:
    save the file: CTRL-X, Y and ENTER.
    - sudo service vsftpd restart
  15. use filezilla to enter in raspberry and save files
  16. sudo apt-get install vlc
  17. sudo apt-get --purge --reinstall install pulseaudio
  18. using ssh test the play with vlc:
  19. sudo apt-get install python3-pip python2.7-dev
  20. sudo pip install tornado
  21. 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
  22. from ssh: add the follow line "/home/pi/radioExec/ &" 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
  23. 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/", stdout=subprocess.PIPE, shell=True,preexec_fn=os.setsid)
                subprocess.Popen(str(message), stdout=subprocess.PIPE, shell=True,preexec_fn=os.setsid)

def socketloop():
    global io_loop
    global server
        app = tornado.web.Application(handlers=[(r"/", LedHandler)])
        server = tornado.httpserver.HTTPServer(app)
        io_loop = tornado.ioloop.IOLoop.instance()
    except RuntimeError:
        print("server already on")

if __name__ == "__main__":
        global io_loop
        global server
        global run
            run = 0
            while True :
                if run == 0:
                    print("  Started")
                    run = 1
                        print("Thread was already off")
                    our_thread = threading.Thread(target=socketloop)

        except KeyboardInterrupt:
            print("  Quit")

About Author

IPTV admin
I'm the administrator of this website

Leave a Comment

Your email address will not be published. Required fields are marked *