Sunday, November 5, 2017

A smart watering system built on IBM Bluemix

In the last months, I spent some time building a prototype of a smart watering system. I had the idea while building a watering system for my plants, because the current technology has few drawbacks, like:
  • inability to remotely monitor the status of the plants;
  • inability to remotely configure the watering cycles (possibly basing the configuration on the current weather and the forecasts);
  • impossibility to remotely check if the system is delivering too much water (leakage) or too few (bottleneck).
These kind of problems can be quickly solved through an internet connected watering device. I just decided to build a prototype using some commercial components, an control board I developed, and a software stack built on the IBM Bluemix platform.

Architecture overview

The following picture provides an overview of the involved components:



Hardware and Software Components

The hardware of the prototype includes:
  • A Parrot Flower Power sensor, that collects multiple metrics about the air and terrain. It provides a bluetooth interface, to export data;
  • A 9V Gardena Irrigation Valve that allows very limited battery usage, requiring power only to open or close it (bistable);
  • A water flow sensor, to control the water delivery process;
  • An Espressif ESP32 controller, that offers both bluetooth and WiFi radios, together with very low power modes;
  • A control board that contains the controller plus an H-bridge, a Step-up voltage regulator, and few additional discrete components that generate the 9V impulses to control the valve opening and closing;
  • A solar panel, coupled with a battery and a charging circuit, that allow to provide continuous power to the control board.
On the software side the hearth of the system is the Watson IoT Platform, available as a service on Bluemix. More in details the software stack includes:
  • The Watson IoT Platform service available on IBM Bluemix (free trial). The Watson IoT Platform is responsible for registering the devices, collecting data and delivering commands;
  • A Cloudant DB that stores historical data; it is also available as a service on Bluemix. The Cloudant DB integrates seamlessly with the Watson IoT platform, thanks to some pre-built recipes that require just very few clicks for the deployment;
  • A nodeJS application, also deployed in Bluemix through the NodeJS container, that provides access control the to the collected data;
  • A mobile application based on Xamarin Forms that allows to access the collected data and to control the configuration of the devices and their watering cycles.
The system prototype is now built inside of a large plant pot, that allows to move it around for demonstration:

How the system works

The hearth of the system is the control board that has multiple roles. It collects data coming from the sensors, using the bluetooth interface, and uploads them to the Watson IoT platform using the WiFi radio. It is also responsible for receiving the commands from the Watson IoT platform, commands used to configure the watering cycle or execute it. The additional circuitry is responsible for generating the appropriate impulses (voltage and current) for opening or closing the valve.

The nodeJS application provides a front end to the Watson IoT platform, in order to allow every user to access just the data collected from the devices he owns. When I started building this prototype, the Watson IoT for electronics offering was not yet available so I built on my own few of the functions that are now offered out-of-the-box by this new service. The nodeJS application implements a set of REST APIs that allow user login, access control to device data, retrieval of historical data and submission of commands.
The nodeJS application interacts both with the Watson IoT Platform and the Cloudant DB in order to retrieve the required data and submit the commands. It completely hides these two services in order to properly enforce a more granular access control.

The mobile application offers a graphical interface to the nodeJS REST APIs. As a first step a user has to login into the mobile application (which corresponds to a login to the nodeJS REST APIs). Then he has the ability to monitor the last collected data or generate graphs for the historical data, with the possibility of scrolling data day by day. The graph are generated based on the data stored in the Cloudant DB, while current data are retrieved directly from the Watson IoT platform.
The mobile application allows also to start a watering cycle; the command is delivered to the control board through the Watson IoT Platform and it is possible to monitor (in quasi real time) the watering process, i.e. the amount of water delivered and the water flow. If the water flow is too high, the system can have a water leakage, while a below the average flow can indicate either a low pressure or a bottleneck in the tubes. While the system currently does not generate any alert, in the future the flow data can be used to generate a notification to the user's mobile phone, to alert him of a dangerous condition.

In the next weeks I plan to provide more details about every component of the system, posting the schematics and the source code of each one of them. Stay tuned.

No comments:

Post a Comment