May 8, 2015

Power Meter pulse logger with ESP8266 running NodeMCU

This device is installed in my home to monitor the usage of electricity. It counts the pulses from the meter and produces a log file with number of pulses and a time stamp that can later be analyzed. The hardware is quite simple. The NodeMCU development kit board with an ESP8266 running the NodeMCU firmware is connected to a phototransistor with an pull-down resistor. The firmware and my lua script seems stable since it has been running for more than 10 days without problems.

The phototransistor used is PT204-6C. It is aimed at the pulse windows on the power meter.

I also working on a php script that produces a diagram.

Below is the NodeMCU lua code. Pin 1 is set to generate an interrupt on the rising edge. I had some issues with pulses counted multiple times probably due to bounce in the input signal. I have solved this by only inrement the counter if there is a gap of 20 ms or more between interrupts since the pulse is about 10 ms wide. This is done with the method described in my previous post. Every 60 seconds it also loads a webpage with a php script that writes to a log file.elog.lua

This is the php script on the server. It has a simple security feature with a secret key to avoid bots bloating the log. The firmaware loads the url:http://your-host.com/logdata.php?timestamp=1111&key=your-key&counter=8888
The script extracts the parameters from the url and creates an entry in a file. There is a new file create every 24 hour.logdata.php