Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MQTT handling #971

Merged
merged 2 commits into from
Sep 3, 2022
Merged

Improve MQTT handling #971

merged 2 commits into from
Sep 3, 2022

Conversation

caco3
Copy link
Collaborator

@caco3 caco3 commented Sep 2, 2022

This MR makes sure that it tries to establish a connection on every ClassFlowMQTT, if MQTT is enabled and it the connection is not established.
Also it adds some log messages for easier debugging.

Below my test log:

Broker running on start

2022-09-03T00:18:41: Time zone set to CET-1CEST,M3.5.0,M10.5.0/3
2022-09-03T00:18:41: MQTT - Connected
[..]
2022-09-03T00:19:05:    FlowControll.doFlow - ClassFlowMQTT
2022-09-03T00:19:05: MQTT - sent publish successful in MQTTPublish, msg_id=9266, testzaehler/connection, connected
2022-09-03T00:19:05: MQTT - sent publish successful in MQTTPublish, msg_id=58884, testzaehler/uptime, 29
[..]
2022-09-03T00:19:05: task_autodoFlow - round done

broker stopped during runtime

2022-09-03T00:19:41: task_autodoFlow - next round - Round #2
[..]
2022-09-03T00:20:05:    FlowControll.doFlow - ClassFlowMQTT
2022-09-03T00:20:05: MQTT - Failed to publish + testzaehler/connection, no connection!
2022-09-03T00:20:05: task_autodoFlow - round done

broker gets started again during runtime

2022-09-03T00:23:41: task_autodoFlow - next round - Round #6
[..]
2022-09-03T00:24:05:    FlowControll.doFlow - ClassFlowMQTT
2022-09-03T00:24:05: MQTT - sent publish successful in MQTTPublish, msg_id=65376, testzaehler/connection, connected
2022-09-03T00:24:05: MQTT - sent publish successful in MQTTPublish, msg_id=62293, testzaehler/uptime, 329
[..]
2022-09-03T00:24:05: task_autodoFlow - round done

Broker stopped on start

2022-09-03T00:13:31: Time zone set to CET-1CEST,M3.5.0,M10.5.0/3
[..]
2022-09-03T00:13:58:    FlowControll.doFlow - ClassFlowMQTT
2022-09-03T00:13:58: MQTT - Can not publish, not connected!
2022-09-03T00:13:58: task_autodoFlow - round done
2022-09-03T00:14:32: task_autodoFlow - next round - Round #2
[..]
2022-09-03T00:14:57:    FlowControll.doFlow - ClassFlowMQTT

2022-09-03T00:14:57: MQTT - Can not publish, not connected!
2022-09-03T00:14:57: task_autodoFlow - round done

broker gets started during runtime

2022-09-03T00:16:32: task_autodoFlow - next round - Round #4
[..]
2022-09-03T00:16:57: FlowControll.doFlow - ClassFlowMQTT
2022-09-03T00:16:57: download_get_handler
2022-09-03T00:16:57: MQTT - sent publish successful in MQTTPublish, msg_id=18122, testzaehler/connection, connected2022-09-03T00:16:57: MQTT - sent publish successful in MQTTPublish, msg_id=32639, testzaehler/uptime, 210
[..]
2022-09-03T00:16:57: task_autodoFlow - round done

broker gets stopped again during runtime

2022-09-03T00:17:32: task_autodoFlow - next round - Round #5
[..]
2022-09-03T00:17:56:    FlowControll.doFlow - ClassFlowMQTT
2022-09-03T00:17:56: MQTT - Failed to publish + testzaehler/connection, no connection!
2022-09-03T00:17:56: task_autodoFlow - round done

MQTT disabled

2022-09-03T00:29:16: Time zone set to CET-1CEST,M3.5.0,M10.5.0/3
2022-09-03T00:29:16: task_autodoFlow - next round - Round #1
2022-09-03T00:29:16:    FlowControll.doFlow - ClassFlowMakeImage
2022-09-03T00:29:24:    FlowControll.doFlow - ClassFlowAlignment
2022-09-03T00:29:39:    FlowControll.doFlow - ClassFlowCNNGeneral
2022-09-03T00:29:39: ClassFlowCNNGeneral::doFlow nach Alignment
2022-09-03T00:29:41:    FlowControll.doFlow - ClassFlowPostProcessing
2022-09-03T00:29:41: ClassFlowCNNGeneral::getReadout _analog=0, _extendedResolution=0, prev=-1
2022-09-03T00:29:41: ClassFlowCNNGeneral::ZeigerEvalHybridNeu - kein Vorgänger - Ergebnis = 1 zahl: 1.000000 zahl_vorgaenger = -1.000000 eval_vorgaenger = -1 DigitalUnschaerfe = 0.200000
2022-09-03T00:29:41: ClassFlowCNNGeneral::getReadout(dig100)  prev=1
2022-09-03T00:29:41: task_autodoFlow - round done

@caco3
Copy link
Collaborator Author

caco3 commented Sep 2, 2022

@jomjol, @f-fritz, @Varkzor, @pos-ei-don and @s0170071: Maybe you could test it as well with the attached
firmware.bin.zip)?

@tutu81
Copy link

tutu81 commented Sep 3, 2022

Quite cool !

022-09-03T10:09:31: 	FlowControll.doFlow - ClassFlowMQTT
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=56580, water-meter/connection, connected
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=55251, water-meter/uptime, 113
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=29510, water-meter/freeMem, 3027715
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=48094, water-meter/wifiRSSI, -82
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=16150, water-meter/CPUtemp, 47.222221
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=35273, water-meter/main/value, 2840.8992
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=37537, water-meter/main/error, no error
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=6423, water-meter/main/rate, 0.000000
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=4369, water-meter/main/changeabsolut, 0.0000
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=10560, water-meter/main/raw, 0284N.8991
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=30070, water-meter/main/timestamp, 2022-09-03T10:08:06
2022-09-03T10:09:31: MQTT - sent publish successful in MQTTPublish, msg_id=57686, water-meter/main/json, {"value":2840.8992,"raw":"0284N.8991","error":"no error","rate":0.000000,"timestamp":"2022-09-03T10:08:06"}
2022-09-03T10:09:31: task_autodoFlow - round done

@caco3
Copy link
Collaborator Author

caco3 commented Sep 3, 2022

I deployed it now also to my live systems. Sadly there still seems to be an issue. it looks as if it only works every 2nd time:


2022-09-03T10:15:55: task_autodoFlow - next round - Round #8
2022-09-03T10:15:55: 	FlowControll.doFlow - ClassFlowMakeImage
2022-09-03T10:15:58: MQTT - Connected
2022-09-03T10:16:03: 	FlowControll.doFlow - ClassFlowAlignment
2022-09-03T10:16:19: MQTT - Connected
2022-09-03T10:16:27: 	FlowControll.doFlow - ClassFlowCNNGeneral
2022-09-03T10:16:27: ClassFlowCNNGeneral::doFlow nach Alignment
2022-09-03T10:16:31: 	FlowControll.doFlow - ClassFlowCNNGeneral
2022-09-03T10:16:43: 	FlowControll.doFlow - ClassFlowMQTT
2022-09-03T10:16:43: MQTT - Failed to publish + wasserzaehler/connection, no connection!
2022-09-03T10:16:43: task_autodoFlow - round done
2022-09-03T10:16:43: CPU Temperature: 68.9
2022-09-03T10:16:49: MQTT - Connected
2022-09-03T10:17:19: MQTT - Connected
2022-09-03T10:17:44: MQTT - Connected
2022-09-03T10:18:14: MQTT - Connected
2022-09-03T10:18:45: MQTT - Connected
2022-09-03T10:18:55: task_autodoFlow - next round - Round #9
2022-09-03T10:18:55: 	FlowControll.doFlow - ClassFlowMakeImage
2022-09-03T10:19:03: 	FlowControll.doFlow - ClassFlowAlignment
2022-09-03T10:19:05: MQTT - Connected
2022-09-03T10:19:27: 	FlowControll.doFlow - ClassFlowCNNGeneral
2022-09-03T10:19:27: ClassFlowCNNGeneral::doFlow nach Alignment
2022-09-03T10:19:30: MQTT - Connected
2022-09-03T10:19:31: 	FlowControll.doFlow - ClassFlowCNNGeneral
2022-09-03T10:19:43: 	FlowControll.doFlow - ClassFlowMQTT
2022-09-03T10:19:43: MQTT - sent publish successful in MQTTPublish, msg_id=31094, wasserzaehler/connection, connected
2022-09-03T10:19:43: MQTT - sent publish successful in MQTTPublish, msg_id=5285, wasserzaehler/uptime, 1493
2022-09-03T10:19:43: MQTT - sent publish successful in MQTTPublish, msg_id=64423, wasserzaehler/freeMem, 2962327
2022-09-03T10:19:43: MQTT - sent publish successful in MQTTPublish, msg_id=60971, wasserzaehler/wifiRSSI, -78
2022-09-03T10:19:43: MQTT - sent publish successful in MQTTPublish, msg_id=55900, wasserzaehler/CPUtemp, 68.888885
2022-09-03T10:19:43: MQTT - sent publish successful in MQTTPublish, msg_id=29993, wasserzaehler/main/value, 505.3486
2022-09-03T10:19:44: MQTT - sent publish successful in MQTTPublish, msg_id=40058, wasserzaehler/main/error, no error
2022-09-03T10:19:44: MQTT - sent publish successful in MQTTPublish, msg_id=38563, wasserzaehler/main/rate, 0.003398
2022-09-03T10:19:44: MQTT - sent publish successful in MQTTPublish, msg_id=51635, wasserzaehler/main/changeabsolut, 0.0102
2022-09-03T10:19:44: MQTT - sent publish successful in MQTTPublish, msg_id=17304, wasserzaehler/main/raw, 0505.3486
2022-09-03T10:19:44: MQTT - sent publish successful in MQTTPublish, msg_id=45117, wasserzaehler/main/timestamp, 2022-09-03T10:19:03
2022-09-03T10:19:44: MQTT - sent publish successful in MQTTPublish, msg_id=18705, wasserzaehler/main/json, {"value":505.3486,"raw":"0505.3486","error":"no error","rate":0.003398,"timestamp":"2022-09-03T10:19:03"}
2022-09-03T10:19:44: task_autodoFlow - round done

I will have to have another look sometimes.

@tutu81
Copy link

tutu81 commented Sep 3, 2022

See #953 (comment)

Seems that with this branch, even if MQTT says "all good", you have to reboot with MQTT disabled, then enable again to have it working.

@caco3
Copy link
Collaborator Author

caco3 commented Sep 4, 2022

I tried to improve it further, see #980 and the comments to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants