|
@ -403,19 +403,19 @@ void receiveMqtt(const char* topic, const char* data, int data_len) { |
|
|
ESP_LOGW(TAG, "Error parsing JSON, code: %s", err.c_str()); |
|
|
ESP_LOGW(TAG, "Error parsing JSON, code: %s", err.c_str()); |
|
|
} else { |
|
|
} else { |
|
|
// got json
|
|
|
// got json
|
|
|
sensor->temperature = jsonDoc["temperature"].as<float>(); |
|
|
if (jsonDoc.containsKey("temperature")) sensor->temperature = jsonDoc["temperature"].as<float>(); |
|
|
sensor->humidity = jsonDoc["humidity"].as<float>(); |
|
|
if (jsonDoc.containsKey("humidity")) sensor->humidity = jsonDoc["humidity"].as<float>(); |
|
|
sensor->pressure = jsonDoc["pressure"].as<float>(); |
|
|
if (jsonDoc.containsKey("pressure")) sensor->pressure = jsonDoc["pressure"].as<float>(); |
|
|
sensor->voc = jsonDoc["voc"].as<uint32_t>(); |
|
|
if (jsonDoc.containsKey("voc")) sensor->voc = jsonDoc["voc"].as<uint32_t>(); |
|
|
sensor->lux = jsonDoc["lux"].as<float>(); |
|
|
if (jsonDoc.containsKey("lux")) sensor->lux = jsonDoc["lux"].as<float>(); |
|
|
sensor->uvi = jsonDoc["uvi"].as<float>(); |
|
|
if (jsonDoc.containsKey("uvi")) sensor->uvi = jsonDoc["uvi"].as<float>(); |
|
|
sensor->uva = jsonDoc["uva"].as<float>(); |
|
|
if (jsonDoc.containsKey("uva")) sensor->uva = jsonDoc["uva"].as<float>(); |
|
|
sensor->uvb = jsonDoc["uvb"].as<float>(); |
|
|
if (jsonDoc.containsKey("uvb")) sensor->uvb = jsonDoc["uvb"].as<float>(); |
|
|
sensor->pm10 = jsonDoc["pm10"].as<float>(); |
|
|
if (jsonDoc.containsKey("pm10")) sensor->pm10 = jsonDoc["pm10"].as<float>(); |
|
|
sensor->pm25 = jsonDoc["pm2.5"].as<float>(); |
|
|
if (jsonDoc.containsKey("pm2.5")) sensor->pm25 = jsonDoc["pm2.5"].as<float>(); |
|
|
sensor->battery = jsonDoc["voltage"].as<int>(); |
|
|
if (jsonDoc.containsKey("voltage")) sensor->battery = jsonDoc["voltage"].as<int>(); |
|
|
sensor->rssi = jsonDoc["rssi"].as<int8_t>(); |
|
|
if (jsonDoc.containsKey("rssi")) sensor->rssi = jsonDoc["rssi"].as<int8_t>(); |
|
|
sensor->lastUpdate = jsonDoc["timestamp"].as<time_t>(); |
|
|
if (jsonDoc.containsKey("timestamp")) sensor->lastUpdate = jsonDoc["timestamp"].as<time_t>(); |
|
|
ESP_LOGI(TAG, "got new values from %s, timestamp: %lu", topic, sensor->lastUpdate); |
|
|
ESP_LOGI(TAG, "got new values from %s, timestamp: %lu", topic, sensor->lastUpdate); |
|
|
ESP_LOGI(TAG, "%lu seconds ago", topic, getTimestamp() - sensor->lastUpdate); |
|
|
ESP_LOGI(TAG, "%lu seconds ago", topic, getTimestamp() - sensor->lastUpdate); |
|
|
} |
|
|
} |
|
|