Pimoroni Pirate Radio tweak; aka 'Talk to me Sweetie!'
2017-Mar-28, Tuesday 12:24 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
You know what's super annoying? Not knowing the ip-address of the server you're trying to access. I could scan the network and find the right machine. But, I'm lazy. And, the server knows its own ip, it should simply tell me.
This is something I believed my Pirate Radio could manage. When the pHAT BEAT bonnet gets installed it sets itself up with a daemon in /usr/bin. Technically I installed it twice (once for spotipy as well). I don't know if the code differs, but as I installed vlc-radio last, that's the code I will play with.
Think it through. I've just booted up the server. The volume and power buttons do very necessary jobs, so we'll leave them alone. The fast-forward and rewind buttons start playing a station/cycle through stations. Very useful if you can't be bothered finding the ip-address. That leaves Play/Pause, which doesn't do anything until a station has started streaming. And if I have access to the web interface, well I can do that very job there. That's it, I'm sacrificing Play/Pause!
In the end I simply replaced line#204 with a call out to my script;
(making sure to import it at the top of the file. Let's hear it for the wonders of Open Source!)
What script you ask? A simple one, to parse the wlan0 ip from ifconfig, and then a call to text-to-speech to actually read it out loud to me.
You'll probably need to install the text-to-speech stuff;
Then save this as a file named myip.py (or whatever) into /usr/bin
And sure, give it a reboot to make sure the changes are picked up.
Now, when I press play the Pirate Radio reads out its ip-address to me! So handy.
(Note; if you press play with monitor and OTG cable attached, it'll probably crash and reboot. So don't do that.)
*edit* 2020-07-10
*edit* 2021-08-12 python3 version
*edit* 2021-11-21 proper python3 version
This is something I believed my Pirate Radio could manage. When the pHAT BEAT bonnet gets installed it sets itself up with a daemon in /usr/bin. Technically I installed it twice (once for spotipy as well). I don't know if the code differs, but as I installed vlc-radio last, that's the code I will play with.
Think it through. I've just booted up the server. The volume and power buttons do very necessary jobs, so we'll leave them alone. The fast-forward and rewind buttons start playing a station/cycle through stations. Very useful if you can't be bothered finding the ip-address. That leaves Play/Pause, which doesn't do anything until a station has started streaming. And if I have access to the web interface, well I can do that very job there. That's it, I'm sacrificing Play/Pause!
In the end I simply replaced line#204 with a call out to my script;
myip.read_ip()
(making sure to import it at the top of the file. Let's hear it for the wonders of Open Source!)
What script you ask? A simple one, to parse the wlan0 ip from ifconfig, and then a call to text-to-speech to actually read it out loud to me.
You'll probably need to install the text-to-speech stuff;
sudo pip3 install pyttsx3
sudo apt-get install espeak
Then save this as a file named myip.py (or whatever) into /usr/bin
#!/usr/bin/env python3
import os, pyttsx3, time
def read_ip():
f = os.popen('ifconfig wlan0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1')
f = os.popen("ifconfig wlan0 | grep 'inet ' | awk '/inet/ {print $2}'")
your_ip = f.read()
if not your_ip:
your_ip = "not online"
engine = pyttsx3.init()
engine.say(your_ip)
engine.runAndWait()
time.sleep(3)
print your_ip
if __name__ == '__main__':
read_ip()
And sure, give it a reboot to make sure the changes are picked up.
Now, when I press play the Pirate Radio reads out its ip-address to me! So handy.
(Note; if you press play with monitor and OTG cable attached, it'll probably crash and reboot. So don't do that.)
*edit* 2020-07-10
*edit* 2021-08-12 python3 version
*edit* 2021-11-21 proper python3 version
no subject
Date: 2017-07-28 07:04 pm (UTC)https://www.mopidy.com/authenticate/#spotify