restructure mqtt msg routine

master
Eggert Jung 4 years ago
parent f590396e0c
commit 7e97d54d0f

@ -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();