Ship IoT with Imagination Creator Ci20 as IoT Gateway for Philips Hue bulb
We've been having some fun with the Philips Hue smart lighting system and I wanted to expand the interactivity beyond the local office WiFi network. We had an Imagination Creator Ci20 (version 1) board available, so I thought it would work as a good gateway to pull data from the Philips Hue bridge and send it to some online services with one of the wot.io data services; bip.io.
To keep it simple, I decided to share one value, the current hue setting of a single one of our lights (see the Hue documentation for details on how it defines light values). To get the value, I wrote a Perl program on the Ci20 to connect to the Hue gateway using the Device::Hue module. The program finds the correct light (we have several), pulls out the hue value, and then sends it along to our bip.io instance set up for Ship IoT. My bip then calls Numerous and updates my hue metric.
First I set up the bip so I would have an endpoint to send data to. It's a simple one with a web hook (HTTP API) for input and a single call to Numerous. The Numerous pod configuration involves activating the pod with your Numerous developer API key, creating a number in Numerous, then providing the metric id for your number created in the Numerous app as a configuration to the configured pod (see the video for details).
If you're not familiar with Numerous, it's a mobile app that displays individual panels with important numbers on each panel. If you install the app and search on "wot.io" you'll find our shared "wot.io Buffalo Hue" number. Then you can see how our Hue changes and maybe set one of your lights to the same color as ours.
Once the bip is created, you have an endpoint. Next is to send data to it using the Ci20 board and a short Perl program.
The Ci20 board uses a MIPS processor and runs Debian out of the box. Add a monitor, keyboard, and mouse and you're ready to go. The board has wifi connectivity, so once the Debian desktop came up, I used the desktop GUI tool to connect the board to the same network the Hue gateway runs on.
Perl is part of the standard install. There are many ways to install the Device::Hue module, cpanminus is likely the fastest:
sudo apt-get install curl
curl -L https://cpanmin.us | perl - --sudo App::cpanminus
cpanm --notest --sudo Device::Hue
You can find the program I used in the wot.io github project. The values you need to run it are all listed at the top:
- Base URL of the Hue bridge on your network
- A username or "key" for the Hue bridge (instructions)
- The name of the light you want to pull data from
- URL of your bip endpoint and token
Once it's configured, you can run and your hue value is updated on Numerous!
Another interesting idea to extend the project is to schedule a job in cron, store the hue value, and send updates only when the value changes. It would also be fun to set up an endpoint on the Ci20 to receive a value back and set the hue value. Maybe a project for next time, or maybe someone will beat me to it and send me a pull request.