diff --git a/code/espurna/analog.ino b/code/espurna/analog.ino new file mode 100644 index 00000000..c5a641e5 --- /dev/null +++ b/code/espurna/analog.ino @@ -0,0 +1,54 @@ +/* + +ANALOG MODULE + +Copyright (C) 2016-2017 by Xose PĂ©rez + +*/ + +#if ENABLE_ANALOG + +int _analog = 0; + +// ----------------------------------------------------------------------------- +// ANALOG +// ----------------------------------------------------------------------------- + +double getAnalog() { + return _analog; +} + +void analogSetup() { + //pinMode(0, INPUT); +} + +void analogLoop() { + + // Check if we should read new data + static unsigned long last_update = 0; + if ((millis() - last_update > ANALOG_UPDATE_INTERVAL) || (last_update == 0)) { + + _analog = analogRead(0); + + DEBUG_MSG_P(PSTR("[ANALOG] Value: %d\n"), _analog); + + last_update = millis(); + + // Send MQTT messages + mqttSend(getSetting("analogTmpTopic", ANALOG_TOPIC).c_str(), String(_analog).c_str()); + + // Send to Domoticz + #if ENABLE_DOMOTICZ + // domoticzSend("dczTmpIdx", 0, _analog); + #endif + + // Update websocket clients + char buffer[100]; + sprintf_P(buffer, PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), _analog); + wsSend(buffer); + + } + +} + +#endif diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 1d02f061..825729c7 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -35,6 +35,13 @@ #define LED1_PIN 2 #define LED1_PIN_INVERSE 1 +#elif defined(D1_MINI) + #define MANUFACTURER "WEMOS" + #define DEVICE "D1_MINI" + #define LED1_PIN 2 + #define LED1_PIN_INVERSE 1 + + #elif defined(D1_RELAYSHIELD) #define MANUFACTURER "WEMOS" diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index bd2c069d..45cbd25c 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -25,6 +25,14 @@ #define HUMIDITY_DRY 2 #define HUMIDITY_WET 3 +//-------------------------------------------------------------------------------- +// Analog sensor +// Enable support by passing ENABLE_ANALOG=1 build flag +//-------------------------------------------------------------------------------- + +#define ANALOG_UPDATE_INTERVAL 60000 +#define ANALOG_TOPIC "/analog" + //-------------------------------------------------------------------------------- // DS18B20 temperature sensor // Enable support by passing ENABLE_DS18B20=1 build flag diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 5dd8b02b..2db8de36 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -181,6 +181,9 @@ void setup() { #if ENABLE_DS18B20 dsSetup(); #endif + #if ENABLE_ANALOG + analogSetup(); + #endif #if ENABLE_DHT dhtSetup(); #endif @@ -218,6 +221,9 @@ void loop() { #if ENABLE_DS18B20 dsLoop(); #endif + #if ENABLE_ANALOG + analogLoop(); + #endif #if ENABLE_DHT dhtLoop(); #endif diff --git a/code/html/index.html b/code/html/index.html index a4be8021..88c6b255 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -178,6 +178,11 @@ +
+ + +
+
diff --git a/code/platformio.ini b/code/platformio.ini index 5c99ce4f..f38db50d 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -31,6 +31,14 @@ lib_deps = lib_ignore = # ------------------------------------------------------------------------------ +[env:d1-analog] +platform = espressif8266 +framework = arduino +board = d1_mini +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +extra_script = pio_hooks.py +build_flags = ${common.build_flags} -DD1_MINI -DENABLE_DS18B20=1 -DDS_PIN=14 -DENABLE_ADC_VCC=0 -DMQTT_USE_ASYNC=0 -DENABLE_ANALOG=1 -DNOWSAUTH [env:d1-debug] platform = espressif8266