|
@ -18,7 +18,7 @@ extern "C" { |
|
|
#include <Wire.h> |
|
|
#include <Wire.h> |
|
|
#include <SPI.h> |
|
|
#include <SPI.h> |
|
|
#include <Adafruit_Sensor.h> |
|
|
#include <Adafruit_Sensor.h> |
|
|
#include <Adafruit_BMP085_U.h> |
|
|
#include <Adafruit_BME280.h> |
|
|
#include <DHT.h> |
|
|
#include <DHT.h> |
|
|
|
|
|
|
|
|
#include <RunningAverage.h> |
|
|
#include <RunningAverage.h> |
|
@ -66,8 +66,8 @@ uint32_t loop_count = 0; |
|
|
#define SENSOR8_ID "5a9eddb1f55bff001a51de52" |
|
|
#define SENSOR8_ID "5a9eddb1f55bff001a51de52" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static constexpr uint8_t BMP_SCL = D4; |
|
|
static constexpr uint8_t BME_SCL = D4; |
|
|
static constexpr uint8_t BMP_SDA = D3; |
|
|
static constexpr uint8_t BME_SDA = D3; |
|
|
|
|
|
|
|
|
static constexpr uint8_t DHT22_PIN = D7; |
|
|
static constexpr uint8_t DHT22_PIN = D7; |
|
|
static constexpr uint8_t DHTTYPE = DHT22; // DHT 22 (AM2302)
|
|
|
static constexpr uint8_t DHTTYPE = DHT22; // DHT 22 (AM2302)
|
|
@ -87,6 +87,7 @@ ADC_MODE(ADC_VCC); |
|
|
|
|
|
|
|
|
ESP8266WiFiMulti wifiMulti; |
|
|
ESP8266WiFiMulti wifiMulti; |
|
|
|
|
|
|
|
|
|
|
|
WiFiClient wificlient; |
|
|
HTTPClient httpclient; |
|
|
HTTPClient httpclient; |
|
|
BearSSL::WiFiClientSecure net; |
|
|
BearSSL::WiFiClientSecure net; |
|
|
MQTTClient mqttclient(MQTT_MAX_PACKET_SIZE); |
|
|
MQTTClient mqttclient(MQTT_MAX_PACKET_SIZE); |
|
@ -94,7 +95,10 @@ MQTTClient mqttclient(MQTT_MAX_PACKET_SIZE); |
|
|
os_timer_t Timer1; |
|
|
os_timer_t Timer1; |
|
|
RunningAverage geigeraverage(10); |
|
|
RunningAverage geigeraverage(10); |
|
|
|
|
|
|
|
|
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); |
|
|
Adafruit_BME280 bme; // use I2C interface
|
|
|
|
|
|
//Adafruit_Sensor *bme_temp = bme.getTemperatureSensor();
|
|
|
|
|
|
//Adafruit_Sensor *bme_pressure = bme.getPressureSensor();
|
|
|
|
|
|
//Adafruit_Sensor *bme_humidity = bme.getHumiditySensor();
|
|
|
DHT dht(DHT22_PIN, DHTTYPE); |
|
|
DHT dht(DHT22_PIN, DHTTYPE); |
|
|
SdsDustSensor sds(SDS_TX, SDS_RX); |
|
|
SdsDustSensor sds(SDS_TX, SDS_RX); |
|
|
volatile unsigned long geiger_counts = 0; |
|
|
volatile unsigned long geiger_counts = 0; |
|
@ -112,6 +116,7 @@ struct __attribute__((packed)) SENSOR_DATA { |
|
|
float humidity; |
|
|
float humidity; |
|
|
float pressure; |
|
|
float pressure; |
|
|
float temp2; |
|
|
float temp2; |
|
|
|
|
|
float humidity2; |
|
|
float p10; |
|
|
float p10; |
|
|
float p25; |
|
|
float p25; |
|
|
float cpm; |
|
|
float cpm; |
|
@ -233,12 +238,18 @@ void ICACHE_FLASH_ATTR getValuesJSON(char* buffer, const size_t buf_len, int for |
|
|
void ICACHE_FLASH_ATTR sendValues() { |
|
|
void ICACHE_FLASH_ATTR sendValues() { |
|
|
unsigned long currentMillis = rtcMillis(); |
|
|
unsigned long currentMillis = rtcMillis(); |
|
|
|
|
|
|
|
|
sd.temperature = dht.readTemperature(); |
|
|
bme.takeForcedMeasurement(); // has no effect in normal mode
|
|
|
sd.humidity = dht.readHumidity(); |
|
|
|
|
|
|
|
|
|
|
|
bmp.getPressure(&(sd.pressure)); |
|
|
sd.temp2 = dht.readTemperature(); |
|
|
sd.pressure /= 100; |
|
|
sd.humidity2 = dht.readHumidity(); |
|
|
bmp.getTemperature(&(sd.temp2)); |
|
|
|
|
|
|
|
|
//bmp.getPressure(&(sd.pressure));
|
|
|
|
|
|
//sd.pressure /= 100;
|
|
|
|
|
|
//bmp.getTemperature(&(sd.temp2));
|
|
|
|
|
|
|
|
|
|
|
|
sd.temperature = bme.readTemperature(); |
|
|
|
|
|
sd.humidity = bme.readHumidity(); |
|
|
|
|
|
sd.pressure = bme.readPressure() / 100.0F; |
|
|
|
|
|
|
|
|
#ifndef EXTERNAL_POWER |
|
|
#ifndef EXTERNAL_POWER |
|
|
sd.voltage = ESP.getVcc()/1024.0; |
|
|
sd.voltage = ESP.getVcc()/1024.0; |
|
@ -260,7 +271,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
|
|
|
|
|
|
if (rtcMillis() - geiger_previousMillis > 10000) { |
|
|
if (rtcMillis() - geiger_previousMillis > 10000) { |
|
|
sd.cpm = geiger_counts * 60000 / (rtcMillis() - geiger_previousMillis); |
|
|
sd.cpm = geiger_counts * 60000 / (rtcMillis() - geiger_previousMillis); |
|
|
DEBUG_MSG("[DEBUG] resetting geiger counts. was: %d\n", geiger_counts); |
|
|
DEBUG_MSG("[DEBUG] resetting geiger counts. was: %ld\n", geiger_counts); |
|
|
geiger_previousMillis = rtcMillis(); |
|
|
geiger_previousMillis = rtcMillis(); |
|
|
geiger_counts = 0; |
|
|
geiger_counts = 0; |
|
|
geigeraverage.addValue(sd.cpm); |
|
|
geigeraverage.addValue(sd.cpm); |
|
@ -269,10 +280,11 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
float constexpr own_cpm = OWN_BACKGROUND_CPS * 60; |
|
|
float constexpr own_cpm = OWN_BACKGROUND_CPS * 60; |
|
|
sd.radioactivity = (sd.cpm - own_cpm) * CONV_FACTOR; |
|
|
sd.radioactivity = (sd.cpm - own_cpm) * CONV_FACTOR; |
|
|
|
|
|
|
|
|
DEBUG_MSG("Temperature : %6.2f°C (DHT22)\n", sd.temperature); |
|
|
DEBUG_MSG("Temperature : %6.2f°C (BME280)\n", sd.temperature); |
|
|
DEBUG_MSG("Humidity : %6.2f%% (DHT22)\n", sd.humidity); |
|
|
DEBUG_MSG("Humidity : %6.2f%% (BME280)\n", sd.humidity); |
|
|
DEBUG_MSG("Temperature : %6.2f°C (BMP180)\n", sd.temp2); |
|
|
DEBUG_MSG("Pressure : %6.2fhPa (BME280)\n", sd.pressure); |
|
|
DEBUG_MSG("Pressure : %6.2fhPa (BMP180)\n", sd.pressure); |
|
|
DEBUG_MSG("Temperature : %6.2f°C (DHT22)\n", sd.temp2); |
|
|
|
|
|
DEBUG_MSG("Humidity : %6.2f%% (DHT22)\n", sd.humidity2); |
|
|
if (sd.sds_updated) DEBUG_MSG("Particles 10 : %6.2fµg/m³ (SDS011)\n", sd.p10); |
|
|
if (sd.sds_updated) DEBUG_MSG("Particles 10 : %6.2fµg/m³ (SDS011)\n", sd.p10); |
|
|
if (sd.sds_updated) DEBUG_MSG("Particles 2.5: %6.2fµg/m³ (SDS011)\n", sd.p25); |
|
|
if (sd.sds_updated) DEBUG_MSG("Particles 2.5: %6.2fµg/m³ (SDS011)\n", sd.p25); |
|
|
if (sd.cpm > 0) DEBUG_MSG("Radiation : %6.2fµSv/h (J305)\n", sd.radioactivity); |
|
|
if (sd.cpm > 0) DEBUG_MSG("Radiation : %6.2fµSv/h (J305)\n", sd.radioactivity); |
|
@ -359,7 +371,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
char url[100]; |
|
|
char url[100]; |
|
|
sprintf(url, "http://%s/boxes/%s/data", server, SENSEBOX_ID); |
|
|
sprintf(url, "http://%s/boxes/%s/data", server, SENSEBOX_ID); |
|
|
|
|
|
|
|
|
httpclient.begin(url); |
|
|
httpclient.begin(wificlient, url); |
|
|
httpclient.addHeader("Content-Type", "application/json"); |
|
|
httpclient.addHeader("Content-Type", "application/json"); |
|
|
|
|
|
|
|
|
httpCode = httpclient.POST(buffer); |
|
|
httpCode = httpclient.POST(buffer); |
|
@ -431,20 +443,28 @@ void setup() { |
|
|
Serial.begin(115200); |
|
|
Serial.begin(115200); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT); |
|
|
//pinMode(LED_BUILTIN, OUTPUT);
|
|
|
digitalWrite(LED_BUILTIN, HIGH); // turn OFF board led
|
|
|
//digitalWrite(LED_BUILTIN, HIGH); // turn OFF board led
|
|
|
|
|
|
|
|
|
//wifi_status_led_uninstall();
|
|
|
//wifi_status_led_uninstall();
|
|
|
|
|
|
|
|
|
|
|
|
Wire.begin(BME_SDA, BME_SCL); |
|
|
|
|
|
for (int tries=0; tries<5 && !bme.begin(0x76, &Wire); tries++) { |
|
|
|
|
|
DEBUG_MSG("[ERROR] No valid BME280 sensor!\n"); |
|
|
|
|
|
delay(20); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// weather monitoring
|
|
|
|
|
|
bme.setSampling(Adafruit_BME280::MODE_FORCED, |
|
|
|
|
|
Adafruit_BME280::SAMPLING_X1, // temperature
|
|
|
|
|
|
Adafruit_BME280::SAMPLING_X1, // pressure
|
|
|
|
|
|
Adafruit_BME280::SAMPLING_X1, // humidity
|
|
|
|
|
|
Adafruit_BME280::FILTER_OFF ); |
|
|
|
|
|
|
|
|
sds.begin(); |
|
|
sds.begin(); |
|
|
sds.setCustomWorkingPeriod(5); // sensor sends data every 5 minutes
|
|
|
sds.setCustomWorkingPeriod(5); // sensor sends data every 5 minutes
|
|
|
sds.setQueryReportingMode(); // ensures sensor is in 'query' reporting mode
|
|
|
sds.setQueryReportingMode(); // ensures sensor is in 'query' reporting mode
|
|
|
|
|
|
|
|
|
Wire.begin(BMP_SDA, BMP_SCL); |
|
|
|
|
|
if (!bmp.begin(BMP085_MODE_STANDARD)) { |
|
|
|
|
|
DEBUG_MSG("[ERROR] No valid BMP085 sensor!\n"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dht.begin(); |
|
|
dht.begin(); |
|
|
|
|
|
|
|
|
pinMode(GEIGER_PIN, INPUT); |
|
|
pinMode(GEIGER_PIN, INPUT); |
|
@ -466,11 +486,11 @@ void loop() { |
|
|
unsigned long currentMillis = rtcMillis(); |
|
|
unsigned long currentMillis = rtcMillis(); |
|
|
if ((currentMillis - previousMillis) >= postingInterval) { |
|
|
if ((currentMillis - previousMillis) >= postingInterval) { |
|
|
previousMillis = currentMillis; |
|
|
previousMillis = currentMillis; |
|
|
DEBUG_MSG("[DEBUG] sending values... previousMillis:%u, millis():%u, difference:%d\n", previousMillis, currentMillis, currentMillis-previousMillis); |
|
|
DEBUG_MSG("[DEBUG] sending values... previousMillis:%lu, millis():%lu, difference:%ld\n", previousMillis, currentMillis, currentMillis-previousMillis); |
|
|
sendValues(); |
|
|
sendValues(); |
|
|
} |
|
|
} |
|
|
DEBUG_MSG("[DEBUG] heap: %d\n", ESP.getFreeHeap()); |
|
|
DEBUG_MSG("[DEBUG] heap: %d\n", ESP.getFreeHeap()); |
|
|
DEBUG_MSG("[DEBUG] sleeping now... (%u)\n", currentMillis); |
|
|
DEBUG_MSG("[DEBUG] sleeping now... (%lu)\n", currentMillis); |
|
|
|
|
|
|
|
|
delay(10); |
|
|
delay(10); |
|
|
detachInterrupt(digitalPinToInterrupt(GEIGER_PIN)); |
|
|
detachInterrupt(digitalPinToInterrupt(GEIGER_PIN)); |
|
|