Close

Refactoring with Node-RED and MQTT

A project log for Internet-of-Things Power Meter

Simple, cheap, easy to build and deploy, the IoT Power Meter provides accurate statistics on household power consumption.

SolenoidSolenoid 09/09/2017 at 22:350 Comments

I've recently learned how to use Node-RED and MQTT and I wanted to try them out in. I decided to refactor this project as it was difficult to maintain the way it was made. I was pleasantly surprised, actually this was exactly what I had imagined from the start:

My goal was to build a system that I could check whenever I wanted, from any platform and that did not require any additional infrastructure or services. That's why I aimed at a self-contained system to log, serve a webpage and publish data to the cloud.

Doing all this on an ESP8266 was possible, but challenging. Indeed, it did not handle concurrent web requests or large data transfers well, uploading data to Google Spreadsheets was riddled with obstacles (because of SSL), logging methods and space were limited and testing was bothersome.

Node-RED allowed to unload the hard work form the ESP, actually it was simply a matter of publishing MQTT messages to a broker and the rest of the program could be "written" on the Node-RED server:

This had many advantages:

As I had a Raspberry Pi running 24/7 to handle various things around the house it was simply a matter of installing Node-RED and the MQTT broker and point the IoT Power Meter to the server.

A final note on this log: this project has made me much more aware of my energy consumption, how much certain things around the house consume and what it costs me. I started this project as a learning opportunity and a fun way to do something potentially useful. I now realise its true potential is to give me an incentive on getting the lowest numbers possible.

Discussions