Introduction
Over the past few months I have created an easily expandable, well scaling and easy to optimize solution for controlling and otherwise bringing together a wide range of disparate devices.
With it one can gather data from all kinds of sensors (e.g. light, noise, pollution, position, etc) to keep a log, or aggregate data and display them in a centralized manner as well as make things happen in real life, for example lock/unlock things, or manage a workflow.
In the following few articles I would like to share it in the hope some may find it useful and inspirational.
More than a year ago (as many others interested in embedded electronics and gadgets) I started experimenting with some ESP8266 based modules, starting with the ESP-01 module. I soon moved on to more powerful modules such as the ESP-07, ESP-12, ESP-12E, WROOM-02 and lately I have been working with the ESP-12F modules. These modules have progressively more on-board flash memory (for programs), more GPIO available for the end user (me), and also have better antennas. Since these modules are ridiculously inexpensive (less than USD 3 a piece) compared to their abilities, I constantly keep an eye on any new versions that may be even better.
Unfortunately (and this is probably the only bad thing I can say about these modules), most modules’ pin spacing are not 0.1mil (2.54mm), making them difficult to use them on breadboards, so they need some sort of an adapter. Some of these modules are pin compatible with each other (or very close to that) so I created a couple of development boards to speed up prototyping:
Using these development boards (or breakout boards) I have created some basic projects, each focusing on a certain aspect of the ESP chip. Then it occurred to me: Why not combine all of these and create something more flexible, more useful?
This is how ActoSenso Platform was born.
System architecture
The ActoSenso Platform is a combination of a number of hardware and software components:
Hardware
ActoSenso Server
At the center there is a server computer that has three primary functions:
- Stores historical data of any kind (for example, if temperature sensors are used, any previous temperature readings are stored in a database and can be retrieved at will).
- Negotiates the flow of commands/data to and from each ActoSenso node.
- Keeps a log of all things going on in the system. This feature helps troubleshoot difficult-to-track problems. The more complex the hardware and software components, the more this helps to get to the root of a problem.
ActoSenso nodes (or simply “nodes”)
ActoSenso nodes (nodes that are part of the ActoSenso Platform) are small devices that are placed in strategical locations to perform a limited set of functions. Although in most cases a ActoSenso node would perform a few tasks only (say measure a temperature and report it back to the server), there is nothing to prevent one to create very sophisticated ActoSenso nodes that perform a host of tasks. Normally, I would leave the heavy lifting for the central computer as it is far more powerful and much easier to program than a ActoSenso node, but there are situations when you may want to move some business logic to it. Such example would be a standalone ActoSenso node, which I will discuss later.
ActoSenso nodes perform one or more of the following tasks:
- Gather sensor data from a variety of (digital or analog) sources
Example: Detect if a particular switch is on/off, light/noise level of a room. - Control actuators
Example: Switch lights on/off, display useful information on a display. - In case of standalone ActoSenso node, perform some business logic
Example: Room temperature control, plant watering automation.
So far all ActoSenso nodes I have created are ESP8266 based, but this is purely my preference (for the tasks I use them for). One can use whatever hardware they like.
Software
One of the main goals of this project was for me to learn new technologies, languages, systems, processes. After having evaluated several development environments, workflows, I ended up using the following programming languages, tools and technologies in the development of the ActoSenso Platform:
- As an IDE (Integrated Development Environment) I use Atom text editor with PlatformIO plugin. This makes firmware development a breeze for the ESP8266 chips.
- To develop the firmware for the ActoSenso nodes I use an Arduino-style c++. Never before had I developed in c++, nor had I used an Arduino.
- To style the web pages for both the ActoSenso nodes and the server I use Bootstrap. It’s amazing, how nice Bootstrap makes the ugliest, most boring web pages with almost zero effort and zero graphic design background!
- I use PHP on the ActoSenso Server for creating interactive web pages to view and control the ActoSenso Platform – another first time experience.
- Data on the ActoSenso Server are stored in a MySql database. I had previously worked (professionally) a lot with Microsoft SQL Server, but migrating my knowledge to MySql did take some time.
- ActoSenso nodes communicate with the ActoSenso Server using MQTT, which is an open source, lightweight and reliable M2M protocol. Another first timer for me.
- I use Mosquitto as the server component responsible for smooth MQTT communications.
- I also run a Node-RED server on my ActoSenso Server. Node-RED is built on Node.js, and provides a visual, in-browser tool to create the “glue” between the ActoSenso nodes and the ActoSenso Server. (More details about this later.) Yet another new technology for me.
As best practice, I also try to use as many software components that are heavily tested and widely used as possible to minimize the chances for introducing new issues to my code. Here is a list of software components I have used in one or more parts of the ActoSenso Dallas Temperature Control library
- ArduinoJson library
- OneWire library
- PubSubClient library
- Time library
- My sunset and sunrise calculations are based on this algorithm.
- Chart.js for displaying various charts on the management console
All of the above software libraries are open source and I also make all the code I have developed open to everyone who wishes to study, check, improve or otherwise use it.
Result
Combining all the above hardware and software elements, technologies I got a system that is:
- Flexible: ActoSenso nodes can be made as simple or as complex as it is required.
- Cheap: ActoSenso nodes are based on Espressif’s ESP8266 chip, which is less than USD3. Depending on the other components added to a ActoSenso node for a specific purpose, even in small quantities, the total cost of an ActoSenso node is much more affordable than comparable commercial systems.
Pretty much any computer can be used as a ActoSenso Server: Any old PC/laptop that needs a new purpose, a Raspberry Pi or similar credit card sized computer, or – if you don’t need to much computing power for your business logic – you can even do away without a ActoSenso Server. - Scalable: Virtually any number of ActoSenso nodes can be added to an automation project.
- Self contained: It is my view that any decent home automation should depend on as few external services as possible. My solution depends on only power and local wi-fi. It does not depend on an ISP, or any other “cloud” service provider for the business logic.
In the next article I will show what ActoSenso nodes are and how they work.