Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a7c23852cc |
@ -2,18 +2,27 @@
|
||||
#define SERIAL_DEBUG
|
||||
//#define OLED_OUTPUT
|
||||
//#define BATTERY_USE
|
||||
#define BME2_USE
|
||||
//#define BME2_USE
|
||||
//#define BME6_USE
|
||||
#define BH_USE
|
||||
//#define BH_USE
|
||||
//#define SHT_USE
|
||||
//#define VEML_USE
|
||||
//#define CCS_USE
|
||||
#define SGP30_USE
|
||||
//#define SGP30_USE
|
||||
#define SDS011_USE
|
||||
#define SI7021_USE
|
||||
|
||||
const bool metric = true;
|
||||
/************************* generic libs *********************************/
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266httpUpdate.h>
|
||||
#endif
|
||||
#if defined(ESP32)
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MQTTClient.h>
|
||||
#include <IPAddress.h>
|
||||
@ -85,51 +94,64 @@ const int WIFI_CONNECT_TIMEOUT = 10; // seconds - max time for wifi connect to r
|
||||
|
||||
|
||||
//ToDo Legacy IPv4
|
||||
/*
|
||||
IPAddress ip(10, 0, 4, 14);
|
||||
IPAddress gateway(10, 0, 4, 1);
|
||||
IPAddress subnet(255, 255, 255, 240);
|
||||
IPAddress dns(10, 0, 4, 1);
|
||||
*/
|
||||
IPAddress mqttBroker(10, 0, 4, 1); //failsafe
|
||||
|
||||
/********************* Firmware update **************************************/
|
||||
const int FW_VERSION = 10;
|
||||
const char* fwUrlBase = "http://10.0.4.2/fota/";
|
||||
const char* fwUrlBase = "";
|
||||
/************************* MQTT Broker Setup *********************************/
|
||||
#define name "test"
|
||||
#define name "bund"
|
||||
//see secrets.h
|
||||
char MQTT_CLIENTID[10];
|
||||
const char MQTT_WILL_TOPIC[] = "test/sys/will";
|
||||
const int MQTT_PORT = 1883;
|
||||
const char MQTT_SERVER[] = "mqtt.koelner.dynvpn.de";
|
||||
const char MQTT_USERNAME[] = mqttUser;
|
||||
const char MQTT_PASSWORD[] = mqttPass;
|
||||
const char MQTT_WILL_TOPIC[] = "unsafe/sys/will";
|
||||
const int MQTT_WILL_QOS = 0;
|
||||
const int MQTT_WILL_RETAIN = 0;
|
||||
const char MQTT_WILL_MESSAGE[] = "Finally died...";
|
||||
const char MQTT_WILL_MESSAGE[] = "Look out of the window!";
|
||||
/****************************** Feeds ***************************************/
|
||||
//ToDo: generate feed from CLIENTID and determine the ClientID from the ChipID
|
||||
#if defined(BME2_USE) || defined(BME6_USE)
|
||||
const char TEMPERATURE_FEED[] = "test/sensors/temperature";
|
||||
const char PRESSURE_FEED[] = "test/sensors/pressure";
|
||||
const char HUMIDITY_FEED[] = "test/sensors/humidity";
|
||||
const char ABSHUMIDITY_FEED[] = "test/sensors/abshumidity";
|
||||
const char TEMPERATURE_FEED[] = "unsafe/sensors/temperature";
|
||||
const char PRESSURE_FEED[] = "unsafe/sensors/pressure";
|
||||
const char HUMIDITY_FEED[] = "unsafe/sensors/humidity";
|
||||
const char ABSHUMIDITY_FEED[] = "unsafe/sensors/abshumidity";
|
||||
#endif
|
||||
#if defined(SHT_USE)
|
||||
const char TEMPERATURE_FEED[] = "test/sensors/temperature";
|
||||
const char HUMIDITY_FEED[] = "test/sensors/humidity";
|
||||
const char ABSHUMIDITY_FEED[] = "test/sensors/abshumidity";
|
||||
#if defined(SHT_USE) || defined(SI7021_USE)
|
||||
const char TEMPERATURE_FEED[] = "unsafe/sensors/temperature";
|
||||
const char HUMIDITY_FEED[] = "unsafe/sensors/humidity";
|
||||
const char ABSHUMIDITY_FEED[] = "unsafe/sensors/abshumidity";
|
||||
#endif
|
||||
#ifdef BME6_USE
|
||||
const char IAQ_FEED[] = "test/sensors/iaq";
|
||||
const char IAQPREC_FEED[] = "test/sensors/iaqprec";
|
||||
const char IAQ_FEED[] = "unsafe/sensors/iaq";
|
||||
const char IAQPREC_FEED[] = "unsafe/sensors/iaqprec";
|
||||
#endif
|
||||
#ifdef VEML_USE
|
||||
const char UVA_FEED[] = "test/sensors/uva";
|
||||
const char UVB_FEED[] = "test/sensors/uvb";
|
||||
const char UVINDEX_FEED[] = "test/sensors/uvindex";
|
||||
const char UVA_FEED[] = "unsafe/sensors/uva";
|
||||
const char UVB_FEED[] = "unsafe/sensors/uvb";
|
||||
const char UVINDEX_FEED[] = "unsafe/sensors/uvindex";
|
||||
#endif
|
||||
#ifdef BH_USE
|
||||
const char LIGHT_FEED[] = "test/sensors/light";
|
||||
const char LIGHT_FEED[] = "unsafe/sensors/light";
|
||||
#endif
|
||||
#if defined (CCS_USE) || defined(SGP30_USE)
|
||||
const char ECO2_FEED[] = "test/sensors/eco2";
|
||||
const char TVOC_FEED[] = "test/sensors/tvoc";
|
||||
const char ECO2_FEED[] = "unsafe/sensors/eco2";
|
||||
const char TVOC_FEED[] = "unsafe/sensors/tvoc";
|
||||
#endif
|
||||
#if defined (SDS011_USE) || defined(SGP30_USE)
|
||||
const char PM10_FEED[] = "unsafe/sensors/pm10";
|
||||
const char PM10CORR_FEED[] = "unsafe/sensors/pm10corr";
|
||||
const char PM25_FEED[] = "unsafe/sensors/pm25";
|
||||
const char PM25CORR_FEED[] = "unsafe/sensors/pm25corr";
|
||||
#endif
|
||||
#ifdef BATTERY_USE
|
||||
const char BATTERY_FEED[] = "test/sys/battery";
|
||||
const char BATTERY_FEED[] = "unsafe/sys/battery";
|
||||
#endif
|
||||
|
69
main.ino
69
main.ino
@ -110,6 +110,28 @@ CCS811 ccs;
|
||||
SGP30 sgp;
|
||||
#endif
|
||||
|
||||
#ifdef SDS011_USE
|
||||
#ifndef ESP32
|
||||
#include <SoftwareSerial.h>
|
||||
#endif
|
||||
#include <Sds011.h>
|
||||
#define SDS_PIN_RX D7
|
||||
#define SDS_PIN_TX D6
|
||||
#ifdef ESP32
|
||||
HardwareSerial& serialSDS(Serial2);
|
||||
Sds011Async< HardwareSerial > sds011(serialSDS);
|
||||
#else
|
||||
SoftwareSerial serialSDS;
|
||||
Sds011Async< SoftwareSerial > sds011(serialSDS);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SI7021_USE
|
||||
//https://github.com/sparkfun/Si7021_Breakout/blob/master/Libraries/Arduino/Si7021/
|
||||
#include "SparkFun_Si7021_Breakout_Library.h"
|
||||
Weather THMeter;
|
||||
#endif
|
||||
|
||||
void messageReceived(String &topic, String &payload) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("incoming: " + topic + " - " + payload);
|
||||
@ -232,6 +254,16 @@ float tvoc(NAN);
|
||||
String tvoc_str;
|
||||
char tvocC[8];
|
||||
#endif
|
||||
#ifdef SDS011_USE
|
||||
double pm25(NAN);
|
||||
double pm10(NAN);
|
||||
double pm25corr(NAN);
|
||||
double pm10corr(NAN);
|
||||
String pm25_str;
|
||||
String pm10_str;
|
||||
char pm25x[8];
|
||||
char pm10x[8];
|
||||
#endif
|
||||
#ifdef BATTERY_USE
|
||||
float battery(NAN);
|
||||
String batt_str;
|
||||
@ -247,6 +279,8 @@ bool bh1750Check = false;
|
||||
bool ccs811Check = false;
|
||||
bool sht30Check = false;
|
||||
bool sgp30Check = false;
|
||||
bool sds011Check = false;
|
||||
bool si7021Check = false;
|
||||
|
||||
WiFiClient mqttSocket;
|
||||
MQTTClient mqttClient;
|
||||
@ -634,6 +668,18 @@ void initSensors() {
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*********************SI7021 I2C init **************************************/
|
||||
#ifdef SI7021_USE
|
||||
Serial.print(F("\tSI7021 init...\t"));
|
||||
if (!THMeter.begin())
|
||||
{
|
||||
Serial.println(F("no SI7021 detected!"));
|
||||
}
|
||||
else {
|
||||
si7021Check = true;
|
||||
Serial.println(F("SI7021 ready."));
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************** i2c init END ****************/
|
||||
}
|
||||
@ -713,6 +759,29 @@ void setup() {
|
||||
mqtt_disconnect();
|
||||
yield();
|
||||
}
|
||||
if (si7021Check) {
|
||||
//InProgress
|
||||
//ToDo Heater https://www.silabs.com/community/sensors/forum.topic.html/when_si7021_is_neede-8a2a
|
||||
float dewpoint = DewPoint(temperature, humidity);
|
||||
Serial.println("[DEBUG]: Taupunkt:\t" + String(dewpoint));
|
||||
if (humidity >= 80.0 || dewpoint > temperature) {
|
||||
THMeter.heaterOn();
|
||||
delay(50);
|
||||
|
||||
Serial.println(F("[DEBUG] : Si7021 Heater ON"));
|
||||
//THMeter.heaterOff();
|
||||
}
|
||||
int temporary = 500;
|
||||
while (temporary >= 0 && THMeter.getRH() >= 80.0) {
|
||||
Serial.print("[DEBUG]: " + String(temporary) + "\t");
|
||||
Serial.println(String(THMeter.getRH()));
|
||||
temporary--;
|
||||
delay(20);
|
||||
}
|
||||
THMeter.heaterOff();
|
||||
//InProgress
|
||||
Serial.println(F("[DEBUG] : Si7021 Heater OFF"));
|
||||
}
|
||||
//firmware update check
|
||||
/*if (firmware_available()
|
||||
//{
|
||||
|
266
measurement.ino
266
measurement.ino
@ -1,4 +1,30 @@
|
||||
// The example stops the sensor for 10s, then runs it for 30s, then repeats.
|
||||
// At tablesizes 19 and below, the tables get filled during duty cycle
|
||||
// and measurement completes.
|
||||
// At tablesizes 20 and above, the tables do not get completely filled
|
||||
// and the rampup / 4 timeout trips, completing measurement at whatever
|
||||
// number of measurements were recorded in the tables.
|
||||
constexpr int pm_tablesize = 20;
|
||||
int pm25_table[pm_tablesize];
|
||||
int pm10_table[pm_tablesize];
|
||||
|
||||
bool is_SDS_running = true;
|
||||
|
||||
void start_SDS() {
|
||||
Serial.println("Start wakeup SDS011");
|
||||
|
||||
if (sds011.set_sleep(false)) { is_SDS_running = true; }
|
||||
|
||||
Serial.println("End wakeup SDS011");
|
||||
}
|
||||
|
||||
void stop_SDS() {
|
||||
Serial.println("Start sleep SDS011");
|
||||
|
||||
if (sds011.set_sleep(true)) { is_SDS_running = false; }
|
||||
|
||||
Serial.println("End sleep SDS011");
|
||||
}
|
||||
/********************* Measurement **************************************/
|
||||
void measurement() {
|
||||
|
||||
@ -148,41 +174,44 @@ void measurement() {
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/************************** ADC Measurement *********************************/
|
||||
#ifdef BATTERY_USE
|
||||
adc = analogRead(A0);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("ADC Read:\t" + String(adc) );
|
||||
|
||||
#ifdef SDS011_USE
|
||||
#endif
|
||||
yield();
|
||||
delay(10);
|
||||
batt_str = String(float(voltageDivCorrelation(adc) - BATT_MEASUREMENT_OFFSET) / 100);
|
||||
batt_str.toCharArray(batt, batt_str.length() + 1);
|
||||
/************************** ADC Measurement *********************************/
|
||||
#ifdef BATTERY_USE
|
||||
adc = analogRead(A0);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Battery Read:\t" + batt_str + " V" + "\t\t\t");
|
||||
Serial.println("ADC Read:\t" + String(adc) );
|
||||
#endif
|
||||
yield();
|
||||
delay(10);
|
||||
batt_str = String(float(voltageDivCorrelation(adc) - BATT_MEASUREMENT_OFFSET) / 100);
|
||||
batt_str.toCharArray(batt, batt_str.length() + 1);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Battery Read:\t" + batt_str + " V" + "\t\t\t");
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Publish Battery: \t\t");
|
||||
Serial.print("Publish Battery: \t\t");
|
||||
#endif
|
||||
if (! mqttClient.publish(BATTERY_FEED, batt, true, 1) || !mqttClient.loop()) {
|
||||
if (! mqttClient.publish(BATTERY_FEED, batt, true, 1) || !mqttClient.loop()) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Failed!");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("OK");
|
||||
#endif
|
||||
}
|
||||
yield();
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
yield();
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
#endif
|
||||
/********************* Temperature **************************************/
|
||||
/********************* Temperature **************************************/
|
||||
#ifdef BME2_USE
|
||||
if (bme280Check) {
|
||||
if (bme280Check) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Temperature:\t");
|
||||
Serial.print(temperature);
|
||||
@ -295,11 +324,11 @@ if (bme280Check) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/********************* Temperature **************************************/
|
||||
/********************* Temperature **************************************/
|
||||
#ifdef SHT_USE
|
||||
if (sht30Check) {
|
||||
if (sht30Check) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Temperature:\t");
|
||||
Serial.print(temperature);
|
||||
@ -375,11 +404,11 @@ if (sht30Check) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif //SHT_USE
|
||||
/********************* Temperature **************************************/
|
||||
/********************* Temperature **************************************/
|
||||
#ifdef SI7021_USE
|
||||
if (si7021Check) {
|
||||
if (si7021Check) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Temperature:\t");
|
||||
Serial.print(temperature);
|
||||
@ -455,11 +484,11 @@ if (si7021Check) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/********************* UVA **************************************/
|
||||
/********************* UVA **************************************/
|
||||
#ifdef VEML_USE
|
||||
if (veml6075Check) {
|
||||
if (veml6075Check) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("UVA:\t\t");
|
||||
Serial.print(uvalight);
|
||||
@ -571,11 +600,11 @@ if (veml6075Check) {
|
||||
}
|
||||
mqttClient.loop();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/********************* visible light **************************************/
|
||||
/********************* visible light **************************************/
|
||||
#ifdef BH_USE
|
||||
if (bh1750Check && vislight >= 0.0) {
|
||||
if (bh1750Check && vislight >= 0.0) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Light:\t\t");
|
||||
Serial.print(vislight);
|
||||
@ -613,11 +642,11 @@ if (bh1750Check && vislight >= 0.0) {
|
||||
}
|
||||
mqttClient.loop();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/********************* Absolute Humidity **************************************/
|
||||
/********************* Absolute Humidity **************************************/
|
||||
#ifdef SHT_USE
|
||||
if (sht30Check) {
|
||||
if (sht30Check) {
|
||||
absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("abs Humidity:\t");
|
||||
@ -655,11 +684,11 @@ if (sht30Check) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/********************* Absolute Humidity **************************************/
|
||||
/********************* Absolute Humidity **************************************/
|
||||
#ifdef SI7021_USE
|
||||
if (si7021Check) {
|
||||
if (si7021Check) {
|
||||
absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("abs Humidity:\t");
|
||||
@ -697,12 +726,12 @@ if (si7021Check) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************* Absolute Humidity **************************************/
|
||||
/********************* Absolute Humidity **************************************/
|
||||
#ifdef BME2_USE
|
||||
if (bme280Check) {
|
||||
if (bme280Check) {
|
||||
absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("abs Humidity:\t");
|
||||
@ -740,13 +769,13 @@ if (bme280Check) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************* eCO2 **************************************/
|
||||
/********************* eCO2 **************************************/
|
||||
#ifdef CCS_USE
|
||||
//fix sensors internal wait delay
|
||||
if (ccs811Check && eco2 > 0.00) {
|
||||
//fix sensors internal wait delay
|
||||
if (ccs811Check && eco2 > 0.00) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("eCO2:\t\t");
|
||||
Serial.print(eco2);
|
||||
@ -783,12 +812,12 @@ if (ccs811Check && eco2 > 0.00) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/********************* TVOC **************************************/
|
||||
/********************* TVOC **************************************/
|
||||
#ifdef CCS_USE
|
||||
//fix sensors internal wait delay
|
||||
if (ccs811Check && eco2 > 0.00) {
|
||||
//fix sensors internal wait delay
|
||||
if (ccs811Check && eco2 > 0.00) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("TVOC:\t\t");
|
||||
Serial.print(tvoc);
|
||||
@ -825,13 +854,13 @@ if (ccs811Check && eco2 > 0.00) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************* SGP30 eCO2 **************************************/
|
||||
/********************* SGP30 eCO2 **************************************/
|
||||
#ifdef SGP30_USE
|
||||
//fix sensors internal wait delay
|
||||
if (sgp30Check) {
|
||||
//fix sensors internal wait delay
|
||||
if (sgp30Check) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("eCO2:\t\t");
|
||||
Serial.print(eco2);
|
||||
@ -868,12 +897,12 @@ if (sgp30Check) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/********************* TVOC **************************************/
|
||||
/********************* TVOC **************************************/
|
||||
#ifdef SGP30_USE
|
||||
//fix sensors internal wait delay
|
||||
if (sgp30Check) {
|
||||
//fix sensors internal wait delay
|
||||
if (sgp30Check) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("TVOC:\t\t");
|
||||
Serial.print(tvoc);
|
||||
@ -910,11 +939,120 @@ if (sgp30Check) {
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/************************************ END *******************************/
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
return;
|
||||
/*****************PM2.5***************************************/
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("PM2.5:\t");
|
||||
Serial.print(pm25);
|
||||
Serial.print(" mg");
|
||||
Serial.print("\t\t");
|
||||
#endif
|
||||
pm25_str = String(pm25);
|
||||
pm25_str.toCharArray(pm25x, pm25_str.length() + 1);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Publish PM2.5: \t");
|
||||
#endif
|
||||
if (! mqttClient.publish(PM25_FEED, pm25x, true, 1) || !mqttClient.loop()) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Failed!");
|
||||
#endif
|
||||
} else {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("OK");
|
||||
#endif
|
||||
}
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
/*****************PM10***************************************/
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("PM10:\t");
|
||||
Serial.print(pm10);
|
||||
Serial.print(" mg");
|
||||
Serial.print("\t\t");
|
||||
#endif
|
||||
pm10_str = String(pm10);
|
||||
pm10_str.toCharArray(pm10x, pm10_str.length() + 1);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Publish PM10: \t");
|
||||
#endif
|
||||
if (! mqttClient.publish(PM10_FEED, pm10x, true, 1) || !mqttClient.loop()) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Failed!");
|
||||
#endif
|
||||
} else {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("OK");
|
||||
#endif
|
||||
}
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
/*****************PM2.5 Corr***************************************/
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("PM2.5Corr:\t");
|
||||
Serial.print(pm25corr);
|
||||
Serial.print(" mg");
|
||||
Serial.print("\t\t");
|
||||
#endif
|
||||
pm25_str = String(pm25corr);
|
||||
pm25_str.toCharArray(pm25x, pm25_str.length() + 1);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Publish PM2.5: \t");
|
||||
#endif
|
||||
if (! mqttClient.publish(PM25CORR_FEED, pm25x, true, 1) || !mqttClient.loop()) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Failed!");
|
||||
#endif
|
||||
} else {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("OK");
|
||||
#endif
|
||||
}
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
/*****************PM10 Corr***************************************/
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("PM10Corr:\t");
|
||||
Serial.print(pm10corr);
|
||||
Serial.print(" mg");
|
||||
Serial.print("\t\t");
|
||||
#endif
|
||||
pm10_str = String(pm10corr);
|
||||
pm10_str.toCharArray(pm10x, pm10_str.length() + 1);
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Publish PM10Corr: \t");
|
||||
#endif
|
||||
if (! mqttClient.publish(PM10CORR_FEED, pm10x, true, 1) || !mqttClient.loop()) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Failed!");
|
||||
#endif
|
||||
} else {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("OK");
|
||||
#endif
|
||||
}
|
||||
/************************************ END *******************************/
|
||||
mqttClient.loop();
|
||||
yield();
|
||||
delay(10);
|
||||
return;
|
||||
}
|
||||
float DewPoint
|
||||
(
|
||||
float temp,
|
||||
float hum
|
||||
)
|
||||
{
|
||||
// Equations courtesy of Brian McNoldy from http://andrew.rsmas.miami.edu;
|
||||
float dewPoint = NAN;
|
||||
|
||||
if (!isnan(temp) && !isnan(hum))
|
||||
{
|
||||
dewPoint = 243.04 * (log(hum / 100.0) + ((17.625 * temp) / (243.04 + temp)))
|
||||
/ (17.625 - log(hum / 100.0) - ((17.625 * temp) / (243.04 + temp)));
|
||||
}
|
||||
return dewPoint;
|
||||
}
|
||||
|
2
wifi.ino
2
wifi.ino
@ -50,7 +50,7 @@ bool wifi_connect() {
|
||||
// http://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html#persistent
|
||||
WiFi.persistent (false);
|
||||
WiFi.hostname(name); //ToDo Change to correct value
|
||||
WiFi.config(ip, gateway, subnet, dns);
|
||||
//WiFi.config(ip, gateway, subnet, dns);
|
||||
// Connect to WiFi access point.
|
||||
if( rtcValid ) {
|
||||
// The RTC data was good, make a quick connection
|
||||
|
Loading…
Reference in New Issue
Block a user