chebe: (VintageMoon)
2017-03-28 12:24 am
Entry tags:

Pimoroni Pirate Radio tweak; aka 'Talk to me Sweetie!'

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;
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 pip install pyttsx
sudo apt-get install espeak


Then save this as a file named myip.py (or whatever) into /usr/bin

#!/usr/bin/env python

import os, pyttsx, time

def read_ip():
f = os.popen('ifconfig wlan0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1')
your_ip=f.read()

engine=pyttsx.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.)
chebe: (HandAgainstGlass)
2016-12-12 11:25 am

Quantified Self and Fitbit sleep data

This weekend involved getting to see Placebo in concert, so not much else happened. But that's the great thing about software, you can be productive without getting out of bed.

I recently attended a Quantified Self meetup on sleep, that gave me the kick up the arse I've been needing. (Which was only compounded when I heard about Pebble closing, and that Fitbit would take over their servers, and staff.) One of the presenters talked about how he got his Fitbit data and how he analysed it. (If you're interested, slides are here, and blog post here.) He switched to using the official APIs when they became available, but I went with his original approach, a python program to log in and get your intraday data points instead of the aggregated stuff you get on the dashboard.

I haven't been the most steady wearable user, but there were a few months when I wore it reliably. Simply because I was sleeping terribly and wanted to understand just how badly. Although I never got around to actually analaysing the data, until now. (That's one thing about all these QS talks, typically everyone showing their data is the picture of good health. I'm more interested in seeing what it looks like when it goes wrong.)

I used the website dashboard to find the months that actually contained data. Then I exported csv files, month-by-month, using the official export option. This is the aggregated information, but it will be nice to see if it correlates with the intraday info.

Then armed with dates that contain valid data, I put them into the python program, and grabbed all my data. In short, download and extract the source code. In the same folder as setup.py create your own python file, where you will create your own client. (This information is apparently in the example files, but I poked around before I noticed that.) To create your own client you just pass in your email address and password;
client = fitbit.Client.login(email="bob@example.com", password="password")
You grab the specific info you're interested in;
client.intraday_sleep(date)
And then dump it to screen/file/whatever you want. Although it's a good idea to format it a little.

Sleep data is recorded as one value per minute.

# The different values for sleep are:
# 0: no sleep data
# 1: asleep
# 2: awake
# 3: very awake

# data will be a similar list of tuples, but spaced one minute apart
# [
# (datetime.datetime(2010, 2, 20, 23, 59), 2),
# (datetime.datetime(2010, 2, 21, 0, 0), 1),
# (datetime.datetime(2010, 2, 21, 0, 1), 1),
# ....
# (datetime.datetime(2010, 2, 21, 8, 34), 1),
# ]


And then, we are left with the task of analysing the data. Which is a much bigger one.