|
|
@ -24,6 +24,7 @@ |
|
|
|
#include "Adafruit_BME680.h" |
|
|
|
|
|
|
|
#include "Adafruit_VEML6075.h" |
|
|
|
#include <BH1750.h> |
|
|
|
|
|
|
|
#define ARDUINO_SAMD_VARIANT_COMPLIANCE |
|
|
|
#include "SdsDustSensor.h" |
|
|
@ -48,6 +49,7 @@ Adafruit_BME680 bme680; // I2C (also available: hardware SPI |
|
|
|
//HardwareSerial Serial2(2);
|
|
|
|
SdsDustSensor sds(Serial2); |
|
|
|
Adafruit_VEML6075 uv = Adafruit_VEML6075(); |
|
|
|
BH1750 lightMeter; |
|
|
|
|
|
|
|
XD0OTA ota("esp32-weatherstation"); |
|
|
|
XD0MQTT mqtt; |
|
|
@ -59,6 +61,7 @@ struct __attribute__((packed)) sensor_readings_t { |
|
|
|
uint32_t voc = 0; // Ohm
|
|
|
|
float pm10 = NAN; // µg/m³
|
|
|
|
float pm25 = NAN; // µg/m³
|
|
|
|
float lux = NAN; |
|
|
|
float uvi = NAN; |
|
|
|
float uva = NAN; |
|
|
|
float uvb = NAN; |
|
|
@ -75,6 +78,7 @@ uint32_t lastDisplayRefresh = 0; |
|
|
|
bool bme280_active = false; |
|
|
|
bool bme680_active = false; |
|
|
|
bool uv_active = false; |
|
|
|
bool light_active = false; |
|
|
|
bool sds_active = false; |
|
|
|
|
|
|
|
void helloWorld() |
|
|
@ -161,6 +165,10 @@ void getSensorMeasurements() { |
|
|
|
sensor_readings.uvb = uv.readUVB(); |
|
|
|
} |
|
|
|
|
|
|
|
if (light_active) { |
|
|
|
sensor_readings.lux = lightMeter.readLightLevel(); |
|
|
|
} |
|
|
|
|
|
|
|
if (sds_active) { |
|
|
|
PmResult pm = sds.readPm(); |
|
|
|
if (pm.isOk()) { |
|
|
@ -325,6 +333,11 @@ void displayValues() { |
|
|
|
display.printf("%.1f", pm10); |
|
|
|
display.setCursor(200,y_offset+65); |
|
|
|
display.printf("%.1f", pm25); |
|
|
|
// Lux
|
|
|
|
//display.setCursor(200,y_offset+80);
|
|
|
|
//display.println("Lux:");
|
|
|
|
//display.setCursor(200,y_offset+90);
|
|
|
|
//display.printf("%.1f", sensor_readings.lux);
|
|
|
|
// UV
|
|
|
|
float uvi, uva, uvb; |
|
|
|
if (uv_active) { |
|
|
@ -451,6 +464,12 @@ void sendValues() { |
|
|
|
delay(10); |
|
|
|
} |
|
|
|
|
|
|
|
if (light_active) { |
|
|
|
String topic_lux = String("thomas/sensor/") + ota.getMAC() + String("/lux"); |
|
|
|
mqtt.publish(topic_lux.c_str(), sensor_readings.lux, "%.2f"); |
|
|
|
delay(10); |
|
|
|
} |
|
|
|
|
|
|
|
if (sds_active) { |
|
|
|
String topic_pm10 = String("thomas/sensor/") + ota.getMAC() + String("/pm10"); |
|
|
|
String topic_pm25 = String("thomas/sensor/") + ota.getMAC() + String("/pm25"); |
|
|
@ -515,6 +534,10 @@ void setup() |
|
|
|
Serial.println("Failed to communicate with VEML6075 sensor, check wiring?"); |
|
|
|
} |
|
|
|
|
|
|
|
if (lightMeter.begin()) { |
|
|
|
light_active = true; |
|
|
|
} |
|
|
|
|
|
|
|
sds.begin(); |
|
|
|
|
|
|
|
FirmwareVersionResult sds_fw = sds.queryFirmwareVersion(); |
|
|
|