-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add modbus support #1618
feat: add modbus support #1618
Conversation
Hi @mheyse - I looked through the code the best I can and it looks solid. A few points:
|
Hi, thanks for the review.
Not sure when you looked at it, maybe my last commit was not in there yet? In this commit I changed the configuration from using a std::map to just an initializer list (to save on RAM), and all registers are defined using the
What exactly would such a test look like? Are you talking about automated tests that run during a CI build, or something "hands-on"? Currently I use a very simple C# program (using the EasyModbusTCP library) to connect to the EMS-ESP and read out some values. "cybcon/modbus-server" is a server, wouldn't we need a client for such a test? There's also the pyModbusTCP (haven't looked at it yet) that should allow to easily implement a Modbus client in Python. Would this be something of a test?
I can keep working in my repo, and I'll keep it in sync with the dev branch. I have one more question regarding addressing the individual devices: The HTTP API and the MQTT connector access devices by device type and not the device address or id (which is what I implemented in the Modbus connector) - the API path is something like |
5f3571f
to
c17e06a
Compare
Hi, the Modbus interface currently seems to do what I want it to do - reading and writing entities works in my tests as expected. The two big things missing are
Re. configuration UI: Could you give me a hint what's the mimimum that needs to be implemented to have a simple on/off switch for the Modbus component? Looking at the mqtt configuration user interace code it looks pretty involved. There's only very few parameters that can be configured (enabled, TCP port, max. num of clients, timeout). Re. documentation: Where is it stored, how do I contribute? I'd like to generate a Modbus register doc from dump_entities.csv automatically, and additionally write a bit about the interface in general. Thanks! |
This is going to be an awesome addition, nice work!
|
Can you tell me where you get the compile error, is it in I replaced the |
Regarding the config UI: The parameters that should be configurable are defined at the beginning of
Configuring |
I see the issue, the platformio EDIT forget that, the gn++17 is included. And it compiles fine on my MacBook, just not on Linux/Ubuntu. As for settings, we can add to Settings like we do with SysLog and just set enabled/disabled, port, maxClients and the timeout? |
So now I'm confused does it compile or not? :-) I can try it on Ubuntu, too, if needed. |
there's a typo at Line 46 in 14af4a0
with the extra "s" which is preventing the |
7e6e8ea
to
1ceaa95
Compare
For the settings, create modbus_ and add to Once they are settings variables, I can build the WebUI section. Some memory comparisons (flash/ram and build and heap/max alloc mem during runtime) on ESP32-S3 and a normal ESP32 would be useful to see. |
@mheyse if you want some help with the Settings let me know |
I didn't have time to look at it until now - I had to move to a Windows PC from Mac, and now I can't get the firmware to build at all any more, I always get a I also tried building in WSL2/Ubuntu, same error. Any hints?
I added the parameters and treated the "enable" flag analogous to the telnet server - so a reboot is required if Modbus is enbabled or disabled. But because I can't build I have no idea if it works. |
OK I added |
|
no I don't. FWIW, I first ran I pushed my changes after rebasing to current dev. One question: you removed Are changes like that expected to occur more frequently? If yes I'd rather hardcode fixed values for the tag -> modbus register block mapping. |
(same with the |
we made some major breaking changes with the tags, and this will be the last change. If you point us to the code that uses the tags myself and @MichaelDvP can review. For building, I wouldn't use the target |
Yes, it should be a esp32_16M (I'm using a BBQKees E32 Gateway V2). Regarding the enums I'm using:
|
I updated (FYI: I still had to re-enable the |
there was one change in |
Please check the types, Once the webpage is created there is no need to build it every time, Saves a lot of time when compiling code. To build it once manually: |
Thank you both for your infos. I updated all code yesterday with the settings changes so please feel free to take a look, I think you could implement the UI now @proddy. @MichaelDvP I still get the following compile errors on Ubuntu, gcc 1.4.0, if I don't apply above patch (sans the platformio.ini change):
|
FYI, when clone the doc repo I get the following warning:
|
I'll fix those lint errors. You not be sync'd with the latest dev? you shouldn't be seeing those compile warnings |
actually @mheyse since this is such a big change, and a major feature, I'll create a new feature branch. Then we can work together on that. Can you create a PR against the branch |
It was 2 days old :-) I just rebased to the latest dev, and the build warnings/errors are gone, thanks. EDIT: sorry that was too quick. I still get the errors when building standalone on Ubuntu with gcc 11.4 because of the
|
I changed the base branch of this PR to the feat_modbus branch. Because there are so many commits and WIP changes I think it would make sense that I squash everything I did to a single commit, also makes it easier to review and rebase. Do you agree? |
yup, squish it! |
[draft] - preview, not ready to be merged. TODOs see below.
This pull request adds Modbus support.
General
EMSESP Modbus server
There is one Modbus server for metadata. It currently transmits the following information:
1
: The number of EMS devices detected on the bus.1000 + n
: The ID of the nth device.Modbus register/entity mapping
DeviceValueTAG
). So for example all values for heating circuit 3 are tagged withTAG_HC3
.TAG_HC3
is defined as7
, so the hc3 values start at block7
, which starts at register address7000
. This works similar with all tags, also for example withTAG_DEVICE_DATA
(3
, register start address3000
)ecotemp
for device typethermosotat
has the offset5
. So the Modbus address forecotemp
in hc2 (TAG_HC2
=6
) would be6005
.numeric_operator
. For exampleecotemp
for a RC310 thermostat has numeric operatorDV_NUMOP_DIV2
, so the value read from the register needs to be divided by 2 to get the actual temperature.BOOL
,INT
,UINT
,SHORT
,USHORT
andENUM
are transmitted in a single register,ULONG
andTIME
in two registers (in big endian order) andSTRING
as an entity dependent number of registers, packing two characters in a 16 bit register and including the terminating\0
.TODOs
[x] The implementation is currently read-only. Implement writing.
[x] performance optimizations
[x]
memory optimizations (currently the mapping uses 44kB of RAM)Fixed in edc36cf[ ] documentation
[ ] configuration UI