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()
|
||||
//{
|
||||
|
1146
measurement.ino
1146
measurement.ino
File diff suppressed because it is too large
Load Diff
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