|
@ -82,22 +82,21 @@ struct __attribute__((packed)) SENSOR_DATA { |
|
|
float temp2; |
|
|
float temp2; |
|
|
float p10; |
|
|
float p10; |
|
|
float p25; |
|
|
float p25; |
|
|
|
|
|
unsigned long cpm; |
|
|
float radioactivity; |
|
|
float radioactivity; |
|
|
float voltage; |
|
|
float voltage; |
|
|
float rssi; |
|
|
float rssi; |
|
|
} sd; |
|
|
} sd; |
|
|
|
|
|
|
|
|
void ICACHE_FLASH_ATTR sendValues() { |
|
|
void ICACHE_FLASH_ATTR sendValues() { |
|
|
float temperature = dht.readTemperature(); |
|
|
sd.temperature = dht.readTemperature(); |
|
|
float humidity = dht.readHumidity(); |
|
|
sd.humidity = dht.readHumidity(); |
|
|
|
|
|
|
|
|
float pressure, temp2; |
|
|
bmp.getPressure(&(sd.pressure)); |
|
|
bmp.getPressure(&pressure); |
|
|
sd.pressure /= 100; |
|
|
pressure /= 100; |
|
|
bmp.getTemperature(&(sd.temp2)); |
|
|
bmp.getTemperature(&temp2); |
|
|
|
|
|
|
|
|
|
|
|
float p10, p2_5; |
|
|
int sds_error = sds.read(&(sd.p25), &(sd.p10)); |
|
|
int sds_error = sds.read(&p2_5, &p10); |
|
|
|
|
|
if(!sds_error) { |
|
|
if(!sds_error) { |
|
|
// Serial.println("SDS011 updated.");
|
|
|
// Serial.println("SDS011 updated.");
|
|
|
} else { |
|
|
} else { |
|
@ -106,57 +105,57 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
|
|
|
|
|
|
// sds.sleep();
|
|
|
// sds.sleep();
|
|
|
|
|
|
|
|
|
unsigned long cpm = 0; |
|
|
sd.cpm = 0; |
|
|
float radiationValue = -1; |
|
|
sd.radioactivity = -1; |
|
|
if (millis() - geiger_previousMillis > logging_period_ms) { |
|
|
if (millis() - geiger_previousMillis > logging_period_ms) { |
|
|
cpm = geiger_counts * 60000 / (millis() - geiger_previousMillis); |
|
|
sd.cpm = geiger_counts * 60000 / (millis() - geiger_previousMillis); |
|
|
unsigned long constexpr own_cpm = OWN_BACKGROUND_CPS * 60; |
|
|
unsigned long constexpr own_cpm = OWN_BACKGROUND_CPS * 60; |
|
|
geiger_previousMillis = millis(); |
|
|
geiger_previousMillis = millis(); |
|
|
geiger_counts = 0; |
|
|
geiger_counts = 0; |
|
|
radiationValue = (cpm - own_cpm) * CONV_FACTOR; |
|
|
sd.radioactivity = (sd.cpm - own_cpm) * CONV_FACTOR; |
|
|
// Serial.println(cpm);
|
|
|
// Serial.println(cpm);
|
|
|
} else { |
|
|
} else { |
|
|
// Serial.println("Geiger Counter: no new value");
|
|
|
// Serial.println("Geiger Counter: no new value");
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Serial.printf("Temperature : %6.2f°C (DHT22)\n", temperature); |
|
|
Serial.printf("Temperature : %6.2f°C (DHT22)\n", sd.temperature); |
|
|
Serial.printf("Humidity : %6.2f% (DHT22)\n", humidity); |
|
|
Serial.printf("Humidity : %6.2f% (DHT22)\n", sd.humidity); |
|
|
Serial.printf("Temperature : %6.2f°C (BMP180)\n", temp2); |
|
|
Serial.printf("Temperature : %6.2f°C (BMP180)\n", sd.temp2); |
|
|
Serial.printf("Pressure : %6.2fhPa (BMP180)\n", pressure); |
|
|
Serial.printf("Pressure : %6.2fhPa (BMP180)\n", sd.pressure); |
|
|
if (!sds_error) Serial.printf("Particles 10 : %6.2fµg/m³ (SDS011)\n", p10); |
|
|
if (!sds_error) Serial.printf("Particles 10 : %6.2fµg/m³ (SDS011)\n", sd.p10); |
|
|
if (!sds_error) Serial.printf("Particles 2.5: %6.2fµg/m³ (SDS011)\n", p2_5); |
|
|
if (!sds_error) Serial.printf("Particles 2.5: %6.2fµg/m³ (SDS011)\n", sd.p25); |
|
|
if (cpm > 0) Serial.printf("Radiation : %6.2fµSv/h (J305)\n", radiationValue); |
|
|
if (sd.cpm > 0) Serial.printf("Radiation : %6.2fµSv/h (J305)\n", sd.radioactivity); |
|
|
|
|
|
|
|
|
DynamicJsonBuffer jsonBuffer; |
|
|
DynamicJsonBuffer jsonBuffer; |
|
|
JsonArray& array = jsonBuffer.createArray(); |
|
|
JsonArray& array = jsonBuffer.createArray(); |
|
|
|
|
|
|
|
|
JsonObject& temperatureObject = array.createNestedObject(); |
|
|
JsonObject& temperatureObject = array.createNestedObject(); |
|
|
temperatureObject["sensor"] = SENSOR1_ID; |
|
|
temperatureObject["sensor"] = SENSOR1_ID; |
|
|
temperatureObject["value"] = temperature; |
|
|
temperatureObject["value"] = sd.temperature; |
|
|
|
|
|
|
|
|
JsonObject& humidityObject = array.createNestedObject(); |
|
|
JsonObject& humidityObject = array.createNestedObject(); |
|
|
humidityObject["sensor"] = SENSOR2_ID; |
|
|
humidityObject["sensor"] = SENSOR2_ID; |
|
|
humidityObject["value"] = humidity; |
|
|
humidityObject["value"] = sd.humidity; |
|
|
|
|
|
|
|
|
JsonObject& pressureObject = array.createNestedObject(); |
|
|
JsonObject& pressureObject = array.createNestedObject(); |
|
|
pressureObject["sensor"] = SENSOR3_ID; |
|
|
pressureObject["sensor"] = SENSOR3_ID; |
|
|
pressureObject["value"] = pressure; |
|
|
pressureObject["value"] = sd.pressure; |
|
|
|
|
|
|
|
|
if (!sds_error) { |
|
|
if (!sds_error) { |
|
|
JsonObject& pm10Object = array.createNestedObject(); |
|
|
JsonObject& pm10Object = array.createNestedObject(); |
|
|
pm10Object["sensor"] = SENSOR4_ID; |
|
|
pm10Object["sensor"] = SENSOR4_ID; |
|
|
pm10Object["value"] = p10; |
|
|
pm10Object["value"] = sd.p10; |
|
|
|
|
|
|
|
|
JsonObject& pm25Object = array.createNestedObject(); |
|
|
JsonObject& pm25Object = array.createNestedObject(); |
|
|
pm25Object["sensor"] = SENSOR5_ID; |
|
|
pm25Object["sensor"] = SENSOR5_ID; |
|
|
pm25Object["value"] = p2_5; |
|
|
pm25Object["value"] = sd.p25; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (cpm > 0) { |
|
|
if (sd.cpm > 0) { |
|
|
JsonObject& cpmObject = array.createNestedObject(); |
|
|
JsonObject& cpmObject = array.createNestedObject(); |
|
|
cpmObject["sensor"] = SENSOR6_ID; |
|
|
cpmObject["sensor"] = SENSOR6_ID; |
|
|
cpmObject["value"] = radiationValue; |
|
|
cpmObject["value"] = sd.radioactivity; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
JsonObject& voltageObject = array.createNestedObject(); |
|
|
JsonObject& voltageObject = array.createNestedObject(); |
|
@ -184,8 +183,8 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
Serial.print("."); |
|
|
Serial.print("."); |
|
|
if (tries > 20) { |
|
|
if (tries > 20) { |
|
|
Serial.println(" [ERROR]"); |
|
|
Serial.println(" [ERROR]"); |
|
|
Serial.println("Retrying in 1 minute.."); |
|
|
Serial.println("Retrying in 10 seconds.."); |
|
|
delay(postingInterval); |
|
|
delay(powerbankInterval); |
|
|
ESP.restart(); |
|
|
ESP.restart(); |
|
|
} |
|
|
} |
|
|
delay(500); |
|
|
delay(500); |
|
@ -256,7 +255,7 @@ void sendESPNOW() { |
|
|
WiFi.forceSleepBegin(); |
|
|
WiFi.forceSleepBegin(); |
|
|
delay(1); // yield();
|
|
|
delay(1); // yield();
|
|
|
digitalWrite(LED_BUILTIN, HIGH); |
|
|
digitalWrite(LED_BUILTIN, HIGH); |
|
|
Serial.printf("sendESPNOW() took %d ms\n", millis()-espnowmillis); |
|
|
// Serial.printf("sendESPNOW() took %d ms\n", millis()-espnowmillis);
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ICACHE_RAM_ATTR ISR_geiger_impulse() { |
|
|
void ICACHE_RAM_ATTR ISR_geiger_impulse() { |
|
|