Part 5 - Bluemix and the Internet of (50000 small) Things: Finalizing the Bluemix solution
Contents
Part 1: An introduction to BeeSpiPart 2: The BeeSpi hardware
Part 3:Configuring the Pi software
Part 4: Completing the Pi software
Part 5: Finalizing the Bluemix solution
If you've been following along and made it through the last part, you'll already have your Raspberry Pi sending sensor data to the Internet of Things Foundation on Bluemix. This final part describes how to use the captured data. What we'll do is capture the data in a database, and create a REST API to retrieve the temperature values and display them as a graph on the page.
To create the application flow, we need to start the Node-RED editor on Bluemix, similar to what we did on the Raspberry Pi. The URL to go to is
http://<appname>.myblumix.net/red
Of course, everything is on GitHub - download the source from there: if you copy the contents of bluemix.flow and import it into your Node-RED flow editor, you'll get the following:
This shows three flows:
- The first flow captures data sent by the Raspberry Pi over MQTT to the IBM IoT. It's then manipulated a little and then saved to the database. Since the IoT connection is defined at the project level, it's really simple to attach it to here- you don't even have to define the authentication explicitly:
The connection to the database is also simple - it's the only available database
- The second flow shows two REST services which retrieve the temperature and humidity readings from the database, returning them in a form that can be manipulated on the web page. This, of course, can lead to difficulties if there is a large amount of data and the web page cannot process it quickly enough
- The third flow shows another REST service which calls a remote REST service on the Raspberry Pi, returning the response.
- Twitter Bootstrap to ensure that the page is responsive
- JQuery for the usual web functions
- Google Charts to provide the graphic representation of the temperature and humidity data
The page streams from the camera to a graphic on the page, and the current temperature is retrieved using the REST API and displayed using a gauge widget. All the other temperature and humidity values are charted as line graphs, resulting in a page that looks like:
Conclusion
The application is tracking two hives, but I've had to split my hives because they were about to swarm - I now have four and a nucleus (a mini-hive). In the process the camera was exposed to the rain, so it's stopped working. If I can't repair it, I think instead I'll put a camera watching the hive entrance instead: that's probably more interesting at this time of year anyway.
Bee Factoid: When bees start to get active in the spring, they reproduce not only using the usual egg-laying method, but also spread by splitting the colony. What happens is that they decide that the colony is growing too large and the workers build special elongated cells called queen cells. When an egg has been laid in the cell and it hatches (after three days), the workers feed the larva with royal jelly for a further five days whereupon the cell is sealed.
At this point the queen and most of the foraging workers load up on honey and head off as a swarm. The bees are actually quite docile because of the ingested honey, so they're no real danger. The swarm hangs out on a nearby tree (or car or bicycle) while the scouts search for a suitable home. This is an extraordinarily democratic process - when a scout finds somewhere she thinks is suitable, she does the famous waggle dance to tell the other scouts. They don't take her word for it, but all go check it out for themselves. When the scouts are pretty much unanimous about the choice, the swarm moves off to their new home.
In the meantime, the queen cell will hatch after eight days and thew new queen will be ready to mate about five days later. If there are other queen cells (and there usually are), secondary swarms (called casts) may leave when they hatch, assuming that the new queen doesn't kill them first!
Of course, beekeeping would be much less successful if the bees all decided to move on, so a technique known as an artificial swarm makes the bees think they've swarmed, but in reality they've simply been moved into another hive. I had to do this with both of mine, so now I have four.
At this point the queen and most of the foraging workers load up on honey and head off as a swarm. The bees are actually quite docile because of the ingested honey, so they're no real danger. The swarm hangs out on a nearby tree (or car or bicycle) while the scouts search for a suitable home. This is an extraordinarily democratic process - when a scout finds somewhere she thinks is suitable, she does the famous waggle dance to tell the other scouts. They don't take her word for it, but all go check it out for themselves. When the scouts are pretty much unanimous about the choice, the swarm moves off to their new home.
In the meantime, the queen cell will hatch after eight days and thew new queen will be ready to mate about five days later. If there are other queen cells (and there usually are), secondary swarms (called casts) may leave when they hatch, assuming that the new queen doesn't kill them first!
Of course, beekeeping would be much less successful if the bees all decided to move on, so a technique known as an artificial swarm makes the bees think they've swarmed, but in reality they've simply been moved into another hive. I had to do this with both of mine, so now I have four.
The amount of data that I have to process in the web page now means that the performance is rather poor, so be patient if you visit. I think I need to change the way that's done, moving the processing back to the database and perhaps even using a more traditional RDBMS.
I think there may well be another part in this sequence of articles!
Comments
Post a Comment