A couple of months ago my brother-in-law asked me if I could write some simple code for his RaspberryPi to count the electric pulses from his kWh energy meter so he could replace his YouLess Energy monitor and also monitor a second meter in front of another solar panel setup on the roof of his garage. Discussing this at work, one of my colleagues suggested an ESP8266 chip which is smaller and easier to fit in a DIN-Rail Enclosure. Another advantage is the absence of an (Linux) OS so it needs less maintenance then the RaspberryPi. He had some of these chips at home and promised to bring one the next day.
Next day he gave me a ESP8266 ESP-12 development board which contained an ESP8266 chip, an USB serial connector and lots of GPIO pins. This was reason enough to investigate how the ESP8266 chip works and how it can be directly programmed (not with Arduino). The first option was to test it with the pre-installed NodeMCU LUA interface. The second option was to download a cross-compile toolchain with the Espressif IoT C SDK and program it in C. Since I'm more familiar with C then LUA, I started to write some sample programs in C and played with all the available ESP tools. One week later my colleague provided me an extension cord with a kWh meter in between so I could write some interrupt code and test the s0 pulses with my girlfriends hairdryer :-) This was the beginning of the esp8266-pvoutput-logger project.
The ESP8266 ESP-12 development board:
Next day he gave me a ESP8266 ESP-12 development board which contained an ESP8266 chip, an USB serial connector and lots of GPIO pins. This was reason enough to investigate how the ESP8266 chip works and how it can be directly programmed (not with Arduino). The first option was to test it with the pre-installed NodeMCU LUA interface. The second option was to download a cross-compile toolchain with the Espressif IoT C SDK and program it in C. Since I'm more familiar with C then LUA, I started to write some sample programs in C and played with all the available ESP tools. One week later my colleague provided me an extension cord with a kWh meter in between so I could write some interrupt code and test the s0 pulses with my girlfriends hairdryer :-) This was the beginning of the esp8266-pvoutput-logger project.
The extension cord and kWh meter:
Not much later I ordered a set of solar panels and a electric car. I asked the solar panel guy to place a kWh meter between the solar panel setup and deliver an extra one so I could place it after the power socket on the shed to monitor the charging of my car. I wired separate ESP8266 development boards on every meter, connected them to a Raspberry Pi (so I can upload the code) and resumed coding and testing.
For the solar panels I implemented a pvoutput.org client and for the car I wrote a thingspeak.com client. To control the current power and total energy value postings I wrote a scheduler and queueing mechanism which posts them nicely on a certain timestamp every 5 or 15 minutes. It also resets the values between queueing and at the end of the day when everything needs to be zero again. To cover server or internet problems the values are stored in a queue which will be re-posted when the connection is ok again.
Another goal was to keep track of the current status of the chip and running code. For this I used 4 different colored LEDs and wired them to the GPIO pins on the chip. They show the current power status, wifi status, error status and power pulses. More information about this can be found in the README on GitHub.
The DIN-Rail Enclosure of my solar panels with the connected ESP8266 chip and LED's:
And this is the final result of the DIN-Rail Enclosure of my solar panels:
The code runs stable for a couple of months now on my solar panels and car setup. Meanwhile my brother-in-law replaced his YouLess Energy monitors with 2 ESP8266 chips and LED setup.
Another thing worth to mention is that the total costs of this setup (this includes the ESP8266 development board, the LED's, the wires and the USB adaptor) came around EUR 10,-. But if you are handy with a soldering iron and buy loose ESP8266 parts instead of the whole development board then the costs would be around 2/3 of this.
Another thing worth to mention is that the total costs of this setup (this includes the ESP8266 development board, the LED's, the wires and the USB adaptor) came around EUR 10,-. But if you are handy with a soldering iron and buy loose ESP8266 parts instead of the whole development board then the costs would be around 2/3 of this.
For anyone who is interested in building a similar setup (or something different), the code is open source and can be found on GitHub:
No comments:
Post a Comment