letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.27k stars 2.21k forks source link

MODBUS support #1017

Open s0170071 opened 6 years ago

s0170071 commented 6 years ago

I have conducted some experiments on my SMA STP5000TL solar inverter and found that it can be probed easily using MODBUS /TCP. See this entry in the forum https://www.letscontrolit.com/forum/viewtopic.php?f=6&t=4960&p=25485&hilit=sma#p25485 While I was just quick and dirty assembling the frame, there could be a more general aproach to support modbus.

LeeNX commented 6 years ago

I have some Estron power meters and RS485 serial interface devices, which could come handy if there is anything that is not too hard to put in place on a NodeCMU device for testing. Will try and keep an eye on this issue.

LeeNX commented 6 years ago

I know there has been some great work on #1625 and scheduling, but wondering if there might have been any progress on the ModBus support? Put some time aside this weekend to get a PoC hardware up before deploying in the house DB box and hoping I might be able to deploy with ESPEasy.

Thanks for all the hard and great work!!

TD-er commented 6 years ago

Not yet. Recently I have been brushing up my Modbus code a bit, which I wrote about a year ago for the new Senseair sensors (K33 et.al.) See https://github.com/TD-er/ESPEasy/tree/feature/MODBUS_enhancements The current Modbus in ESPeasy main repo is more about RTU over ethernet and the code I wrote for those Senseair modules is about RTU over UART. I still have to find a way to merge those into a good interface.

But to be honest, I want to improve stability of the existing code first to get a release out, which is really way overdue. So first:

There is some support in the playground if I am not mistaken for the Eastron DIN meters. https://github.com/letscontrolit/ESPEasyPluginPlayground/blob/master/_P150_SDM120C.ino Not sure if those are the Modbus or the M-bus versions of those meters.

LeeNX commented 6 years ago

Thanks @TD-er !

Been keeping a voyeur eye on the issue queue and mails and I thank You and everybody doing their little bit, either by testing or reporting back!! You are all Awesome!!!

Please don't think I am complaining, just poking and hoping that when there is nothing else to work on, maybe we could make some progress on this issue ... ;-)

Going to see if I can get a PlayGround build going or switch over too https://github.com/reaper7/SDM_Energy_Meter but it does not have all the bits of ESPEasy like mqtt and things, but really need to pull info from my meters!!

If you need anything tested, I should be around, just shout.

s0170071 commented 6 years ago

+1 for the stable release :-P

LeeNX commented 6 years ago

Friday afternoon trying to build a firmware was unsuccessful. Lack of knowledge or some issue on my local machine not helping.

Going too have to wait until somebody with more skill and/or time can poke at this issue.

I will check back when I have some time, but in the meantime, going to use reaper7's lib and modified example with Telegraf-HTTP for metric capture.

TD-er commented 6 years ago

If you find something that wasn't obvious connecting the Eastron meter to the ESP when running the reaper firmware, please also share it here :)

LeeNX commented 6 years ago

Spent the weekend setting up my PoC for testing hardware and software. Ran into some stability problems with my NodeMCU WiFi, but I am not sure if this something in my toolchain or the newer/different NodeMCU device.

Wondering if when we include ModBus support, would we not just target the Eastron power meters or this would make the ESPEasy firmware possible too big? Basically just thinking about all the read registers of the Eastron meters - https://github.com/reaper7/SDM_Energy_Meter/blob/master/SDM.h#L50

Or would we just have a set of interfaces to registers and format of registers for reading?

Have not yet even thought about writing into the ModBus devices ... Not sure if that is even worth thinking about?

s0170071 commented 6 years ago

related: https://github.com/letscontrolit/ESPEasy/issues/1466

TD-er commented 6 years ago

I am not sure if I get what you meant to write, but maybe it will be clear when I explai a little about the current state of how ESPeasy does handle sensors.

On top of that, there are some rules that can act on events or timers and perform actions like taking plugin values and sending them to controllers, etc.

There are sensors that provide a lot more sensor data than the 4 available value positions, so we still have to think about how to handle those. That's not yet a solved question.

LeeNX commented 6 years ago

Thanks both @s0170071 and @TD-er ! You both send me down another rabbit hole!! ;-)

Write options was more me thinking about getting something into the Eastron Meter, as there is an option to set things like secondary pulse option rate or other things, but you are quite right, that would be out of scope for ESPEasy, don't mind my rambling.

Maybe I should move my question about supporting the large number of registers per ModBus device too #1466 ... It was just some brainstorming that left me with questions.

I had done this before without the NodeMCU using python in OpenHAB, but every stormy season, my USB RS485 adapter would be hit by lightning and I would be without data again. Moving too NodeMCU and WiFi data collection using ESPEasy, I am hoping will remove the smoking electronics problem.

As for offering any ideas on how to support more ModBus devices or attribs/registers, is a little outside of my wheelhouse.

TD-er commented 6 years ago

You can ofcourse let a plugin send some parameters to the sensor device. For example the SDS011 (dust sensor) and INA219 (Energy) do have such an option. Also some plugins accept commands (sent from rules or other routes) which can be used to set some settings a bit more dynamically.

I guess changing settings on an Eastron meter doesn't have to occur that often, so either way could be acceptable.

LeeNX commented 6 years ago

ModBus relay? ;-)

Using ESPEasy platform as a bridge ... Crazy ideas

LeeNX commented 6 years ago

Just received another MODBus/RS485 Meter DDS-238-2 ZN/S, which I am thinking of hooking up to my eBike charger, so I know how much power/currency I am converting.

Need to track down a manual and see how much might need to be done?

Will start looking at this issue soon, thou I have so many things planned!!

LeeNX commented 6 years ago

Link too ModBus Registers for DDS-238-1 ZN/S http://domoticx.com/modbus-kwh-meter-dds238-1-zn/

Hope this is the same as DDS-238-2 ZN/S, soon too test, I hope.

IoTPlay commented 5 years ago

Dis you make any progress?

TD-er commented 5 years ago

For Modbus RTU, I made a separate interface, which is now used by the SenseAir plugin. I'm also working on using that library to work with a MAX485 to address the DC power measurement units made by AccuEnergy. So for the Modbus RTU part, there is some active development. N.B., that's different from the Modbus TCP, as mentioned in the topic start of this issue.

mttstt commented 5 years ago

I made a plugin for Aurora Inverter Power DC. This is ok but there is a low memory problem, perhaps the plugin uses too many resources. To go I need delete some other plugin on a wemos 4M. Probably the new Modbus RTU class can resolve my problem. But I am not able to implment it.

https://github.com/mttstt/remote-control-shutters/blob/master/ESP8266/Espeasy%20Plugin/_P111_Aurora.ino

TD-er commented 5 years ago

@mttstt Maybe you can open a new issue about it. The update of ModbusRTU is not yet merged (worked on it last night) so the patch to use the DE/RE pin is not yet included in the mega repository. You can see the progress here: https://github.com/letscontrolit/ESPEasy/pull/2439 (and also get some inspiration)

One thing that's consuming a lot of memory is all the strings you're using. None of them are wrapped in F() macro tags, so they will be put in memory and not just read from flash.

pite81 commented 5 years ago

I am not sure if I get what you meant to write, but maybe it will be clear when I explai a little about the current state of how ESPeasy does handle sensors.

  • A plugin provides connection to a sensor device and is responsible for taking samples and collecting them in ESPeasy.
  • A plugin presents up-to 4 float values as sensor values and optionally provides those samples to one or more controllers.
  • A controller is responsible for sending values to another host in a specific format using a specific protocol (e.g. Domoticz HTTP/Domoticz MQTT/Thingspeak/etc.)

On top of that, there are some rules that can act on events or timers and perform actions like taking plugin values and sending them to controllers, etc.

There are sensors that provide a lot more sensor data than the 4 available value positions, so we still have to think about how to handle those. That's not yet a solved question.

I just try to work around the Eastron SDM630, managed to flash a firmware (ESP_Easy_mega-20190523_test_core_260_sdk222_alpha_ESP8266_4M.bin) but it keeps crashing, nothing connected yet. Even on soft reset, it struggles, only a cold start help it to recover. I have tried to upload a custom sketch with Arduino following this, https://www.letscontrolit.com/wiki/index.php/Tutorial_Arduino_Firmware_Upload. came up with an error. Same error in platformio. The goal would to disable the unwanted modules and plugins and use the ones I need to increase stability. Ideally, I just need an SDM630 and DS18, DHT22 for this purpose. I will measure the status of a heat pump, ie power consumption, the temperature of the hot water cylinder, temp and hum of the utility room. That is it. Some reason the older version ESP tend to solid and does not require a restart, the 2019 version crashes a lot. Any possibilities for that? Thanks for the brilliant firmware! You are a Genius!

TD-er commented 5 years ago

Maybe you should have a look at the Vagrant build option About the restarts. The last few weeks/months we've made quite a lot of progress in reducing the number of restarts. Most of them appeared to be related to WiFi and how it is handled.

I am not entirely sure how the SDM plugin does handle not connected modules.