Skip to content

Commit

Permalink
trying to fix mqtt stops to work after a few hours
Browse files Browse the repository at this point in the history
  • Loading branch information
Holger Fleischmann committed Nov 15, 2020
1 parent 91c7b5e commit 733ca42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/ingest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "GeigerData.h"

void initIngest();
void loopIngest();
void deinitIngest();
void ingestToThingspeak(GeigerData &geigerData, uint16_t intervalSamples);
void ingestToMqtt(GeigerData &geigerData, uint16_t intervalSamples);
Expand Down
13 changes: 12 additions & 1 deletion src/ingest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ void initIngest()
connectWiFi();
}

void loopIngest()
{
if (mqttClient.connected())
{
mqttClient.loop();
}
}

void deinitIngest()
{
if (WiFi.status() == WL_CONNECTED)
Expand Down Expand Up @@ -182,6 +190,9 @@ void ingestToMqtt(GeigerData &geigerData, uint16_t intervalSamples)
sprintf(payload, "{\"pulses\":%lu, \"cpm\":%lu,\"uSph\":%.3f,\"secs\":%d}",
pulses, cpm, uSph, (int)intervalSamples);

mqttClient.publish(mqttTopic, payload);
if (!mqttClient.publish(mqttTopic, payload))
{
mqttClient.disconnect();
}
}
}
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void loop()

if (wifiSwitchOn())
{
loopIngest();
ingestCountdown--;
if (ingestCountdown <= 0)
{
Expand Down

0 comments on commit 733ca42

Please sign in to comment.