From 7e97d54d0f28b57e2a35db671982c400da4fb674 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Mon, 21 Feb 2022 05:40:14 +0100 Subject: [PATCH] restructure mqtt msg routine --- main.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index d8d6b53..eebc294 100644 --- a/main.c +++ b/main.c @@ -76,7 +76,7 @@ static void avr_init() return; } -void send_abzug_speed(void){ +void send_info(void){ char msg[4]; sprintf(msg, "%d", abzug_speed); mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/abzug/speed", msg, strlen(msg)); @@ -86,8 +86,19 @@ void send_abzug_speed(void){ else sprintf(msg, "False"); mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/abzug/onoff", msg, strlen(msg)); + + ltoa(kraftsensor_value, msg, 10); + mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/kraft", msg, strlen(msg)); + + ltoa(taenzer_state.pos, msg, 10); + mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/speicher/pos", msg, strlen(msg)); + + sprintf(msg, "%ld", millis()/1000); + mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/uptime", msg, strlen(msg)); } + + int main() { // INIT MCU @@ -150,7 +161,7 @@ int main() ioHelperSetBit(outStatesBlinking, LED_PLC_OK, 1); uint32_t timer_blink_outs = millis(); - uint32_t timer_send_uptime = millis(); + uint32_t timer_send_info = millis(); uint32_t timer_modbus_poll = millis(); while(1) @@ -159,7 +170,7 @@ int main() #if PLC_MQTT_ENABLED if(millis() < 10) - send_abzug_speed(); + send_info(); #endif ioHelperReadPins(); @@ -175,27 +186,18 @@ int main() timer_blink_outs = millis(); } -#if PLC_MQTT_ENABLED - // send misc info - //if(millis() - timer_send_uptime > 5000){ - // timer_send_uptime += 5000; - // char msg[64]; - // sprintf(msg, "%ld", millis()/1000); - // mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/uptime", msg, strlen(msg)); - //} -#endif if(millis() - timer_modbus_poll > 200){ timer_modbus_poll += 200; do_kraftsensor(); + } + #if PLC_MQTT_ENABLED - send_abzug_speed(); - char msg[10]; - ltoa(kraftsensor_value, msg, 10); - mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/kraft", msg, strlen(msg)); - ltoa(taenzer_state.pos, msg, 10); - mqtt_pub(&mqtt_client, "/Filamentanlage/05_Abzug/state/speicher/pos", msg, strlen(msg)); -#endif + // send misc info + if(millis() - timer_send_info > 200){ + timer_send_info += 200; + send_info(); } +#endif do_notaus(); do_abzug();