Counting pulses from an electricity meter

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
torwag
Posts: 216
Joined: Fri Dec 13, 2013 9:25 am

Re: Counting pulses from an electricity meter

Post by torwag » Tue Nov 12, 2019 7:35 am

Hi,

is there any reason you want to write to your influxdb database every 250ms?
The ESP should be powerful enough to do the math and e.g. send an average value every minute.
Or, if you really want to get all the raw data, you could create a buffer and send 100 values in one go, which would result in a connection every 25 seconds.
The ESPs are known not only for notorious wifi outages, but also the internal housekeeping which can conflict with micropython and its tasks. It might be that by rare chance you run into a situation, where this conflicts. Very hard to debug and not much one could do about it.
Thus, I would agree with pythoncoder and try to make your code as fail-safe as possible. Sending only every minute, gives you enough time to reset the microcontroller and restart the measurement in case any of your safety protocols triggers.

User avatar
pythoncoder
Posts: 3718
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Counting pulses from an electricity meter

Post by pythoncoder » Tue Nov 12, 2019 7:55 am

The micropython-iot library may be found here.

Indeed, looking at the big picture I can't see any good reason for sending data at such a high rate. Not least because 3.6KW for an entire house is a fraction of the worst-case load. My kettle alone takes 3KW ;) Maybe your system croaks when you make a cup of tea while the microwave is running and someone else vacuums...

Your ESP8266 is a 32 bit computer: until recently the stuff of dreams. Why not use a tiny fraction of its capability to reduce the worst-case data rate to something more manageable?

A simple algorithm would be something along these lines. Maintain a count of pulses. Once a minute, if count > 0, send the count and reset it to zero. Implemented with care, no pulses will be lost. You trade being unable to track usage at a 250ms rate for higher reliability. With resilient MQTT the application could cope with WiFi outages: with some attention to detail outages could be handled without loss of pulses.

As an aside, this project is an entirely different way of solving the same problem. This uses a clip-on current transformer and phase sensitive detection to measure power. It could equally be applied to an entire house with no disruption to the wiring.
Peter Hinch

User avatar
ghayne
Posts: 38
Joined: Sat Jun 08, 2019 9:31 am
Location: Cwmllynfell, Wales

Re: Counting pulses from an electricity meter

Post by ghayne » Tue Nov 12, 2019 2:54 pm

pythoncoder wrote:
Tue Nov 12, 2019 7:55 am
The micropython-iot library may be found here.
I think I will have to bite the bullet and go down that road Peter, I have given up on the high speed streaming version, as torwag stated, the ESP's are not the most reliable for WIFI connections.

The combination Pyboard > ESP is also something I am considering (I HAVE put a Pyboard D on my Chrismas list :D )

Garry Hayne

Post Reply