cesanta / mongoose-os

Mongoose OS - an IoT Firmware Development Framework. Supported microcontrollers: ESP32, ESP8266, CC3220, CC3200, STM32F4, STM32L4, STM32F7. Amazon AWS IoT, Microsoft Azure, Google IoT Core integrated. Code in C or JavaScript.
https://mongoose-os.com
Other
2.51k stars 429 forks source link

Support of HLW8012 energy meter #531

Open sebastien-savalle opened 4 years ago

sebastien-savalle commented 4 years ago

Hello,

Many devices (like Shelly 1PM or SonOff Pow R2) are using the HLW8012 sensor to monitor the power consumption. Would it be possible to integrate the HLW8012 library (https://www.arduinolibraries.info/libraries/hlw8012) to Mongoose OS ?

Thanks

pimvanpelt commented 4 years ago

I had it on my todo list (because I have those exact Shelly 1PM units), but I'm afraid I won't be able to get to it in the short term. I can work on this in ~June at the earliest, although it would be pretty straight forward to add because the chip is a straight forward I2C speaker. By the way, Shelly 2.5 uses ADE7953 which would've been the first one on my list to implement a driver for.

On Fri, Mar 20, 2020 at 11:35 AM ellavas notifications@github.com wrote:

Hello,

Many devices (like Shelly 1PM or SonOff Pow R2) are using the HLW8012 sensor to monitor the power consumption. Would it be possible to integrate the HLW8012 library ( https://www.arduinolibraries.info/libraries/hlw8012) to Mongoose OS ?

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cesanta/mongoose-os/issues/531, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDRSPMSSDKOHOFIK7ASY4DRINBINANCNFSM4LQIEOFA .

-- Pim van Pelt pim@ipng.nl PBVP1-RIPE - http://www.ipng.nl/

sebastien-savalle commented 4 years ago

Shelly firmwares are based on Mongoose, so it should not be too difficult to integrate it.

albanlud commented 4 years ago

That would be awesome to have this power monitoring available for Shelly 1 PM ! I can't wait !

pimvanpelt commented 4 years ago

I just submitted https://github.com/mongoose-os-libs/ade7953-i2c which is for Shelly 2.5 and confirmed working on my unit:

esp8266_10C60B 5329 1585312791.954 2|mgos_ade7953.c:105      val=4475 hertz=49.988831
esp8266_10C60B 5330 1585312791.961 2|mgos_ade7953.c:114      val=6101779 volts=234.683807
esp8266_10C60B 5331 1585312791.967 2|mgos_ade7953.c:130      reg=794 val=1773 amperes=0.017730
esp8266_10C60B 5332 1585312791.973 2|mgos_ade7953.c:130      reg=795 val=46998 amperes=0.469980
esp8266_10C60B 5333 1585312791.982 2|main.c:16               frequency=49.988831 voltage=234.683807 currentA=0.017730 currentB=0.469980

I do not currently have access to a spare Shelly 1PM for the HLW8012 driver. I've ordered a few units to be able to write and test the driver, and as soon as they arrive I'll work on that next.

rojer commented 4 years ago

this is great, i can integrate it into https://github.com/mongoose-os-apps/shelly-homekit now

pimvanpelt commented 4 years ago

By the way, Shelly 1PM seems to be based on BL 0937, not HLW8012, but they are often referenced together so likely the same interface. I will update this issue once I have my hands on either, but could probably use some help testing that one.

rojer commented 4 years ago

i only have 1 and 2.5 myself, unfortunately

albanlud commented 4 years ago

I got a "ready to be tested" shelly 1PM, so please do not hesitate to ask for help !

sebastien-savalle commented 4 years ago

I got a "ready to be tested" shelly 1PM, so please do not hesitate to ask for help !

Could you check which chip is soldered in the Shelly 1PM ?

albanlud commented 4 years ago

It is a BL 0937 ...

sebastien-savalle commented 4 years ago

I’ve ported the Arduino HLW8012 power meter sensor library.

It's working fine with the Shelly 1PM. (BL0937) You can have a look here:

https://github.com/ellavas/mongoose-lib-hlw8012

albanlud commented 4 years ago

Great job !!

rojer commented 4 years ago

interesting, i need to take a look. anychance you can integrate it into the firmware as well? i don't even have 1PM to test.