2018-12-06 19:14:48 +00:00
/************************* settings *********************************/
# define SERIAL_DEBUG
//#define OLED_OUTPUT
//#define BATTERY_USE
2019-04-05 10:52:42 +00:00
# define BME2_USE
2018-12-06 19:14:48 +00:00
//#define BME6_USE
2019-04-05 10:52:42 +00:00
# define BH_USE
//#define SHT_USE
2018-12-06 19:14:48 +00:00
//#define VEML_USE
//#define CCS_USE
2019-04-05 10:52:42 +00:00
# define SGP30_USE
2018-12-06 19:14:48 +00:00
const bool metric = true ;
/************************* generic libs *********************************/
# include <ESP8266WiFi.h>
# include <ESP8266HTTPClient.h>
# include <ESP8266httpUpdate.h>
# include <Wire.h>
# include <MQTTClient.h>
# include <IPAddress.h>
2019-03-29 19:41:00 +00:00
# include "EnvironmentCalculations.h"
# include "secrets.h"
2018-12-06 19:14:48 +00:00
/*
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!
2019-05-23 16:50:46 +00:00
# define BATT_MEASUREMENT_OFFSET 30 //Meh, somewhere and somehow is something not that well...
2018-12-06 19:14:48 +00:00
# endif
/************************* WiFi Client *********************************/
2019-04-05 10:52:42 +00:00
//see secrets.h
2018-12-06 19:14:48 +00:00
const int WIFI_CONNECT_TIMEOUT = 10 ; // seconds - max time for wifi connect to router, if exceeded go to sleep
//ToDo Legacy IPv4
2019-04-05 10:52:42 +00:00
IPAddress ip ( 10 , 0 , 4 , 14 ) ;
2018-12-06 19:14:48 +00:00
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 *********************************/
2019-04-05 10:52:42 +00:00
# define name "test"
//see secrets.h
2018-12-06 19:14:48 +00:00
char MQTT_CLIENTID [ 10 ] ;
2019-04-05 10:52:42 +00:00
const char MQTT_WILL_TOPIC [ ] = " test/sys/will " ;
2018-12-06 19:14:48 +00:00
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)
2019-04-05 10:52:42 +00:00
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 " ;
2018-12-06 19:14:48 +00:00
# endif
# if defined(SHT_USE)
2019-04-05 10:52:42 +00:00
const char TEMPERATURE_FEED [ ] = " test/sensors/temperature " ;
const char HUMIDITY_FEED [ ] = " test/sensors/humidity " ;
const char ABSHUMIDITY_FEED [ ] = " test/sensors/abshumidity " ;
2018-12-06 19:14:48 +00:00
# endif
# ifdef BME6_USE
2019-04-05 10:52:42 +00:00
const char IAQ_FEED [ ] = " test/sensors/iaq " ;
const char IAQPREC_FEED [ ] = " test/sensors/iaqprec " ;
2018-12-06 19:14:48 +00:00
# endif
# ifdef VEML_USE
2019-04-05 10:52:42 +00:00
const char UVA_FEED [ ] = " test/sensors/uva " ;
const char UVB_FEED [ ] = " test/sensors/uvb " ;
const char UVINDEX_FEED [ ] = " test/sensors/uvindex " ;
2018-12-06 19:14:48 +00:00
# endif
# ifdef BH_USE
2019-04-05 10:52:42 +00:00
const char LIGHT_FEED [ ] = " test/sensors/light " ;
2018-12-06 19:14:48 +00:00
# endif
2019-04-05 10:52:42 +00:00
# if defined (CCS_USE) || defined(SGP30_USE)
const char ECO2_FEED [ ] = " test/sensors/eco2 " ;
const char TVOC_FEED [ ] = " test/sensors/tvoc " ;
2018-12-06 19:14:48 +00:00
# endif
# ifdef BATTERY_USE
2019-04-05 10:52:42 +00:00
const char BATTERY_FEED [ ] = " test/sys/battery " ;
2018-12-06 19:14:48 +00:00
# endif