-
-
Notifications
You must be signed in to change notification settings - Fork 32
Disconnecting or closing a link #18
Comments
Look at (private) method _disconnect: esp32ModbusTCP/src/esp32ModbusTCP.cpp Line 107 in 8621d98
|
Hi bertmelis Thank you very much for the rapid response. My knowledge is a very thin veneer and I have extremely limited knowledge of libraries. I had a look at void esp32ModbusTCP::_disconnect(bool now) { in the esp32ModbusTCP.cpp. Based on the the other functions within the library I would have expected sunnyisland.disconnect(true); to be the appropriate function call to disconnect and close the sunnyisland client. I’m working in VSCode and intellisens is indicating that Clearly I’m missing something and I’m hoping you could again please point me in the right direction. I fiddled and I mean I’m fiddling in the dark, I tried sunnyisland.~esp32ModbusTCP.disconnect(true); and intellisens seems to like it :) Edit...but it didn’t compile with a does not have class type error. Hopefully you can give me a bit more guidance please. Many thanks |
You need to do a few steps: make the function public. It's private now. So move the function in the .h file from the private section the the public section. Maybe rename the function: remove the underscore. But you'll also have to change the name in all places that call the function (in the cpp file). Does this make sense to you? |
Hi bertmelis Thanks for the even more rapid response. I’ll give it a bash and see if I get it right. In reading the original library more closely I notice that writing to registers is not implemented. I’ll try my luck with this too. Or would you recommend I rather move to v1 and adjust my sketch accordingly? I would still need to change the header to make the .disconnect() public, but it appears that the register write has been implemented. Many thanks |
Hi bertmelis I followed your guidance above, thank you. Done. I commented it out in the private section and pasted it into public after readInputRegisters line. LBut you'll also have to change the name in all places that call the function (in the cpp file).” The intellisens was seeing the public function .connect and the sketch compiles. However no matter what I use it does not seem to disconnect the link, as I continue to get read errors. I tried I then resorted to commenting out the sunnyisland.disconnect() and just did not read the holdingregister for 180s. This did not reset the link either, even though #define MB_IDLE_DISCONNECT_TIME is set to 10000ms. I then powered the ESP32 off for 180s and then powered it up. Now the link is up and the holdingregister is being successfully read. This physical power cycle with the 3 minute delay (2 minutes is too short) does it every time so far. Any guidance would be appreciated. Many thanks |
Hi bertmelis I have installed v1 library, adjusted for the load prohibited error by commenting out the two lines in esp32ModbusTCP.cpp, adjusted code to examples, compiled and uploaded fine. However the esp32 is now rebooting after the first SI holdingregister read per below. SI reading error Backtrace: 0x400d1ee1:0x3ffde7a0 0x400e41d1:0x3ffde7c0 0x400e45d5:0x3ffde810 0x4016507d:0x3ffde840 0x400e4e29:0x3ffde860 0x400e4e6d:0x3ffde8a0 0x400e52d6:0x3ffde8c0 0x40089805:0x3ffde8f0 Rebooting... Hopefully this helps you to identify the problem. Cheers |
Hi bertmelis
Thanks for your efforts with the original ESP32ModbusTCP library.
My setup is a Sunny Boy and Sunny Island. Using your original library (not v1) I am able to read the holdingregisters I need using an ESP32 by creating two Modbus server instances. In the development environment I need to tweak code and upload, which on occasion causes Modbus comms errors to occur. If I kill the ESP32 and wait 3 minutes I get the Modbus back up and running correctly without errors. The .onerror function is reporting the errors but the link rarely recovers on its own. I’m polling 4 registers on the SI and one register on the SB every 1s.
To regain a ModbusTCP connection to the SMA without errors I either need to timeout the link (brute force) or use a library function to close the link and reopen it after a short delay(preferable as it’s more elegant).
I have scanned the ESP32ModbusTCP and AsyncTCP libraries for relevant .close() or similar .disconnect() commands, but can’t find any that seem to work they way I would have thought they worked. For example I want to close and reinstate the link ESP32ModbusTCP sunnyisland(3,{IP},502) by issuing a sunnyisland.close() on an error and then reinstate the link with another ESP32ModbusTCP sunnyisland(3,{IP},502) after a short delay.
Did you implement a TCP link disconnection in your original library? If so could you please share the syntax?
Many thanks
Carl
The text was updated successfully, but these errors were encountered: