MBUS adapter randomly dropping out

Hi,

I have recently had a heat pump installed. I had a Sontex Superstatic 749 fitted along with a couple of SDM230 modbus meters. I’ve been running a local Emoncms on a laptop for a year or two monitoring the solar and house battery. I added the MBUS heat meter but am having an issue where the connection drops out randomly. I see another thread here where there is a similar issue with MBUS electricity meters, however, all I need to do is restart Emonhub and it will start working again. Sometimes for hours, other times for 5 minutes!
Any suggestions please?

Also, do you know whether on the heatpump app, I should be using the Power or heat_calc value from the meter? They don’t differ by much at all but I don’t know what the difference is…

Thanks,
Mark.

Emonhub log:

2023-11-21 06:30:20,695 DEBUG    MQTT       Publishing: emon/SDM230/HeatPump_Total active energy kWh 99.1
2023-11-21 06:30:20,697 INFO     MQTT       Publishing 'node' formatted msg
2023-11-21 06:30:20,698 DEBUG    MQTT       Publishing: emonhub/rx/SDM230/values 708,10155.8,2762,0,9254.8,0,3402.6,22.7,1176.3,815.85400390625,79.9,15.8,433.5,99.1
2023-11-21 06:30:20,772 DEBUG    MBUS       Invalid MBUS data received 127 bytes 681.4 ms
2023-11-21 06:30:20,775 DEBUG    MBUS       Decoded MBUS data: {"Energy": [122, "kWh"], "Energy2": [0, "kWh"], "Volume": [80.56, "m3"], "Volume2": [0.0, "m3"], "Record5": [10700, ""], "Record6": [1100, ""], "Record7": [0.7679154276847839, ""], "Record8": [0.2185436487197876, ""], "FabNo": [30579092, ""], "DateTime": [737478429, ""], "Record11": [-3615, ""], "FlowT": [32.95947265625, "C"], "ReturnT": [28.6650390625, "C"], "FlowRate": [0.42126181721687317, "m3/h"], "Power": [2091.444091796875, "W"], "Record16": [0, ""], "Ontime Hours": [5494, "h"], "Record18": [0, ""], "heat_calc": [2085.468259284527, "W"]}
2023-11-21 06:30:20,776 DEBUG    MBUS       94 NEW FRAME : 
2023-11-21 06:30:20,776 DEBUG    MBUS       94 Timestamp : 1700548220.090358
2023-11-21 06:30:20,777 DEBUG    MBUS       94 From Node : MBUS
2023-11-21 06:30:20,778 DEBUG    MBUS       94    Values : [122, 0, 80.56, 0, 10700, 1100, 0.7679154276847839, 0.2185436487197876, 30579092, 737478429, -3615, 32.95947265625, 28.6650390625, 0.42126181721687317, 2091.444091796875, 0, 5494, 0, 2085.468259284527]
2023-11-21 06:30:20,778 DEBUG    MBUS       94 Sent to channel(start)' : ToEmonCMS
2023-11-21 06:30:20,779 DEBUG    MBUS       94 Sent to channel(end)' : ToEmonCMS
2023-11-21 06:30:20,911 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Energy 122
2023-11-21 06:30:20,912 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Energy2 0
2023-11-21 06:30:20,914 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Volume 80.56
2023-11-21 06:30:20,916 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Volume2 0
2023-11-21 06:30:20,917 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Record5 10700
2023-11-21 06:30:20,919 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Record6 1100
2023-11-21 06:30:20,920 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Record7 0.7679154276847839
2023-11-21 06:30:20,922 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Record8 0.2185436487197876
2023-11-21 06:30:20,924 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_FabNo 30579092
2023-11-21 06:30:20,926 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_DateTime 737478429
2023-11-21 06:30:20,927 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Record11 -3615
2023-11-21 06:30:20,929 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_FlowT 32.95947265625
2023-11-21 06:30:20,930 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_ReturnT 28.6650390625
2023-11-21 06:30:20,932 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_FlowRate 0.42126181721687317
2023-11-21 06:30:20,934 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Power 2091.444091796875
2023-11-21 06:30:20,936 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Record16 0
2023-11-21 06:30:20,937 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Ontime Hours 5494
2023-11-21 06:30:20,939 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_Record18 0
2023-11-21 06:30:20,941 DEBUG    MQTT       Publishing: emon/MBUS/heatmeter_heat_calc 2085.468259284527
2023-11-21 06:30:20,943 INFO     MQTT       Publishing 'node' formatted msg
2023-11-21 06:30:20,944 DEBUG    MQTT       Publishing: emonhub/rx/MBUS/values 122,0,80.56,0,10700,1100,0.7679154276847839,0.2185436487197876,30579092,737478429,-3615,32.95947265625,28.6650390625,0.42126181721687317,2091.444091796875,0,5494,0,2085.468259284527
2023-11-21 06:30:25,475 DEBUG    modbus     [708.6, 10155.8, 2762.0, 0.0, 9254.8, 0.0, 3402.6, 22.5, 1176.3, 815.85400390625, 77.7, 15.8, 433.9, 99.1]
2023-11-21 06:30:25,476 DEBUG    modbus     96 NEW FRAME : 
2023-11-21 06:30:25,476 DEBUG    modbus     96 Timestamp : 1700548225.003688
2023-11-21 06:30:25,477 DEBUG    modbus     96 From Node : SDM230
2023-11-21 06:30:25,478 DEBUG    modbus     96    Values : [708.6, 10155.8, 2762, 0, 9254.8, 0, 3402.6, 22.5, 1176.3, 815.85400390625, 77.7, 15.8, 433.9, 99.1]
2023-11-21 06:30:25,478 DEBUG    modbus     96 Sent to channel(start)' : ToEmonCMS
2023-11-21 06:30:25,479 DEBUG    modbus     96 Sent to channel(end)' : ToEmonCMS
2023-11-21 06:30:25,499 DEBUG    MQTT       Publishing: emon/SDM230/Grid_Active power W 708.6
2023-11-21 06:30:25,500 DEBUG    MQTT       Publishing: emon/SDM230/Grid_Import active energy kWh 10155.8
2023-11-21 06:30:25,502 DEBUG    MQTT       Publishing: emon/SDM230/Grid_Export active energy kWh 2762
2023-11-21 06:30:25,503 DEBUG    MQTT       Publishing: emon/SDM230/Generation_Active power W 0
2023-11-21 06:30:25,505 DEBUG    MQTT       Publishing: emon/SDM230/Generation_Total active energy kWh 9254.8
2023-11-21 06:30:25,506 DEBUG    MQTT       Publishing: emon/SDM230/Eddi_Active power W 0
2023-11-21 06:30:25,509 DEBUG    MQTT       Publishing: emon/SDM230/Eddi_Total active energy kWh 3402.6
2023-11-21 06:30:25,512 DEBUG    MQTT       Publishing: emon/SDM230/Pylontech_Active power W 22.5
2023-11-21 06:30:25,514 DEBUG    MQTT       Publishing: emon/SDM230/Pylontech_Import active energy kWh 1176.3
2023-11-21 06:30:25,515 DEBUG    MQTT       Publishing: emon/SDM230/Pylontech_Export active energy kWh 815.85400390625
2023-11-21 06:30:25,516 DEBUG    MQTT       Publishing: emon/SDM230/Cylinder_Active power W 77.7
2023-11-21 06:30:25,517 DEBUG    MQTT       Publishing: emon/SDM230/Cylinder_Total active energy kWh 15.8
2023-11-21 06:30:25,519 DEBUG    MQTT       Publishing: emon/SDM230/HeatPump_Active power W 433.9
2023-11-21 06:30:25,520 DEBUG    MQTT       Publishing: emon/SDM230/HeatPump_Total active energy kWh 99.1
2023-11-21 06:30:25,521 INFO     MQTT       Publishing 'node' formatted msg
2023-11-21 06:30:25,522 DEBUG    MQTT       Publishing: emonhub/rx/SDM230/values 708.6,10155.8,2762,0,9254.8,0,3402.6,22.5,1176.3,815.85400390625,77.7,15.8,433.9,99.1
2023-11-21 06:30:30,029 WARNING  MBUS       Exception caught in MBUS thread. Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 537, in write
    n = os.write(self.fd, d)
OSError: [Errno 5] Input/output error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/openenergymonitor/emonhub/src/emonhub_interfacer.py", line 31, in wrapper
    return func(*args)
  File "/opt/openenergymonitor/emonhub/src/emonhub_interfacer.py", line 98, in run
    rxc = self.read()
  File "/opt/openenergymonitor/emonhub/src/interfacers/EmonHubMBUSInterfacer.py", line 506, in read
    result = self.request_data(address,[])
  File "/opt/openenergymonitor/emonhub/src/interfacers/EmonHubMBUSInterfacer.py", line 386, in request_data
    self.mbus_short_frame(address, 0x5b)
  File "/opt/openenergymonitor/emonhub/src/interfacers/EmonHubMBUSInterfacer.py", line 77, in mbus_short_frame
    self.ser.write(data)
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 571, in write
    raise SerialException('write failed: {}'.format(e))
serial.serialutil.SerialException: write failed: [Errno 5] Input/output error

2023-11-21 06:30:30,065 WARNING  MainThread MBUS thread is dead.
2023-11-21 06:30:30,070 WARNING  MainThread Attempting to restart thread MBUS (thread has been restarted 0 times...)
2023-11-21 06:30:30,072 INFO     MainThread Setting modbus read_interval: 5
2023-11-21 06:30:30,073 INFO     MainThread Setting modbus meters Grid address 1
2023-11-21 06:30:30,075 INFO     MainThread Setting modbus meters Grid registers [12, 72, 74]
2023-11-21 06:30:30,077 INFO     MainThread Setting modbus meters Grid names ["Active power W", "Import active energy kWh", "Export active energy kWh"]
2023-11-21 06:30:30,078 INFO     MainThread Setting modbus meters Grid precision [1, 1, 1]
2023-11-21 06:30:30,078 INFO     MainThread Setting modbus meters Generation address 2
2023-11-21 06:30:30,080 INFO     MainThread Setting modbus meters Generation registers [12, 342]
2023-11-21 06:30:30,081 INFO     MainThread Setting modbus meters Generation names ["Active power W", "Total active energy kWh"]
2023-11-21 06:30:30,082 INFO     MainThread Setting modbus meters Generation precision [1, 1]
2023-11-21 06:30:30,083 INFO     MainThread Setting modbus meters Eddi address 3
2023-11-21 06:30:30,084 INFO     MainThread Setting modbus meters Eddi registers [12, 342]
2023-11-21 06:30:30,085 INFO     MainThread Setting modbus meters Eddi names ["Active power W", "Total active energy kWh"]
2023-11-21 06:30:30,086 INFO     MainThread Setting modbus meters Eddi precision [1, 1]
2023-11-21 06:30:30,087 INFO     MainThread Setting modbus meters Pylontech address 4
2023-11-21 06:30:30,088 INFO     MainThread Setting modbus meters Pylontech registers [12, 72, 74]
2023-11-21 06:30:30,089 INFO     MainThread Setting modbus meters Pylontech names ["Active power W", "Import active energy kWh", "Export active energy kWh"]
2023-11-21 06:30:30,090 INFO     MainThread Setting modbus meters Pylontech precision [1, 1]
2023-11-21 06:30:30,091 INFO     MainThread Setting modbus meters Cylinder address 5
2023-11-21 06:30:30,092 INFO     MainThread Setting modbus meters Cylinder registers [12, 342]
2023-11-21 06:30:30,093 INFO     MainThread Setting modbus meters Cylinder names ["Active power W", "Total active energy kWh"]
2023-11-21 06:30:30,094 INFO     MainThread Setting modbus meters Cylinder precision [1, 1]
2023-11-21 06:30:30,096 INFO     MainThread Setting modbus meters HeatPump address 6
2023-11-21 06:30:30,097 INFO     MainThread Setting modbus meters HeatPump registers [12, 342]
2023-11-21 06:30:30,098 INFO     MainThread Setting modbus meters HeatPump names ["Active power W", "Total active energy kWh"]
2023-11-21 06:30:30,098 INFO     MainThread Setting modbus meters HeatPump precision [1, 1]
2023-11-21 06:30:30,100 INFO     MainThread Creating EmonHubMBUSInterfacer 'MBUS'
2023-11-21 06:30:30,101 DEBUG    MainThread Connecting to MBUS serial: /dev/ttyUSB1 2400
2023-11-21 06:30:30,106 ERROR    MainThread Unable to create 'MBUS' interfacer: [Errno 2] could not open port /dev/ttyUSB1: [Errno 2] No such file or directory: '/dev/ttyUSB1'
2023-11-21 06:30:30,108 INFO     MainThread Setting emoncmsorg senddata: 1
2023-11-21 06:30:30,109 INFO     MainThread Setting emoncmsorg sendstatus: 1
2023-11-21 06:30:30,468 DEBUG    modbus     [702.4, 10155.8, 2762.0, 0.0, 9254.8, 0.0, 3402.6, 22.7, 1176.3, 815.85400390625, 74.2, 15.8, 427.1, 99.1]
2023-11-21 06:30:30,469 DEBUG    modbus     97 NEW FRAME : 
2023-11-21 06:30:30,470 DEBUG    modbus     97 Timestamp : 1700548230.000135
2023-11-21 06:30:30,471 DEBUG    modbus     97 From Node : SDM230

Is this a new MBUS USB adapter? The problem is at the hardware level where Python is trying to write to the serial port and fails.

Open a separate thread for this.

Yes it’s a new adapter. Are you saying I need to get a new one? Restarting Emonhub makes it work again which seems odd?

Possibly. There are other threads re trouble with USB adapters - not all are built the same. Was this a Shop one (not even sure if OEM do sell these).

Not really. As I say, it is probably a hardware & driver issue, restarting emonhub resets the driver. The code that is failing is not emonhub code, but core Python code so the exception isn’t the ‘fault’ of emonhub.

I also not you are running it on a laptop - again that may be a factor for the underlying Python code interacting with the system driver.

[edit]
Also note MBUS is a different protocol to Modbus