Skip to content

Commit

Permalink
Cleanup in case of null
Browse files Browse the repository at this point in the history
  • Loading branch information
steadramon committed Sep 1, 2024
1 parent c986af4 commit 897543d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ESPGeiger/src/Radmon/Radmon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ void Radmon::setInterval(int interval) {
pingInterval = interval*1000;
}

int Radmon::getInterval() {
return pingInterval / 1000;
}

void Radmon::s_tick(unsigned long stick_now)
{
if (stick_now - lastPing >= pingInterval)
{
if (lastPing == 0) {
ConfigManager &configManager = ConfigManager::getInstance();
int rtimer = atoi(configManager.getParamValueFromID("radmonTime"));
if (rtimer == NULL) {
rtimer = RADMON_INTERVAL;
}
setInterval(rtimer);
lastPing = random(rtimer / 2) * 1000;
return;
Expand Down Expand Up @@ -90,6 +97,9 @@ void Radmon::postMeasurement() {
const char* _api_user = configManager.getParamValueFromID("radmonUser");
const char* _api_key = configManager.getParamValueFromID("radmonKey");
int rtimer = atoi(configManager.getParamValueFromID("radmonTime"));
if (rtimer == NULL) {
rtimer = RADMON_INTERVAL;
}
setInterval(rtimer);

if ((_api_user == NULL) && (_api_key == NULL)) {
Expand Down
3 changes: 2 additions & 1 deletion ESPGeiger/src/Radmon/Radmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Radmon {
void s_tick(unsigned long stick_now);
void postMeasurement();
void setInterval(int interval);
int getInterval();
AsyncHTTPRequest request;
private:
unsigned long lastPing = 0;
Expand All @@ -58,4 +59,4 @@ class Radmon {
};

#endif
#endif
#endif

0 comments on commit 897543d

Please sign in to comment.