The GidTech Where-U-At 2000™
I was asked recently if it was possible to track a group of users via their mobile phone locations, and plot them on a public web page. One of our clients was interested in having their agents displayed on a web map like Uber drivers, so a visitor to the website could contact their nearest agent for an immediate consultation. Of course this would be with consent and appropriate privacy limits.
Anyway, as Google Location Sharing gives private users that very capability, it should be possible to access that data and do stuff with it, right? Well, unfortunately (and unsurprisingly) Google don’t have an API for such sensitive information.
However, by building such great Developer Tools into Chrome, it’s fairly straightforward to figure out how to spoof their internal API to get the data: merely copy the session cookies and parse the data that comes back. It’s a shame they don’t have a reliable API for this, so I’m not comfortable using it for a paid project that our client might rely on.
There are, of course, third-party apps for Fleet Management and user tracking, and I think if the client wants to go ahead with this project, I’ll be recommending one of those. It’ll also give the tracked users better control as well as increased accuracy: Google Location Sharing, it turns out, is not very accurate, as they’ve balanced precision with battery usage carefully for the average user.
Anyway, with two senior-citizen parents, I could also do with the ability to track them just in case they get lost or need help. I’m also happy for them to know where I am so they can plan accordingly if I’m driving back from somewhere… I mean, if I had anything to hide, I’d know how to turn off Location Sharing!
To recap earlier posts, for most of my Internet-of-Things / Smart Home experiments I use an MQTT server — Mosquitto — that receives data from environmental sensors and other data feeds, and a Node-RED environment to wrangle it all. I have a number of “status display panels” — the GidTech Pi-Clock-o-Matic 2000™ — for displaying this information: LCD panels in black boxes, red-tinted so they don’t disturb while I’m asleep.
For the customer requested project above I implemented a proof-of-concept in NodeJS, along with a Slack bot /where is
To benefit from the existing (hack job) code I’ve written for my home devices, I rewrote the code in Python. This makes frequent checks of Google Location Sharing and publishes changes to MQTT. This script runs on the same machine as the MQTT server, but it could be run anywhere on my network.
The other thing I really wanted on this display was a summary of our family’s calendar entries for the days ahead. For a while I’ve considered putting a screen on the refrigerator door, but this new project seems ideal.
Getting a simple ics feed from Google is easy enough, and the icalendar module in Python can read it well enough. Managing to parse and grok recurring events, however, is an extremely complicated procedure. After trying to do it by hand, I discovered dateutil.rrule. This doesn’t combine perfectly with icalendar, mainly due to incompatibilities with timezones (offset-aware and offset-naïve clashes) but it was relatively straightforward to get it working.
Fortunately, being the UK, dealing with the calendar in UTC is relatively painless. I don’t expect much trouble when we switch to British Summer Time at the end of this month, but I do expect it’ll need a few tweaks.
So, a script runs regularly on the same server as the Location Sharing script that frequently downloads the ics files, parses them, checks for changes, and publishes the next 90 days of appointments as a block in easy JSON format to MQTT.
By doing these two data-gathering tasks “centrally” on a wired server, the same information can be mirrored to several displays in the house without repeating the downloading job.
I had a spare 7.5” LCD screen for a prototype:
For fun I hooked up a spare Pimoroni Inky-pHAT but it’s nowhere near big enough to be useful for this particular installation. I might use it for a desk appliance version, though.
For the hallway, I wanted something a little bit cleaner and unobtrusive. I’ve wanted to have a go with ePaper displays for a while, and Waveshare 7.5” ePaper displays with Raspberry Pi compatibility are available via Amazon.
I ordered one of these a while ago, and tried it out, but unfortunately it didn’t survive being in a box for a few weeks, and no longer works no matter what I try. That’s £60 down the drain, unfortunately. Because I’d removed a socket from the pHAT (which I’m sure had nothing to do with the failure) I couldn’t really return it under guarantee.
I ordered another, and it worked for one test and then a component on the back of the pHAT got very *very *hot (burning my thumb in the process) and the screen filled with noise: back to Amazon for a refund.
Third time’s a charm, and the screen now works. I ordered a cheap picture frame at the same time, and it fits pretty damn well. I ordered another Raspberry Pi Zero W, and configured it to access my home network. At the same time, I took the opportunity to make a more standard setup routine for my Raspbian installations, so if the microSD card gets corrupted, I can recreate it easily. I’ve had a few microSD card failures recently, with a couple being replaced under guarantee.
(Incidentally, I really wish Raspbian would add just one hook to automatically run a script placed in /boot on first start-up to configure a fresh device. PiBakery hasn’t been too reliable for me, and it’s a pain to have to manually ssh in just to bootstrap the installation. It would be so easy to add a .service file into the standard installation, just like sshswitch.service.)
(I also wish the RPF would release a properly-commercial Raspberry Pi Zero W rather than their limited stock approach that I understand is a loss-leader. They have an idiosyncratic bulk purchase scheme where the price of the Pi Zero W goes up as you increase quantity, which is to discourage bulk purchase eating into the profit-making full-size Pi, but the Zero W on its own (without headers) is a great piece of kit that I’d be prepared to pay £15+ for if I could legitimately buy a few of them in one order. I have bought more than one, and it makes me sad that in doing so I’ve lost the Foundation some money, and wasted shipping cost. Please release a “retail” Pi Zero W with black PCB in quantity for ~£15 that’s just more expensive for the sake of making a profit rather than a loss. I understand the Pi Zero WH is effectively this, but still…)
I taped off the edges of the frame with white gaffer tape — like Duct Tape, but more cloth-based — and it looks surprisingly good. I used the same tape to cover a flat USB cable across the wall to the corner, run it down to a power outlet near the floor; a low-profile iPhone power adaptor supplies the low power the Pi and the picture frame needs, while being small, flat and inconspicuous.
The screen only updates when it needs to; in other words, when the scripts detect change. This is because the screen in question takes a few seconds, and it’s visually distracting when it does so:
This is also why I went with the two-colour screen rather than the very pretty three colour red/white/black or orange/white/black options, which take 5–10 times longer. As far as I can see, the Waveshare screen doesn’t support partial updates; the documentation says it can’t, and I can’t find any details in the code that suggest it might be hackable. I’m afraid I don’t have the time, patience, oscilloscope, or gigantic brain of Ben Krasnow.
(He’d probably be able to make use of my apparently-buggered screen too. Hmm.)
Anyway, it seems to work for now, and I’ll continue to tweak. Being a wireless device, I can reprogram it remotely, and even test the software by redirecting the image to a Preview.app window with im.show().
The code I’ve used is a massive hack job at the moment. I’m intending to clear it up a bit and pop it up on GitHub in time. Because it’s a mash-up of a lot of bits and pieces, the code is likely to remain fairly messy, but I could still do some work on it.
In hindsight I think it would have been cheaper, easier and better to buy a Kindle, jailbreak it and use it as the picture frame instead. The screen is better, faster, supports greyscale, and it’s more robust. I still could’ve built the wooden surround. At the time, however, I had most of the parts necessary to build it, and if I hadn’t broken the first screen, it would’ve been cheaper. I might still try to pick up a second-hand Kindle to give it a go…
Been There, Done That?
https://magicclock.de/ : A sweet project by some students in 2012. They used a custom app, not unlike the app I wrote for Project 125 (oh, I’ve never mentioned that, have I…?) rather than just hacking into Google Location Sharing, which is now a thing.
One of these days I might try to resurrect Project 125. You’d like it. I just ran out of spoons.
So what else is new?
Another project I’ve completed recently is the GidTech Thermoroid 2000™ Thermal Camera, which uses an Adafruit HUZZAH32 Feather with an AMG8833 8x8 thermal camera sensor. Again, I spent more on parts and time than just buying a low-end thermal camera, dammit.
I found time (and parts) to finish the Volt-U-Like 2000™ bench power supply; again, a project that would’ve been cheaper and better just bought off-the-shelf from Amazon. It’s so easy to see a cheap thing like those neat variable power supply modules, and forget how much the connectors, the switches, the wiring, the enclosure, the mains power supply, and so forth all cost.
I know it’s meant to be more fun building it yourself, but with my health being not ideal, it’s a major drag. I want to keep my time for things that I can’t buy, because no-one makes them yet!
I’ve also been working on fitting nine GY-521 (MPU-6050) accelerometers to the slats of my bed with the aim of feeding them into a neural net to detect when I’m sleeping in a bad position for my back. This was also the idea behind the thermal camera: I hoped it would be just enough information to detect shape of my body heat to do the same job.
Previously, I attempted to fit a 32 x 32 matrix of copper tape separated by pressure-sensitive conductive plastic (the black stuff they make anti-static bags from) to detect a map of my sleeping position, but ran out of time and stamina to spend on a project I wasn’t too sure about anyway. Still, it looks cool.
Unfortunately, the journey to getting my back fixed has had another hitch, meaning more surgery is on the cards. It turns out I now have some loose metal rattling around in there, and it hurts. So, these big fun projects are just not an option anymore.
I still intend to get some data into a neural network with the aim of detecting body position and correcting it. I’m just not sure what form that will take, and absolutely no idea when I’ll be able to get to it. There are a number of other projects on my desk that need finishing off before I go under the knife again, including the “Epoch-o-Clock 2000™” and the continual improvement of the “Page-Turn-O-Matic Air™”.
Update, March 2018
Unfortunately, the ePaper frame started degrading in quality about a week after I fitted it. As I’ve already had a number of failed units, I sent it back for a refund, and I’ve refactored the code as a web app. Now, a dedicated (hacked) Amazon Fire 7 displays the web app as a full-screen kiosk mode. It’s less geeky than the ePaper display, but it does mean I was able to add some extra interactive features: a clock, Google Maps, weather display (which expands to a full day’s forecast on click), and a scrollable calendar pane.
I’ve also refactored the code to use Docker for serving the scripts and the web app.
Update, October 2018
Thanks to aceisace on Medium (on an earlier posting of this article) it looks like the problem with the ePaper screen was due to lack of
epd.sleep() calls, wearing it out prematurely. Damn.