I've been reading through forums and posts for some time to receive data from a Kostal Plenticore inverter via ModBus TCP with the ESP8266 / 32 and output it on a display.
Unfortunately, I have not had success with any example program.
It seems that the IP of the inverter, the Modbus port and the unit ID must be specified to read the registers.
Would be great if someone could provide me with an example script.
I can only suggest to have a look at my eModbus library, whose ModbusClientTCPasync class does run on an ESP8266 and is able to connect to any Modbus TCP server.
Of course you will need the IP of the server, the port number (which is 502 by default for Modbus) and the server ID (that should be given in the inverter's manual) to correctly address the server.
It would be better if you had enclosed your code with code tags to improve readability.
The MB.addRequest() call is exactly what you want: you will set up IP and port with the constructor call and hence read registers by the addRequest() calls.
In the example you were using, 4 registers, starting at address 100 are read from the server with ID 71. The result decoded is like was expectable:
47: the server ID 71
03: function code READ_HOLD_REGISTER
08: 8 bytes of payload in this response. 1 register has 16 bits, so we are getting 4 registers back
7B 8C 44 BC: two registers I reckon will hold a float value, that is 0x44BC7B8C = 1507.86083984
00 00 00 ??: two more registers where you skipped the last byte, obviously. All zero, I think.
Yes right that is what I want to have.
Is the value (1507,86xx) also directly retrievable - So that I can write this directly into a float variable ?
I am still not clear how to export my desired value from the values.
Yes, of course. You may profit from reading the docs, BTW...
There are get() calls for all integral data types, including float and double. You may have to use the byte ordering parameters in the call to adjust to the server's float byte order; I would go for SWAP_WORDS from what I saw.
Ähh - Nein - egal. Ich habe auf deutschen Webseiten wenig hilfreiches über Arduino & Modbus gefunden daher habe ich auf Englisch geschrieben - und dann wohl das flasche Forum erwischt.
Für mich ist nicht ersichtlich, woher die Zeile :
Serial.printf (" %02X ", byte);
den Wert nimmt. %02x ist doch eine Formatierung für HEX - byte der Data Typ.
Da steckt für mich keine Variable drin.
for (auto& byte : response)
{ a++;
Serial.printf ("%02X ", byte);
}
aus einem Beispiel. Die Arduino IDE hat dabei "byte" grün eingefärbt - daher dachte ich es Bezeichnet einen DataTyp.
Bin jetzt ein stückchen weiter gekommen. Werde die einzelnen HEX Werte "zu Fuß" zusammen fügen und in einen float umwandelt.
Wie ich SWAP_WORDS anwenden kann - Interessiert mit trotzdem. Vielleicht hast Du ein Beispiel dafür.
Hallo,
ich habe auch einen Kostal Plenticore im Einsatz und würde gerne die Leistung auslesen, welche Leistung ins gespeist wird. Leider habe ich nicht so viel Erfahrung mit ModBus. Können Sie Ihr Programm mit "anonymem" Setup zur Verfügung Stellen. Womöglich kann ich von dort aus loslegen
Hier ein paar Bilder. Das Display ist ein ILI9341 Touch 2,8". Leider ist der Bildaufbau etwas langsam da ist man vom Smartphone doch schon sehr verwöhnt.
Hallo,
wie ich sehe hast du da Problem mit der richtigen Darstellung der Holding Register des Kostal Plenticore gelöst bekommen. Ich check es einfach nicht wie man den get() Aufruf macht mit SWAP_WORDS und dann ein Float in der richtigen Darstellung bekommt.
Das ist eigentlich mein letztes Problem das ich knacken muss.
Wäre nett wenn du mir ein Code Schnipsel teilen könntest.
Normalerweise werden floats als zwei aufeinander folgende Register MSB-first im IEEE754-Format übertragen. Wenn das so ist, funktioniert der get()-Aufruf ohne jede Angabe irgendwelcher SWAP-Flags. Nur wenn dein Kostal-Server von der Konvention abweicht, brauchst du die.
Hast du mal eine Antwort des Servers im Hexadezimalformat? Da kann man meist erkennen, in welcher Reihenfolge die fliat-Bytes gesendet werden.
Hi, hier mal mein Code.
Ist nicht der letzte und noch etwas wild - aber daraus kannst Du alles entnehmen damit es funktioniert. https://cloudsync.uol.de/s/nQ7ofc2qejSW2tp