add inactive flag to configuration

This commit is contained in:
Wolfgang Hottgenroth
2021-04-14 18:04:32 +02:00
parent 6de48ce2a4
commit e4f2942485
2 changed files with 38 additions and 27 deletions

View File

@ -26,6 +26,7 @@ typedef struct {
const char *deviceId;
const char *location;
const char *sharedSecret;
int inactive;
} t_device;
typedef struct {
@ -93,8 +94,13 @@ int initConfig(const char *configFilename, t_configHandle *configHandle) {
logmsg(LOG_ERR, "Configured sharedsecret for device %d is too long", i);
return -6;
}
logmsg(LOG_INFO, "Device loaded: %d %s %s %s", i,
if (! config_setting_lookup_bool(deviceConfig, "inactive", &(configHandle->devices[i].inactive))) {
logmsg(LOG_INFO, "no inactive flag set for device %d, consider as active", i);
configHandle->devices[i].inactive = 0;
}
logmsg(LOG_INFO, "Device loaded: %d %s %d %s %s", i,
configHandle->devices[i].deviceId,
configHandle->devices[i].inactive,
configHandle->devices[i].location,
configHandle->devices[i].sharedSecret);
}
@ -293,6 +299,7 @@ int forwardMinuteBuffer(t_forwarderHandle *handle, t_minuteBuffer *buf) {
buf->s.deviceId, buf->s.totalRunningHours, buf->s.totalPowercycles, buf->s.totalWatchdogResets,
buf->s.version, location);
if (device->inactive == 0) {
for (uint8_t j = 0; j < SECONDS_PER_MINUTE; j++) {
uint64_t timestamp = buf->s.timestamp + j;
logmsg(LOG_DEBUG, "Time: %lu, Frequency: %u", timestamp, buf->s.frequency[j]);
@ -326,6 +333,9 @@ int forwardMinuteBuffer(t_forwarderHandle *handle, t_minuteBuffer *buf) {
logmsg(LOG_ERR, "%u out of bound, ignored", buf->s.frequency[j]);
}
}
} else {
logmsg(LOG_INFO, "Inactive device, not sent to InfluxDB");
}
logmsg(LOG_INFO, "Successfully sent whole minute to InfluxDB");
return 0;

View File

@ -12,6 +12,7 @@ receivePort = 20169;
devices = (
{
inactive = true;
deviceId = "MainsCnt01";
// sharedSecret must have exactly 31 characters
sharedSecret = "Uj6*uKDp@8Kvfa4g5eRMLUfVsSuqjxW";