134 lines
4.1 KiB
C++
134 lines
4.1 KiB
C++
/************************* settings *********************************/
|
|
#define SERIAL_DEBUG
|
|
//#define OLED_OUTPUT
|
|
//#define BATTERY_USE
|
|
//#define BME2_USE
|
|
//#define BME6_USE
|
|
//#define BH_USE
|
|
#define SHT_USE
|
|
//#define VEML_USE
|
|
//#define CCS_USE
|
|
const bool metric = true;
|
|
/************************* generic libs *********************************/
|
|
#include <ESP8266WiFi.h>
|
|
#include <ESP8266HTTPClient.h>
|
|
#include <ESP8266httpUpdate.h>
|
|
#include <Wire.h>
|
|
#include <MQTTClient.h>
|
|
#include <IPAddress.h>
|
|
/*
|
|
reset causes:
|
|
0:
|
|
1: normal boot
|
|
2: reset pin
|
|
3: software reset
|
|
4: watchdog reset
|
|
|
|
boot device:
|
|
0:
|
|
1: ram
|
|
3: flash
|
|
|
|
Label to GPIO NodeMCU
|
|
D0 = 16;
|
|
D1 = 5; SCL
|
|
D2 = 4; SDA
|
|
D3 = 0;
|
|
D4 = 2;
|
|
D5 = 14;
|
|
D6 = 12;
|
|
D7 = 13;
|
|
D8 = 15;
|
|
D9 = 3;
|
|
D10 = 1; builtinLED
|
|
|
|
Wemos D1 mini
|
|
builtinLED = 2
|
|
D0 = 16;
|
|
D1 = 5; SCL
|
|
D2 = 4; SDA
|
|
D3 = 0;
|
|
D4 = 2; builtinLED
|
|
D5 = 14;
|
|
D6 = 12;
|
|
D7 = 13; CCS INTERRUPT
|
|
D8 = 15;
|
|
RX = 3;
|
|
TX = 1;
|
|
*/
|
|
/************************* state machine *********************************/
|
|
//the charger board cuts at 2.5V
|
|
//state definitions
|
|
#define STATE_COLDSTART 0
|
|
#define STATE_SLEEP_WAKE 1
|
|
#define STATE_FIRMWARE 2
|
|
#define STATE_MEASUREMENT 4
|
|
|
|
#define SLEEP_TIME 60*1000000UL // sleep intervalls in us (1min)
|
|
#define SLEEP_TIME_MEASUREMENT 1*SLEEP_TIME // sleep 60s(1min) after measurement
|
|
#define SLEEP_TIME_WIFI_TIMEOUT 1*SLEEP_TIME // sleep a minute
|
|
#ifdef BATTERY_USE
|
|
#define SLEEP_TIME_LOW_BAT 60*SLEEP_TIME // sleep 3600s(60min) after measurement
|
|
#define BATT_WARNING_VOLTAGE 270 // Voltage for Low-Bat warning in mV --rember the drop-out of the voltage regulator -- Be aware not to measure the VCC!
|
|
#define BATT_MEASUREMENT_OFFSET 20 //Meh, somewhere and somehow is something not that well...
|
|
#endif
|
|
|
|
/************************* WiFi Client *********************************/
|
|
|
|
#define WLAN_SSID "IoT"
|
|
#define WLAN_PASS "TF0xJJHtMz5kJUdh3dqf"
|
|
const int WIFI_CONNECT_TIMEOUT = 10; // seconds - max time for wifi connect to router, if exceeded go to sleep
|
|
|
|
|
|
//ToDo Legacy IPv4
|
|
IPAddress ip(10, 0, 4, 7);
|
|
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/";
|
|
/************************* MQTT Broker Setup *********************************/
|
|
const int MQTT_PORT = 1883;
|
|
const char MQTT_SERVER[] = "mqtt.koelner.dynvpn.de";
|
|
char MQTT_CLIENTID[10];
|
|
const char MQTT_USERNAME[] = "input";
|
|
const char MQTT_PASSWORD[] = "tFnlKJu9";
|
|
const char MQTT_WILL_TOPIC[] = "bathroom/sys/will";
|
|
const int MQTT_WILL_QOS = 0;
|
|
const int MQTT_WILL_RETAIN = 0;
|
|
const char MQTT_WILL_MESSAGE[] = "Finally died...";
|
|
/****************************** Feeds ***************************************/
|
|
//ToDo: generate feed from CLIENTID and determine the ClientID from the ChipID
|
|
#if defined(BME2_USE) || defined(BME6_USE)
|
|
const char TEMPERATURE_FEED[] = "bathroom/sensors/temperature";
|
|
const char PRESSURE_FEED[] = "bathroom/sensors/pressure";
|
|
const char HUMIDITY_FEED[] = "bathroom/sensors/humidity";
|
|
const char ABSHUMIDITY_FEED[] = "bathroom/sensors/abshumidity";
|
|
#endif
|
|
#if defined(SHT_USE)
|
|
const char TEMPERATURE_FEED[] = "bathroom/sensors/temperature";
|
|
const char HUMIDITY_FEED[] = "bathroom/sensors/humidity";
|
|
const char ABSHUMIDITY_FEED[] = "bathroom/sensors/abshumidity";
|
|
#endif
|
|
#ifdef BME6_USE
|
|
const char IAQ_FEED[] = "bathroom/sensors/iaq";
|
|
const char IAQPREC_FEED[] = "bathroom/sensors/iaqprec";
|
|
#endif
|
|
#ifdef VEML_USE
|
|
const char UVA_FEED[] = "bathroom/sensors/uva";
|
|
const char UVB_FEED[] = "bathroom/sensors/uvb";
|
|
const char UVINDEX_FEED[] = "bathroom/sensors/uvindex";
|
|
#endif
|
|
#ifdef BH_USE
|
|
const char LIGHT_FEED[] = "bathroom/sensors/light";
|
|
#endif
|
|
#ifdef CCS_USE
|
|
const char ECO2_FEED[] = "bathroom/sensors/eco2";
|
|
const char TVOC_FEED[] = "bathroom/sensors/tvoc";
|
|
#endif
|
|
#ifdef BATTERY_USE
|
|
const char BATTERY_FEED[] = "bathroom/sys/battery";
|
|
#endif
|