This module builds upon the excellent node-serialport module to read packages from the P1 port of a smart energy meter. This port is a serial port, and spits out information message every 10 seconds. This module reads those messages and emits events whenever a new meter reading comes in. Data is nicely formatted in a js object.
npm install p1reader
To open the serial connection, and start reading messages
var P1Reader = require('p1reader');
// Set up the reader with serial port
var p1Reader = new P1Reader('/dev/ttyUSB0');
// Listen for events
p1Reader.on('reading', function(data) {
console.log('new reading', data);
});
// Open serial port, and start listinging for incoming messages
p1Reader.open(function(err) {
console.log('opened', err);
});
The reader emits the following events:
reading
- For every received message (should come in every 10 seconds)electicity
- for every electricity reading (every 10 secs)gas
- For every gas reading (my meter reports a new gas reading every hour)close
- When the serial connection gets closed for some reasonerror
- When the serial connection emits an error
An event for electricity gets emitted with the following information:
{ date: Tue Mar 03 2015 16:31:23 GMT+0100 (CET),
t1used: 3231.628,
t2used: 3038.542,
t1returned: 0,
t2returned: 0,
currentTarif: 2,
currentlyUsing: 140,
currentlyReturning: 0 }
In my case tarif 2 is during peak times, tarif 1 is my off-peak (evenings, nights and weekends) usage.
While an event for a new gas meter reading contains the following information:
{ date: Fri Apr 03 2015 16:00:00 GMT+0200 (CEST),
used: '02066.247' }
A reading
event contains both gas and electricity readings in a single package
Here are some sites I used to gather all required information in order to make this module (and build a required serial->usb converter)
- maartendamen.com Explanation on how to convert a FTDI cable to read a smart meter
- gejanssen.com - Dutch explanation about reading a smart meter
- node-serialport - Explains how to get nodejs running on a Raspberry Pi