Internet of Pi's is a blog about my experiments with building an IoT (Internet of Things) using MQTT as the protocol between the IoT and the cloud platform Heroku. This IoT is an Internet connected Lamp which can be controlled from anywhere at anytime. Built using a Raspberry Pi. I have been calling it the Internet of Pi (IoP) for pun.
Below is a short video of the Internet of Pi in action.
The Internet of Pi app takes a snapshot of the Lamp after switching it on or off in response to user action and then broadcasts the picture to all watching clients.
Picture of the lamp when switched on.
Here you can see many subscribed clients interacting with the Internet of Pi app.
Here is the NFC tag in the living room used to turn the lamp on/off in action.
Before getting into the details of the Internet of Pi, some thoughts on IoT. My thoughts are based out of my own experience, gut feeling plus influence reading up on IoT.
As with any new wave of innovation there are new buzzwords, predictions etc. plus there will be use cases mentioned about what it can do and how it is going to transform the world we live in. Same with IoT, i came across these use case of the toaster going on when you walk into a room and the refrigerator ordering more eggs when it runs out of them - these are not very convincing use cases for IoT. In my opinion, the real value in the IoT revolution lies elsewhere.
The advent of Big Data i.e the possibility to store and process Terabytes or Petabytes of data made possible by technological advancements and availability of open source software in the area of distributed computing has made business intelligence and analytics at scale possible. The combination of Big Data and Machine Learning (at scale) used in an IoT context is the real game changer. Using Predictive models to analyze sensor data and making decisions based on the measurements is something which is definitely going to shape how some industries will be using IoT.
I have read about some very interesting use cases for IoT in the Health and Medicine, Agriculture, Mining, Transport industries. Predictive maintenance is one interesting use of IoT.
Switching on a Lamp at your home from a mobile device on the go - is it a good use case for IoT?. This is just a fun experiment which was a learning experience for me on how to use a Raspberry PI as an IoT, read up on IoT protocols like MQTT, figuring out how to run services reliably on the "thing" etc. I have definitely learned a few "things" while building the Internet of Pi.
The app is deployed on Heroku which is a good PaaS provider for quick prototyping.
I showed this project to a few of my friends/colleagues and some of my colleagues asked - is the Lamp really going on/off at your home? That kicked off another round of weekend hacking on the Pi, to add "Pi Photo Service" to take a photo with a timestamp after the Lamp goes on/off.
The Pi runs two services:
1) the "Lamp Control Service" to switch the lamp on/off.
2) the "Pi Photo Service" to take photo's off the camera connected to the Raspberry Pi.
The "Pi Photo Service" is a standalone service and the co-ordination happens at the server running on Heroku Cloud platform. There is a If This Then That kind of logic which triggers the "Take photo" event when the lamp is switched on/off.
Microservices on the Raspberry Pi
Developing the "Pi Photo Service" as a separate (micro) service meant that I could first of all reuse this service elsewhere and also update and release them on to the Pi independent to the "Pi Lamp Control Service". Secondly, there is no tight coupling between those 2 events ("Lamp state change" and "Take photo event" - the logic of what to do when is managed/configured elsewhere (i.e on the App server).
Below are notes on how the Internet of Pi application works. The entire application including the services running on the Pi are written in node.js - Javascript everywhere app!
There are 2 components that make the entire Internet of Pi app.
1) The Internet of Lamps app running on Heroku has a Websocket and MQTT module to connect to clients (browsers/mobile apps) and to the MQTT broker respectively. This app is written in node.js.
2) Two services running on the Raspberry Pi
Below is a short video of the Internet of Pi in action.
The Internet of Pi app takes a snapshot of the Lamp after switching it on or off in response to user action and then broadcasts the picture to all watching clients.
Picture of the lamp when switched on.
Here you can see many subscribed clients interacting with the Internet of Pi app.
Here is the NFC tag in the living room used to turn the lamp on/off in action.
The ingredients of the Internet of Pi app:
- A Raspberry Pi
- A Relay - to switch the lamp on/off via the GPIO pins on the Raspberry Pi
- A Camera - connected to the Pi to take photos of the Lamp which is then uploaded to Amazon S3
- MQTT broker - for receiving and sending MQTT encoded messages. The protocol used between the device and Internet of Pi service running on Heroku is MQTT.
- Websockets for publishing updates in near real-time to subscribed users
- NFC tag for toggling the Lamp (on/off) when in proximity with a NFC enabled phone
- Amazon S3 - used by the Pi for uploading photos of the lamp
- Heroku - A cloud PaaS provider
Before getting into the details of the Internet of Pi, some thoughts on IoT. My thoughts are based out of my own experience, gut feeling plus influence reading up on IoT.
As with any new wave of innovation there are new buzzwords, predictions etc. plus there will be use cases mentioned about what it can do and how it is going to transform the world we live in. Same with IoT, i came across these use case of the toaster going on when you walk into a room and the refrigerator ordering more eggs when it runs out of them - these are not very convincing use cases for IoT. In my opinion, the real value in the IoT revolution lies elsewhere.
The advent of Big Data i.e the possibility to store and process Terabytes or Petabytes of data made possible by technological advancements and availability of open source software in the area of distributed computing has made business intelligence and analytics at scale possible. The combination of Big Data and Machine Learning (at scale) used in an IoT context is the real game changer. Using Predictive models to analyze sensor data and making decisions based on the measurements is something which is definitely going to shape how some industries will be using IoT.
I have read about some very interesting use cases for IoT in the Health and Medicine, Agriculture, Mining, Transport industries. Predictive maintenance is one interesting use of IoT.
Switching on a Lamp at your home from a mobile device on the go - is it a good use case for IoT?. This is just a fun experiment which was a learning experience for me on how to use a Raspberry PI as an IoT, read up on IoT protocols like MQTT, figuring out how to run services reliably on the "thing" etc. I have definitely learned a few "things" while building the Internet of Pi.
The app is deployed on Heroku which is a good PaaS provider for quick prototyping.
The Pi runs two services:
1) the "Lamp Control Service" to switch the lamp on/off.
2) the "Pi Photo Service" to take photo's off the camera connected to the Raspberry Pi.
The "Pi Photo Service" is a standalone service and the co-ordination happens at the server running on Heroku Cloud platform. There is a If This Then That kind of logic which triggers the "Take photo" event when the lamp is switched on/off.
Microservices on the Raspberry Pi
Developing the "Pi Photo Service" as a separate (micro) service meant that I could first of all reuse this service elsewhere and also update and release them on to the Pi independent to the "Pi Lamp Control Service". Secondly, there is no tight coupling between those 2 events ("Lamp state change" and "Take photo event" - the logic of what to do when is managed/configured elsewhere (i.e on the App server).
Below are notes on how the Internet of Pi application works. The entire application including the services running on the Pi are written in node.js - Javascript everywhere app!
There are 2 components that make the entire Internet of Pi app.
1) The Internet of Lamps app running on Heroku has a Websocket and MQTT module to connect to clients (browsers/mobile apps) and to the MQTT broker respectively. This app is written in node.js.
2) Two services running on the Raspberry Pi
A high level architecture of the Internet of Pi app.
Below are the sequence of events that happen when a user switches on the lamp.
- There is an HTTP encoded message going from the browser/mobile app to the Internet of Lamps application on Heroku with the action indicating there is a request to switch the lamp ON.
- The Internet of Lamps app on Heroku now Publishes a MQTT message to the MQTT Broker. I have used https://www.cloudmqtt.com/ as the MQTT broker for this app.
- The Pi only talks MQTT - a protocol used in IoT applications. The Pi is SUBSCRIBE'd to topics on the MQTT broker.
- The Pi turns the GPIO pin ON and PUBLISH'es a "lamp on" message to the broker, which is picked up by the Internet of Lamps app running on Heroku.
- The Internet of Pi app on Heroku first NOTIFY's the client (browser) that the Lamp is now ON. It then runs the event through the ITTT (If This Then That) engine and decides that it needs to take a photo of the Lamp now!
- The Internet of Lamps app now sends a message back to the Pi over MQTT to take a photo which is now picked up by the "Pi Photo service"
- The Pi Photo service takes the photo of the lamp and then uploads it to Amazon S3. It then PUBLISH'es a message back on the broker that there is a new photo available for viewing.
- The Internet of lamps app now broadcasts a message over Websockets to all connected clients that a new photo is available for display.
- The client (Browser) fetches the image from S3. (This can be avoided by the app fetching the image from S3 and serving it)
I would be open sourcing the application and the code will be on Github soon.I will build docker images for the services running on the Raspberry Pi so that it can be run without much hassle.
Also, add some notes on how to put this all together to get a working Internet of Pi.
Picture of the NFC tag in the living room
Also, add some notes on how to put this all together to get a working Internet of Pi.
Picture of the NFC tag in the living room




