openenergymonitor / emonhub

Python service linking and decoding input to MQTT & Emoncms
90 stars 83 forks source link

Check for data message in message String #145

Closed borpin closed 3 years ago

borpin commented 3 years ago

If the EmonTX is reset, the interfacer trys to interpret the incoming serial lines as data messages. This can result in spurious inputs being created.

By checking for the string "MSG:" in the decoded text, this can be avoided.

As a bonus, the initial output from the EmonTX can be recorded.

I have also reset the buffer at line 50. I think this is more correct.

I also query why this return does not return False

Output seen in emonhub.log to first MSG

2021-01-16 11:27:16,062 DEBUG    SerialTx   START MESSAGE: emonTx V3.4 EmonLibCM Continuous Monitoring V1.80
2021-01-16 11:27:16,171 DEBUG    SerialTx   START MESSAGE: OpenEnergyMonitor.org
2021-01-16 11:27:16,279 DEBUG    SerialTx   START MESSAGE: Loaded EEPROM config
2021-01-16 11:27:16,385 DEBUG    SerialTx   START MESSAGE: Settings:
2021-01-16 11:27:16,707 DEBUG    SerialTx   START MESSAGE: Calibration:
2021-01-16 11:27:16,821 DEBUG    SerialTx   START MESSAGE: vCal = 268.97
2021-01-16 11:27:16,932 DEBUG    SerialTx   START MESSAGE: i1Cal = 90.90
2021-01-16 11:27:17,041 DEBUG    SerialTx   START MESSAGE: i1Lead = 4.20
2021-01-16 11:27:17,172 DEBUG    SerialTx   START MESSAGE: i2Cal = 90.90
2021-01-16 11:27:17,289 DEBUG    SerialTx   START MESSAGE: i2Lead = 4.20
2021-01-16 11:27:17,396 DEBUG    SerialTx   START MESSAGE: i3Cal = 90.90
2021-01-16 11:27:17,502 DEBUG    SerialTx   START MESSAGE: i3Lead = 4.20
2021-01-16 11:27:17,611 DEBUG    SerialTx   START MESSAGE: i4Cal = 16.67
2021-01-16 11:27:17,718 DEBUG    SerialTx   START MESSAGE: i4Lead = 6.00
2021-01-16 11:27:17,835 DEBUG    SerialTx   START MESSAGE: datalog = 10.01
2021-01-16 11:27:17,958 DEBUG    SerialTx   START MESSAGE: pulses = 1
2021-01-16 11:27:18,078 DEBUG    SerialTx   START MESSAGE: pulse period = 100
2021-01-16 11:27:18,185 DEBUG    SerialTx   START MESSAGE: temp_enable = 1
2021-01-16 11:27:18,319 DEBUG    SerialTx   START MESSAGE: Temperature Sensors found = 0 of 1
2021-01-16 11:27:18,442 DEBUG    SerialTx   START MESSAGE: Temperature measurement is NOT enabled.
2021-01-16 11:27:18,547 DEBUG    SerialTx   START MESSAGE:
2021-01-16 11:27:18,763 DEBUG    SerialTx   START MESSAGE: POST.....wait 10s
2021-01-16 11:27:18,880 DEBUG    SerialTx   START MESSAGE: '+++' then [Enter] for config mode
2021-01-16 11:27:26,093 DEBUG    SerialTx   START MESSAGE: CT1 detected, i1Cal:90.90
2021-01-16 11:27:36,544 DEBUG    SerialTx   START MESSAGE: AC present
2021-01-16 11:27:36,659 DEBUG    SerialTx   5 NEW FRAME : MSG:1,Vrms:241.01,P1:1046,E1:2,pulse:1
borpin commented 3 years ago

I noticed that some of the startup messages were missing. This is because not every line in the startup messages generated by the EmonTX have a /r/n.

2021-01-17 17:52:02,600 DEBUG    SerialTx   START MESSAGE: emonTx V3.4 EmonLibCM Continuous Monitoring V1.80
2021-01-17 17:52:02,709 DEBUG    SerialTx   START MESSAGE: OpenEnergyMonitor.org
2021-01-17 17:52:02,821 DEBUG    SerialTx   START MESSAGE: Loaded EEPROM config
2021-01-17 17:52:02,929 DEBUG    SerialTx   START MESSAGE: Settings:
2021-01-17 17:52:03,045 DEBUG    SerialTx   START MESSAGE: Group 210, Node 15, Band 433 MHz
2021-01-17 17:52:03,260 DEBUG    SerialTx   START MESSAGE: Calibration:
2021-01-17 17:52:03,367 DEBUG    SerialTx   START MESSAGE: vCal = 268.97
2021-01-17 17:52:03,481 DEBUG    SerialTx   START MESSAGE: i1Cal = 90.90
2021-01-17 17:52:03,588 DEBUG    SerialTx   START MESSAGE: i1Lead = 4.20
2021-01-17 17:52:03,695 DEBUG    SerialTx   START MESSAGE: i2Cal = 90.90
2021-01-17 17:52:03,802 DEBUG    SerialTx   START MESSAGE: i2Lead = 4.20
2021-01-17 17:52:03,910 DEBUG    SerialTx   START MESSAGE: i3Cal = 90.90
2021-01-17 17:52:04,019 DEBUG    SerialTx   START MESSAGE: i3Lead = 4.20
2021-01-17 17:52:04,130 DEBUG    SerialTx   START MESSAGE: i4Cal = 16.67
2021-01-17 17:52:04,262 DEBUG    SerialTx   START MESSAGE: i4Lead = 6.00
2021-01-17 17:52:04,386 DEBUG    SerialTx   START MESSAGE: datalog = 10.01
2021-01-17 17:52:04,493 DEBUG    SerialTx   START MESSAGE: pulses = 1
2021-01-17 17:52:04,601 DEBUG    SerialTx   START MESSAGE: pulse period = 100
2021-01-17 17:52:04,709 DEBUG    SerialTx   START MESSAGE: temp_enable = 1
2021-01-17 17:52:04,820 DEBUG    SerialTx   START MESSAGE: Temperature Sensors found = 0 of 1
2021-01-17 17:52:04,936 DEBUG    SerialTx   START MESSAGE: Temperature measurement is NOT enabled.
2021-01-17 17:52:05,040 DEBUG    SerialTx   START MESSAGE:
2021-01-17 17:52:05,147 DEBUG    SerialTx   START MESSAGE: RF off
2021-01-17 17:52:05,258 DEBUG    SerialTx   START MESSAGE: POST.....wait 10s
2021-01-17 17:52:05,384 DEBUG    SerialTx   START MESSAGE: '+++' then [Enter] for config mode
2021-01-17 17:52:12,614 DEBUG    SerialTx   START MESSAGE: CT1 detected, i1Cal:90.90
2021-01-17 17:52:23,061 DEBUG    SerialTx   START MESSAGE: AC present
2021-01-17 17:52:23,180 DEBUG    SerialTx   1041 NEW FRAME : MSG:1,Vrms:243.27,P1:546,E1:1,pulse:1
TrystanLea commented 3 years ago

Thanks @borpin sounds good, sorry for the delay in merging this.