ESP32-PaxCounter/src/homecycle.cpp

40 lines
1.3 KiB
C++
Raw Normal View History

2018-07-22 20:27:58 +02:00
/* This routine is called by interrupt in regular intervals */
/* Interval can be set in paxcounter.conf (HOMECYCLE) */
// Basic config
#include "globals.h"
#include "senddata.h"
// Local logging tag
static const char TAG[] = "main";
// do all housekeeping
void doHomework() {
// read battery voltage into global variable
#ifdef HAS_BATTERY_PROBE
batt_voltage = read_voltage();
ESP_LOGI(TAG, "Measured Voltage: %dmV", batt_voltage);
#endif
// sync time & date if we have valid gps time
#ifdef HAS_GPS
if (gps.time.isValid()) {
setTime(gps.time.hour(), gps.time.minute(), gps.time.second(),
gps.date.day(), gps.date.month(), gps.date.year());
ESP_LOGI(TAG, "Time synced to %02d:%02d:%02d", hour(), minute(), second());
} else {
ESP_LOGI(TAG, "No valid GPS time");
}
#endif
// check free memory
if (esp_get_minimum_free_heap_size() <= MEM_LOW) {
ESP_LOGW(TAG,
"Memory full, counter cleared (heap low water mark = %d Bytes / "
"free heap = %d bytes)",
esp_get_minimum_free_heap_size(), ESP.getFreeHeap());
senddata(COUNTERPORT); // send data before clearing counters
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
}
}