Observe Serial/Modbus via MQTT

Hello community,

  • Platform information:
    • Hardware: Raspberry Pi 5, Chint DTSU 666, Hi-Flying Protos PW11, Solax X3-G4 Inverter
    • OS: openhabian
    • Java Runtime Environment: 17.0.12
    • openHAB version: 4.2.1
  • Issue of the topic: I have a Smart Meter DTSU666 connected via modbus to a device “PW11” (RS485 to Wifi Bridge) which acts as modbus Slave and another PW11 which acts as modbus Master and is connected to a Solax X3 G4 Inverter. The Solax inverter needs to know the DTSU666 values because they are from another inverter only connectable via this WiFi Bridge. This bridge works good - Smart Meter measurement values (serial, modbus) are transmitted via WiFi Bridge (PW11 to PW11) to the Solax inverter.
    If the second PW11 is not connected then i am able to connect via OpenHab modbus TCP binding “Modbus TCP Slave” (=modus Master) and polls modbus registers, e.g. Power, Voltage, Current and so on. But if the second PW11 is connect, there are only strange values via modbus binding. The reason is, that there is only one Master allowed in modbus! Anyway, i would like to have the smart meter values in OpenHab, too! Therefore the idea is to “observe” the modbus traffic anyhow. The 1st attempt is to setup a MQTT connection on the 1st PW11 which works well. I can see the serial payload on the mqtt-topic “pw11-dtsu666/data” in this way:
pw11-dtsu666/data >\(�
pw11-dtsu666/data >\(�
pw11-dtsu666/data >\(�
pw11-dtsu666/data �EpEPE�BBB�yª¢¤CmB�B�B�@��?�AE'�E(pE(�E�(*�
pw11-dtsu666/data �EpEPE�BBB�����wª ¢CkB�B�B�@��?�AE'�E(pE(�E�(C�
pw11-dtsu666/data �EpEPE�BBB���u¨ CiB�B�B�@��?�AE'�E(pE(�E�(:�
pw11-dtsu666/data �E�EPE�BBB�wª¢¢CgB�B�B����?�E(PE(pE(PE�([�

How to decode this? Can i make use of the modbus bindings anyhow, e.g. pipe this to modbus “Regular Poll” or “Modbus Data”? Is there a transformation modbus to String (human readable) or even number values available?

I found similar topics:

But found no ready to use solution.

Do you have the specs on the data format for the inverter, ie what the 16 bit registers represent? Alternatively, do you know how the protoss device formats the registers when transmitting the data?

The thing is modbus data can be interpreted arbitrarily, so you may have to do some scripting.

Perhaps a JS script can help you convert those characters to a integer that means something recognisable.

Single Master is applicable for serial Modbus connection. When connected to TCP you can in theory connect more clients. Check if you can configure another TCP port on that PW11 or if you can modify the setting on the existing port to accept more clients.

I have 2x Enfin EW11 and I can see that you can do both of the options I suggested, maybe same is possible with yours module.

The TCP-Server on the PW11 can handle multiple clients, but they each send pull commands to the serial interface and there is the problem! Even if i spawn 2 TCP Servers (which is posible) - the problem is the same. Because all pull commands from any client (=Master) go to the same serial interface.
That’s why i look for the MQTT-Connector, which is able to only send data to a MQTT Server as answer to request coming from one Master (in my case the X3 Inverter). Which is fine. But i need some tooling to decode this answer. OH can do this with the modbus binding. But how to apply this functionality to the String answer coming via MQTT?
A listen-only thing from the modbus binding or something like this would be nice :slight_smile:

Did you try this?
Because the device should be able to handle the request from each client (I mean wait for the reply of the first request, then process the 2nd).

I have just tested connection from 2 clients on my EW11(Openhab on port 9000 and Modbus simulator on 8899) both polling the same slave device and it works without issue

Yes, i tried. Sometime the answer is correct and sometimes random trash. I think because of collisions.
Have you tried to increase the query rate on both clients? E.G. 200ms or less?
Timed requests reduce the chance of collisions … but is not feasible in my setup because the X3 inverter pulls very often.

If possible, try to decrease the polling speeds or increase the baud rate, once per 10-15 seconds or similar.
Maybe replacing the PW11 with EW11 would also help, they are from the same manufacturer.

When I face issues, it is mostly because of the bad WiFi, since that EW11 is in my garden house. I have ordered WiFi antenna from aliexpress that should arrive any day now to try to solve that.

No, but not sure why you need this. Modbus is not made for fast polls. Even in industrial devices it is rarely more often than once per 5 seconds. I have seen few custody transfer devices that can be polled once a second but usually it is 5-10s

Sound familiar. I also ordered an outdoor Wifi Repeater :wink:

The X3 inverter pull multiple times per second. Which is reasonable, because he has to know the power coming from the second PV generator. But i don’t know how often. On the X3 display the modbus values changes fast, mutliple times per second. But this is only in the display. Internal it could be even faster!?

If you are not able to modify the poll speed from the inverter, then the only other option would be to increase the baud rate.
Maybe also putting 120ohm resistors at each device can also help. Modbus serial link needs to be terminated with 120Ohm

And as last, try some MOXA or Phoenix Contact convertors, expensive for home use but might be able to handle the speed

Hmm, 9600 is max baud rate on the smart meter but the X3 can use higher rates. So the PW11 devices have to run on different baud rates. I try this in the next days :slight_smile:

The more severe problem at the moment is, that sometime but regulary zero-values appear on the X3 inverter. Maybe because of lost packets or not fast enough answers. I have to setup a stable connection first (hopefully with the outdoor Wifi Repeater) and then hang on the “2-client-issue”.

Both sides of the link should be the same baud rate

I thought so, too.

Sebastian,
I believe you shall reconsider the overall set-up you use. Solax X3 G4 inverter requires dedicated RS485 connection with the smart meter that shall be connected to Meter/CT port at the inverter. You can have second smart meter connected to this RS485 port and let the inverter to use data from both, but the Inverter needs to be “the only master” at this RS485.
Given the fact, how important this communication is for safe and effective operations of the inverter (e.g. to mamage energy flow back to the grid, phase balancing etc.), I would kick-out any WiFi conversion devices out of it and put there quality shielded cable with 120Ohm terminations at both ends (and check pull-up registers presence at both ends and need for GND connection next to A+/B-). If you use e.g. J-Y(ST)Y 2x2x0,8 and properly ground shielding at inverter side, you will have industrial level reliability even with several hunderd meters between the inverter and Smart meter (which I do not expect you need).

For communication with OpenHAB, do not interfere at all with the RS485 used for smart meter. The mess you see are for sure collisions at the RS485 itself as the Inverter expects to be the only ModbusRTU master and you are not able to change firmware of the inverter the be “collision aware”.

Instead, use the second RS485 the inverter has at COM port. At this port you can communicate with the inverter including reading of the basic data from the Smart meter (look at Input register table). This is the port designed for communication of the inverter with upstream system including control of the inverter.
Here, you can use safely good ModbusRTU → ModbusTCP converter including WiFi converters. Even if I would personally stay at cable connection and avoid WiFi here as well.

Truth is that you cannot get from the inverter Input registers all the data provided by the smart meter (but I have not checked what the meter you use actually provides). Question is, if you need them. I’m having second grid analyser (more powerful smart meter) connected in series with the one for the inverter so that I can read and record additional grid parameters including THD distorsion etc. independently from what the inverter uses. But this is not needed for 99% of installations and the basic grid data provided by the Inverter Input registers are sufficient (you can read all Voltages, Currents, PF, Freq, Power …).

Btw. setting correct baud rate, data and stop bits and parity is a must for any ModbusRTU connection. Including unique addresses of devices at the same RS485 bus. But I expect you have this right.

1 Like

Wise words, I also strongly recommend to leave the inverter to smart meter connection untouched (and use cable and neither wifi nor lan converters here) as David suggested. Read the data from a second port of the inverter (which is usually available with most inverters).
I have a similar setup, different inverter brand (growatt) though, and came to the exact same conclusion as David suggested.

1 Like

Yes, that’s what i learned and it’s fine. I don’t really need the measures from the second PV smart meter in OpenHab, but it would be nice.

My second PV is on the garage and to install a cable is almost impossible. That is why the RS485-Wifi solution came into place.
The X3 uses the CTs for monitoring currents to/from grid. So i think the setup is safe because the RS485-Wifi connection is only for the secondary PV.

I patched a cable to use the RS485 PINs (4,5) on the Meter/CT Connector of the X3 for the second PV.
Which works in principle, so i can see power values of 3 phases from the smart meter of the second PV (over the RS485-Wifi Connection) on the X3 display.

But every 10-15 seconds there are only zero values for 1-2 seconds on the display.
I tried to optimize the Wifi-Connection but with no change. I tried to play around with buffer sizes and some other parameters on the PW11 devices, but no change.
I use a CAT.5 cable to connect the CTs and the RS485 connection. The PW11’s RS485 port is connected via this CAT.5 cable to the X3. Do i have to add a 120 Ohm resistor somewhere in this point-to-point connection?

Good idea. I currently use a HTTP-Binding to read almost all inverter parameter via Solax Wifi-Dongle into OpenHab. I was also able to read the Power and Energy from the second PV (“other inverter”) which comes from the RS485/Wifi connection. But of course the zero values are there, too. Which i can monitor in OpenHab (blue: Power reported from the second inverter; green: Power reported via RS485/Wifi to X3.


The 2 curves have to be identical, but the zero values prevent this. :-/

I see. It looks to me that you do not describe OpenHAB integration issue, but rather issue in your PV’s connection architecture itself.
Sorry for the very long response. I hope at least some of it will help you.

My second PV is on the garage and to install a cable is almost impossible. That is why the RS485-Wifi solution came into place.
The X3 uses the CTs for monitoring currents to/from grid. So i think the setup is safe because the RS485-Wifi connection is only for the secondary PV.

I patched a cable to use the RS485 PINs (4,5) on the Meter/CT Connector of the X3 for the second PV.
Which works in principle, so i can see power values of 3 phases from the smart meter of the second PV (over the RS485-Wifi Connection) on the X3 display.

If I understood you well, you have 2x PV inverters. One being in the house and one on the garage. One does not have smart meter, but uses 3x CT for measing current to/from grid. Second is having smart meter on their power connection.
Your issue is, that you want meter data from the second PV inverter to be available to the first PV inverter.

If this is correct, than I suggest you speak with your PV vendor. I cannot test it as I do not have setup like this at home. However, my understanding is that this is not how Solax X3 inverters are designed to work in parallel connection mode (= two or more inverters connected in parallel to the same power network).
Take a look to the user manual chapter 5.5.3 and Master/Slave mode. From what I understood in the manual + some installations I have seen, there shall be only one master inverter that is connected to the smart meter/CT’s on connection of the house network to the grid. It is logical as you need to see overall current flow to/from the grid to the house. Slave invertors do not have meter/CT’s connected at all. Instead, they are connected via CAN bus with the master, who is controlling them. In this mode you can ensure that all the inverters work in sync. On the other hand, if the master is down or in error state, all other inverters shut down as well.

Yes, you have an option to run your two PV inverters also in independent mode. But it is not ideal, as the inverters control system will not have way, how to sync both inverters and e.g. avoid energy flow back to the network in case you do not consume all generated energy. Or communicate with the grid authority in case you are obliged to do so for grid stability purposes.
You will have to make other system (e.g. OpenHAB) to act as a master syncing both your PV inverters. It is not ideal and if you have 2x Solax X3 G4, I would use the CAN bus connection and Master/Slave mode.

I patched a cable to use the RS485 PINs (4,5) on the Meter/CT Connector of the X3 for the second PV.
Which works in principle, so i can see power values of 3 phases from the smart meter of the second PV (over the RS485-Wifi Connection) on the X3 display.

Even if you want to run both PV inverters in independent mode, you shall not be sharing any of the meters between them. Again, this is not what the Solax fw is expecting as otherwise, you would have two Modbus RTU master as one RS485. In my view, you have three options:

  1. PREFERED: Master/Slave mode with 1 Smarter meter/3xCT connected the Master inverter. No meter connected to Slave PV, but it is connected via CAN bus to Master and controlled by it.
  2. Independent mode, but the PV in the house is aware of the second PV inverter. In this mode you will actually need 3 Smart meters/CT sets. One will be connected to you PV in the garage. This PV inverted will not controll at all flow to/from the grid. This meter will be there just to see energy produced by second PV (i.e. would not be needed, but Solax inverter do require meter to connected otherwise it goes into “meter failure” alarm.
    Your PV inverter in the house will have 2 smart meters/CT’s connected. One at the connection of the house to the grid for measuring overall flow to/from the grid. And secondary meter at the output from your PV at garage. You PV inverter in the house will be able to control it’s own energy production and reduce it in case enough energy comes from PV at garage. However, it will not be able to control it or shut-down energy production when needed.
    From the graphs above, this is the way, how you have it set-up at this moment. Your graphs and screen shots looks to be from the PV inverter in the house. See section 5.5.2 in the manual for Meter 2 connection. Be sure that you do not share any of the meters between those inverters.
  3. Both PV’s are independendent and not aware of each other. I do not recomend this set-up at all as in this way control system in PV will be quite confused with the energy flow in your home network. If you go this way, than you shall shut down all optimization algorithms in both PV inverters. Actually, I even do not think any of the standard Solax modes would work well for you (Self use/Feed-in/Backup/EPS). You will have to use other system to sync and controll them.
    You will have two meters/CT sets in this mode. One for each inverter. However, they will rather than for the Solax fw be used as source to the overall control system.

But every 10-15 seconds there are only zero values for 1-2 seconds on the display.
I tried to optimize the Wifi-Connection but with no change. I tried to play around with buffer sizes and some other parameters on the PW11 devices, but no change.

If you are not sharing any of the meters (=you actually have 3 meters/CT sets) than the most probable failure point shall be the communication between your PV in the house and this meter. I’m afraid it is really back to the WiFI connection you use. PW11 is using 2,4GHz band. That is very busy band with only few channels and lot of interference. I’m afraid that you will have these problems forever with this device. Using 2,4GHz band and b/g/n standard is probably the worst choice you can make if the communication shall be reliable.
My strong recommendation is to put there a cable connection. Nothing will be more failure resistant. If you have no other choice than WiFI, look at least for RS485 bridge that uses 5GHz band or licensed band. There will be much less interference with AP’s around you, toy controller, microwaves etc. which you othervise have in the 2,4GHz band.
Actually, Solax is selling their own RS485 WiFI bridge that is designed for the Smart meter connection and from the manual seems to use 5GHz band and a/h WiFI standard. Look here.
Do not use the same AP and WiFI channel for the RS485 WiFI bridge as you are using for other WiFI devices at home. By design WiFI is collision communication, so for PV to Meter bridge it is better to you peer-to-peer connection or at least dedicated channel, so you are not slowing down your Meter communication when watching football. Sure, you can play with QoS and priorities, but why when separating it is even better. Except for setting it up, you will not need to access this connection and bridge devices anyway.

I use a CAT.5 cable to connect the CTs and the RS485 connection. The PW11’s RS485 port is connected via this CAT.5 cable to the X3. Do i have to add a 120 Ohm resistor somewhere in this point-to-point connection?

If the CAT.5 cable is 1-2 meters long and it is shielded, than 120Ohm resistors will likely not make a difference. At the same time, there is no harm when you put them at both ends between A+/B-. It shall be used for any RS485 bus according to the standard. I put them to every RS485 bus I have. Also, I always use shielded cable for any RS485 (grounded at one end only). So, in your case, you shall use 4 resistors (DTSU666,PW11,PW11,PV Meter port). At the same time, at the Meter/CT port connect only pins 4 and 5 to this CAT.5 cable. I understand that you are using CT’s as well for the Meter1 at this port of the PV in house. Do not use the same cable for it as otherwise you have 50Hz current of CT’s next to your RS485, which will cause interference.

Also, double check that you are having all the communication parameters set consistently for all devices at the same RS485. I do not see anywhere in the Solax settings, what communication parameters are used for the Meter RS485 connection. Settings you have there are for the COM port, not for the Meter port. If you have not changed any of the communication parameters at DTSU666 delivered to you with the inverter, it is pre-set with the Solax setting. Factory default is 9600bps, 1 stop bit, no parity. So, use those for your PW11 setting as well. Turn off Flow control, your meters are not using it. I would also play with the buffer size of PW11. Actually, try to make it smaller. Your PW11 shall really act as bridge only in this set-up. Any caching is actually not helping. Try to even put both your PW11’s to Transparent mode. You are trying to “replace cable”, so why to make Modbus RTU → Modbus TCP → Modbus RTU conversion, when you do not need it. But you have to check, if two PW11’s in Transparent mode can really act a bridge.
There is no point having different setting at the Meter to PW11 connection and Inverter to PW11 connection. As set, the baud rate in Solax setting shall be for COM port, not for the Meter port. If you use the Transparent mode of PW11, it is even a must to have everything set the same.

Good idea. I currently use a HTTP-Binding to read almost all inverter parameter via Solax Wifi-Dongle into OpenHab. I was also able to read the Power and Energy from the second PV (“other inverter”) which comes from the RS485/Wifi connection. But of course the zero values are there, too. Which i can monitor in OpenHab (blue: Power reported from the second inverter; green: Power reported via RS485/Wifi to X3.

It is fine to use the HTTP-Binding and Solax WiFI dongle. I do not like it personally as I do not want my data to be sent to the Solax cloud and used by this China company. However, for sure it is easier. Feel free to use it if the data provided are sufficient to you.
Just be sure that you do not mix the PV inverter to Smart meter communication with your OpenHAB to PV inverter communication. Use either the ModbusRTU at COM port or your WiFI dongle to connect PV inverter with OpenHAB. Do not connect anything else to your RS485 Wifi bridge devices, let them work solely for the Meter to PV communication.

You are right. The topic has changed.
I appreciate your answer.

My setup is like this:
Garage:

  • 3x Micro-Inverter, one on each phase, all behind one DTSU666 smart meter
  • 1 PW11 connected to smart meter and Wifi

House:

  • 1x Solax-X3-G4 + T58 Battery parallel to the grid with CTs
  • 1 PW11 connect to wifi and X3

My intention is to inform the Solax that there is another generator (=the 3 micro-inverters, or “other inverter” for solax) via connecting the garages DTSU666. As long the grid is available the solax resp. solax cloud is then able to display the second inverter like this:

So the Solax Master/Slave configuration is not applicable. “Independent mode” is my setup.

I share your concerns about this mode and i see the drawbacks. As long as the grid is available there is no electrical problem. If we assume that the RS485-Wifi connection is stable, there is also no problem for the Solax to calculate yield, consumption, earnings and so on, even with the “other generator”.

But I wonder what happens if the grid is not available and the Solax goes into EPS mode. As long as the “other generator” only generates enough power to go either to the loads or to the battery, everything is still fine. But when the battery is full and more is generated by the “other generator” than is consumed, things get exciting!

I suspect that the Solax either goes into error mode and switches off (and nother will be destroyed!). Or the frequency at the EPS output is increased beforehand, which causes the “other generators” to throttle or switch off and the error mode is avoided.

In the case that EPS mode is active, I would also prefer to actively throttle or switch off the micro inverters themselves via OpenHab. This is basically possible, as the Micro-Inverters (Hoymiles) are also integrated in OpenHab and can receive corresponding commands via MQTT (a rule can do this).
But I don’t want to rely exclusively on this solution. Who knows whether all devices are online and remain online when the power is disconnected and EPS mode takes over. Usually there is a brief power fluctuation and all devices continue to run. However, it can happen that a device (router, access points, Raspi with OpenHab etc.) restarts after all and the OpenHab controls fail. Then the “electrical” solution (=Solax increases the frequency and thus throttles the “other generators”) must work!

To come back to the original problem: I will do some tests with the RS485 cables and termination. Perhaps this is what is causing the interruptions or zero values.
I have checked the configuration of the serial interfaces (smart meter, PW11, Solax) several times and adjusted them to each other. I think that if there were errors there, I would not see any smart meter values at all on the Solax.

I don’t trust the wifi connection either, as several devices are involved (1 router, 1 switch, 2 access points) and a direct PW11-to-PW11 Wifi-connection is out of range. I can imagine that this network route could lead to timing problems or packet loss during RS485 signal transmission. I don’t have a RS485 cable connection at the moment, but I’ll see if there’s anything I can do. There are some old telephone cables (twisted cable pairs but unshielded) in the garage, but they are not in use and end somewhere. I have to find the end of those cables, extend it and then transmit the RS485 signal for about 70m over it directly from the smart meter to the Solax… I give this variant little chance of success, but maybe it will work.

Your set-up makes full sense. I agree with you that Solax shall know about the “other inverter”. And for sure you need to solve proper cooperation between your PV’s in all operating modes. Yes, you can use the frequency change in EPS mode. It shall work. However, test it in your network. I had to turn this feature off as in my case it was having one quite unplesant side effect. I have UPS’s connected to the power network and they are also reacting to the frequency change as a “power failure”. Which means, that connected servers go to battery mode and shut-down few minutes later even if there is still power provided from the PV.
I would not be so afraid of controlling sync of the Solax and your Micro-Inverters by additional controller. I would just choose reliable connectivity and also industry level controller for doing this. If you use Industrial PLC (I have very good experience with these: Teco Foxtrot), industry level switches and good connections, it shall be very reliable. What I use is dedicated network with separate physical shitches for my technology devices (with power being provided by the same backed-up power source as controlling PLC’s). It is connected with the other networks and VLAN’s I have via router, but even if all my other IT equipment goes down, the technology network is still up and running.

I don’t trust the wifi connection either, as several devices are involved (1 router, 1 switch, 2 access points) and a direct PW11-to-PW11 Wifi-connection is out of range. I can imagine that this network route could lead to timing problems or packet loss during RS485 signal transmission. I don’t have a RS485 cable connection at the moment, but I’ll see if there’s anything I can do. There are some old telephone cables (twisted cable pairs but unshielded) in the garage, but they are not in use and end somewhere. I have to find the end of those cables, extend it and then transmit the RS485 signal for about 70m over it directly from the smart meter to the Solax… I give this variant little chance of success, but maybe it will work.

No easy solution in here. I would personally make test connection via a cable (even if it would just be hanging from a window) to check, if with physical cable connection with proper 120Ohm terminations would work reliably without drops. If yes, than you have clear indications, what needs to be solved. Than I would try to use the cable as best option. Or at worst use dedicated 5GHz WiFI bridge I have described earlier. Ideally peer-to-peer with directional WiFI antenas. The set-up you describe that has 2 AP’s, routing etc. in the path is really not the way, how to connect smart meter to PV. Especially as you use 2,4GHz band.
Twisted pair in phone line even if not shielded will be much better than WiFI at 2,4GHz. At 70m you just need to avoid any power line to be close to it and at this distance be sure you put there 120Ohm termination resistors. Shielded cable would be much better, but at least something.

Good luck with solving this. I’m sure you will find a way.