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