Logging your energy consumption over time

For now, we built a smart plug that has more or less the same features as a commercial smart plug: it can control a device, measure the power consumption of this device, and also comes with a nice graphical interface. In this section, we are going to go further, and see how we can easily add functions to our project with some lines of code.

As an example, we are going to see how to log the measurements made by the board into a database on the Pi so that those measurements can be recalled later. As the code for this section is really similar to the previous section, I will only highlight the main changes here.

Start by importing the required module for the database:

var Datastore = require('nedb') db = new ...

Get Building Smart Homes with Raspberry Pi Zero now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.