The flat in the cloud
How can you make a smart home smarter? Bring it to the cloud!
So far, living in our smart flat has been pretty awesome. For the most part, we have been using openHAB for day-to-day home automation or IFTTT for some simple automated tasks (e.g. controlling our Philips Hue lighting system using a smartwatch or making our SONOS sound system play a song every time someone tweets something with the hashtag #Project365d). What these approaches have in common, is that they allow integration and co-operation of off-the-shelf systems and sensors, for example Koubachi’s soil-moisture sensor and the Philips LivingColors can be both connected to openHAB, so that every time the soil in the pot of our plant is dry (which is pretty much always), the color of LivingColors becomes red. Inevitably, what these approaches also have in common is the high cost of the products involved, as well as the complexity of using bindings to co-ordinate the operation of many different systems at the same time in openHAB.
Wouldn’t it be nice, however, if we could just buy inexpensive sensors of any type we fancy and hook them up together to quickly implement some crazy idea that would dawn on us in a lazy afternoon? Wouldn’t it be even nicer if we could furthermore keep track of our sensors’ data, or even interact with our smart home from afar? We most certainly thought so, so we decided to bring our smart flat to the next level: into the cloud!
What would be some practical applications of having a bunch of different sensors lying around in one’s apartment? Well, imagine a lighting system which would turn on or off the lights based on a combination of data like brightness, detected motion and sound in each room. Or a heating/air-conditioning and ventilation system that would regulate itself or simply send us a reminder to open a window based on readings of humidity, temperature and dust in the air. Of course, the type and number of sensors required would vary according to the needs of the specific application. Passionate gardeners would probably prefer to ditch the motion sensor in favor of a soil-moisture sensor, which combined with readings of brightness, temperature and humidity in the air would provide a decent monitoring of the state of their plants, possibly growing in a remote greenhouse.
Moving to the cloud
The “cloud” is a pretty neat buzzword and all, but does it offer any additional benefit? Aggregating this data on the cloud, apart from allowing us to impose simple automation rules and trigger notifications whenever some values exceed some predefined bounds, would also provide us with an overview of the evolution of our living conditions over time and let us discover patterns in our daily interaction with our living environment, while at any time we would be able to switch on/off a device from any place in the world and observe the outcome real-time. To come back to the gardening example, by examining the data someone (possibly with the help of a machine learning algorithm) could infer that during the summer months, moisture in the soil lasts longer if the plants are watered overnight instead of mid-day. Also, a malfunctioning valve in the watering system would be timely discovered without having to visit the greenhouse itself. Obviously, asset management would be of much greater importance for production/industrial applications, e.g. think of farmers instead of gardeners.
The IoT platform
So there we were, looking for a sturdy and comfy cloud to host our sensors’ data. Thankfully, the good people of Swisscom ENT-BIZ (thank you Mario Schmuziger!) offered us some space on theirs. The Swisscom IoT cloud is powered by the Telit IoT Portal, a unified platform of services developed by deviceWISE that allows seamless integration of any edge-device, production asset or remote sensor (i.e. any “thing”) with any app or back-office system. It provides a broad spectrum of helpful management features for interconnected “things”, covering connection metrics, geofencing, event-based triggers and alarms, two-way interaction and tunneling (i.e. data forwarding) between remote devices/gateways and data visualization, among others.
Communication between the devices and the IoT portal is achieved using the MQTT protocol, which is a very lightweight (with respect to code footprint and network bandwidth) application layer protocol, especially developed for machine-to-machine (M2M)/”Internet of Things” connectivity. Alternatively, the platform also supports a rich REST API, to be used over HTTP. The packet payload consists of JSON objects, the format of which is defined by a protocol called TR50.
The main component of our data collection platform is a microcontroller, namely the Texas Instruments MSPP430F5529LP, as part of the TI Launchpad Evaluation Kit series. Its cost, together with the WiFi module, amounts to just a little more than CHF 30. On the Launchpad we mount the Seeed Grove shield, which is a platform that allows direct connection of a very large variety of modules (sensors and actuators, such as ultrasonic rangers, relay switches, motor drives, soil-moisture sensors and many more) over a 4-pin standardized interface. The starter’s kit, which includes 10 different modules, costs a little less than CHF 60 (for the sake of comparison, the motion – brightness sensors from HomeMatic, which we are currently using for controlling the light over openHAB, cost CHF 66 apiece).
The modules which we decided to connect with the Launchpad include: a PIR motion sensor, a brightness sensor, a temperature and humidity sensor, a microphone and a buzzer (which we could use to issue some simple alarms), all visible in the image below:
Streaming the data
After putting together the hardware platform, in addition to the standard C/C++ libraries for the microcontroller and the WiFi module, streaming our data required downloading driver libraries for some of the Grove modules (and even fixing a couple of bugs in them here and there 🙂 ), as well as the deviceWISE library for turning our Launchpad into an MQTT client.
All in all, our Launchpad publishes the following types of messages: log messages, location details (admittedly, not particularly useful in the case of a smart home application, but a little more so if the “thing” was mounted on a truck), attributes (key-value pairs where the value is a “thing”-specific string, e.g. a MAC address or serial number) and properties, which are key-value pairs that constitute our sensor measurements themselves. Alarms, e.g. in the case that some measurement exceeds a predefined value, may also be sent as messages, but we preferred to let the IoT cloud platform issue and handle alarms by itself. The actions triggered by an alarm, such as setting “thing” properties (for example this could mean starting a motor) or sending an email, could all be set from within the IoT portal environment or using the REST API.
After all was said and done, how can we visualize our data? Using the IoT Portal, we have designed a dashboard which provides a quick overview. It looks like this:
But you don’t have to take my word for it, check out the real-time data yourself here!
You will need the following credentials to login:
Username: email@example.com Password: 123guestuser123!
Can you discern some patterns in the data? To me, it’s literally like looking for patterns in the cloud(s)…