From 42b29747904353cdb0c893fdc39d0e42a210c977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 12 Apr 2018 00:08:46 +0200 Subject: [PATCH] Some fixings after configuration refactor --- code/espurna/config/dependencies.h | 50 ++-- code/espurna/config/general.h | 342 ++++++++++++------------ code/espurna/config/progmem.h | 11 +- code/espurna/config/prototypes.h | 14 - code/espurna/config/sensors.h | 27 +- code/espurna/config/types.h | 193 ++++++------- code/espurna/sensors/AnalogSensor.h | 4 + code/espurna/sensors/EmonAnalogSensor.h | 6 +- code/espurna/sensors/GUVAS12SDSensor.h | 7 +- code/espurna/sensors/TMP3XSensor.h | 7 +- code/espurna/utils.ino | 11 +- code/espurna/ws.ino | 4 +- 12 files changed, 337 insertions(+), 339 deletions(-) diff --git a/code/espurna/config/dependencies.h b/code/espurna/config/dependencies.h index 4ae45537..73d46e1b 100644 --- a/code/espurna/config/dependencies.h +++ b/code/espurna/config/dependencies.h @@ -2,45 +2,40 @@ //------------------------------------------------------------------------------ // Do not change this file unless you know what you are doing -// Configuration settings are in the settings.h file +// Configuration settings are in the general.h file //------------------------------------------------------------------------------ - #if DEBUG_TELNET_SUPPORT #undef TELNET_SUPPORT -#define TELNET_SUPPORT 1 -#endif - -#ifndef DEBUG_WEB_SUPPORT -#define DEBUG_WEB_SUPPORT WEB_SUPPORT // Enable web debug log if web is enabled too +#define TELNET_SUPPORT 1 #endif -#if DEBUG_WEB_SUPPORT -#undef WEB_SUPPORT -#define WEB_SUPPORT 1 // Chicken and egg :) +#if not WEB_SUPPORT +#undef DEBUG_WEB_SUPPORT +#define DEBUG_WEB_SUPPORT 0 #endif #if not WEB_SUPPORT #undef SSDP_SUPPORT -#define SSDP_SUPPORT 0 // SSDP support requires web support +#define SSDP_SUPPORT 0 // SSDP support requires web support #endif #if UART_MQTT_SUPPORT -#define MQTT_SUPPORT 1 +#define MQTT_SUPPORT 1 #undef TERMINAL_SUPPORT -#define TERMINAL_SUPPORT 0 +#define TERMINAL_SUPPORT 0 #undef DEBUG_SERIAL_SUPPORT -#define DEBUG_SERIAL_SUPPORT 0 +#define DEBUG_SERIAL_SUPPORT 0 #endif #if DOMOTICZ_SUPPORT #undef MQTT_SUPPORT -#define MQTT_SUPPORT 1 // If Domoticz enabled enable MQTT +#define MQTT_SUPPORT 1 // If Domoticz enabled enable MQTT #endif #if HOMEASSISTANT_SUPPORT #undef MQTT_SUPPORT -#define MQTT_SUPPORT 1 // If Home Assistant enabled enable MQTT +#define MQTT_SUPPORT 1 // If Home Assistant enabled enable MQTT #endif #ifndef ASYNC_TCP_SSL_ENABLED @@ -54,21 +49,18 @@ #define NTP_SUPPORT 1 // Scheduler needs NTP #endif -//------------------------------------------------------------------------------ -// Sensors -//------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------- +// Debug +// ----------------------------------------------------------------------------- +#define DEBUG_SUPPORT DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT || DEBUG_TELNET_SUPPORT || DEBUG_WEB_SUPPORT -#if ANALOG_SUPPORT -#undef ADC_VCC_ENABLED -#define ADC_VCC_ENABLED 0 +#if DEBUG_SUPPORT + #define DEBUG_MSG(...) debugSend(__VA_ARGS__) + #define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__) #endif -#if EMON_ANALOG_SUPPORT -#undef ADC_VCC_ENABLED -#define ADC_VCC_ENABLED 0 +#ifndef DEBUG_MSG + #define DEBUG_MSG(...) + #define DEBUG_MSG_P(...) #endif - -// I2C dependencies moved to actual sensor files. - -//------------------------------------------------------------------------------ diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 44d7a3f1..17273f29 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -10,33 +10,17 @@ #define DEVICE_NAME MANUFACTURER "_" DEVICE // Concatenate both to get a unique device name #ifndef ADMIN_PASS -#define ADMIN_PASS "fibonacci" // Default password (WEB, OTA, WIFI) +#define ADMIN_PASS "fibonacci" // Default password (WEB, OTA, WIFI) #endif #ifndef USE_PASSWORD -#define USE_PASSWORD 1 // Insecurity caution! Disabling this will disable password querying completely. +#define USE_PASSWORD 1 // Insecurity caution! Disabling this will disable password querying completely. #endif #ifndef LOOP_DELAY_TIME -#define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250] +#define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250] #endif - -//------------------------------------------------------------------------------ -// TELNET -//------------------------------------------------------------------------------ - -#ifndef TELNET_SUPPORT -#define TELNET_SUPPORT 1 // Enable telnet support by default (3.34Kb) -#endif - -#ifndef TELNET_STA -#define TELNET_STA 0 // By default, disallow connections via STA interface -#endif - -#define TELNET_PORT 23 // Port to listen to telnet clients -#define TELNET_MAX_CLIENTS 1 // Max number of concurrent telnet clients - //------------------------------------------------------------------------------ // DEBUG //------------------------------------------------------------------------------ @@ -67,7 +51,7 @@ #endif #ifndef SERIAL_RX_PORT -#define SERIAL_RX_PORT Serial // This setting is usually defined +#define SERIAL_RX_PORT Serial // This setting is usually defined // in the hardware.h file for those // boards that require it #endif @@ -97,23 +81,29 @@ //------------------------------------------------------------------------------ #ifndef DEBUG_TELNET_SUPPORT -#define DEBUG_TELNET_SUPPORT TELNET_SUPPORT // Enable telnet debug log if telnet is enabled too +#define DEBUG_TELNET_SUPPORT 1 // Enable telnet debug log (will only work if TELNET_SUPPORT is also 1) #endif -#ifndef DEBUG_UDP_SUPPORT -#define DEBUG_UDP_SUPPORT 0 // Enable UDP debug log -#endif -#define DEBUG_UDP_IP IPAddress(192, 168, 1, 100) -#define DEBUG_UDP_PORT 8113 +//------------------------------------------------------------------------------ -#ifndef DEBUG_WEB_ENABLED -#define DEBUG_WEB_ENABLED 1 // Enable debug output by default +#ifndef DEBUG_WEB_SUPPORT +#define DEBUG_WEB_SUPPORT 1 // Enable web debug log (will only work if WEB_SUPPORT is also 1) #endif +//------------------------------------------------------------------------------ +// TELNET //------------------------------------------------------------------------------ -// General debug options and macros -#define DEBUG_SUPPORT DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT || DEBUG_TELNET_SUPPORT +#ifndef TELNET_SUPPORT +#define TELNET_SUPPORT 1 // Enable telnet support by default (3.34Kb) +#endif + +#ifndef TELNET_STA +#define TELNET_STA 0 // By default, disallow connections via STA interface +#endif + +#define TELNET_PORT 23 // Port to listen to telnet clients +#define TELNET_MAX_CLIENTS 1 // Max number of concurrent telnet clients //------------------------------------------------------------------------------ // TERMINAL @@ -133,7 +123,9 @@ #define SYSTEM_CHECK_ENABLED 1 // Enable crash check by default #endif +#ifndef SYSTEM_CHECK_MAX #define SYSTEM_CHECK_TIME 60000 // The system is considered stable after these many millis +#endif #ifndef SYSTEM_CHECK_MAX #define SYSTEM_CHECK_MAX 5 // After this many crashes on boot @@ -160,7 +152,10 @@ #define HEARTBEAT_ENABLED 1 #endif +#ifndef HEARTBEAT_INTERVAL #define HEARTBEAT_INTERVAL 300000 // Interval between heartbeat messages (in ms) +#endif + #define UPTIME_OVERFLOW 4294967295 // Uptime overflow value // Topics that will be reported in heartbeat @@ -183,12 +178,13 @@ //------------------------------------------------------------------------------ // Load average //------------------------------------------------------------------------------ + #ifndef LOADAVG_INTERVAL -#define LOADAVG_INTERVAL 30000 // Interval between calculating load average (in ms) +#define LOADAVG_INTERVAL 30000 // Interval between calculating load average (in ms) #endif #ifndef LOADAVG_REPORT -#define LOADAVG_REPORT 1 // Should we report Load average over MQTT? +#define LOADAVG_REPORT 1 // Should we report Load average over MQTT? #endif //------------------------------------------------------------------------------ @@ -255,88 +251,87 @@ #define RELAY_SAVE_DELAY 1000 #endif - // ----------------------------------------------------------------------------- // WIFI // ----------------------------------------------------------------------------- #ifndef WIFI_CONNECT_TIMEOUT -#define WIFI_CONNECT_TIMEOUT 60000 // Connecting timeout for WIFI in ms +#define WIFI_CONNECT_TIMEOUT 60000 // Connecting timeout for WIFI in ms #endif #ifndef WIFI_RECONNECT_INTERVAL -#define WIFI_RECONNECT_INTERVAL 180000 // If could not connect to WIFI, retry after this time in ms +#define WIFI_RECONNECT_INTERVAL 180000 // If could not connect to WIFI, retry after this time in ms #endif -#define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations +#define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations #ifndef WIFI_AP_MODE -#define WIFI_AP_MODE AP_MODE_ALONE +#define WIFI_AP_MODE AP_MODE_ALONE #endif #ifndef WIFI_SLEEP_MODE -#define WIFI_SLEEP_MODE WIFI_NONE_SLEEP // WIFI_NONE_SLEEP, WIFI_LIGHT_SLEEP or WIFI_MODEM_SLEEP +#define WIFI_SLEEP_MODE WIFI_NONE_SLEEP // WIFI_NONE_SLEEP, WIFI_LIGHT_SLEEP or WIFI_MODEM_SLEEP #endif #ifndef WIFI_SCAN_NETWORKS -#define WIFI_SCAN_NETWORKS 1 // Perform a network scan before connecting +#define WIFI_SCAN_NETWORKS 1 // Perform a network scan before connecting #endif // Optional hardcoded configuration (up to 2 networks) #ifndef WIFI1_SSID -#define WIFI1_SSID "" +#define WIFI1_SSID "" #endif #ifndef WIFI1_PASS -#define WIFI1_PASS "" +#define WIFI1_PASS "" #endif #ifndef WIFI1_IP -#define WIFI1_IP "" +#define WIFI1_IP "" #endif #ifndef WIFI1_GW -#define WIFI1_GW "" +#define WIFI1_GW "" #endif #ifndef WIFI1_MASK -#define WIFI1_MASK "" +#define WIFI1_MASK "" #endif #ifndef WIFI1_DNS -#define WIFI1_DNS "" +#define WIFI1_DNS "" #endif #ifndef WIFI2_SSID -#define WIFI2_SSID "" +#define WIFI2_SSID "" #endif #ifndef WIFI2_PASS -#define WIFI2_PASS "" +#define WIFI2_PASS "" #endif #ifndef WIFI2_IP -#define WIFI2_IP "" +#define WIFI2_IP "" #endif #ifndef WIFI2_GW -#define WIFI2_GW "" +#define WIFI2_GW "" #endif #ifndef WIFI2_MASK -#define WIFI2_MASK "" +#define WIFI2_MASK "" #endif #ifndef WIFI2_DNS -#define WIFI2_DNS "" +#define WIFI2_DNS "" #endif #ifndef WIFI_RSSI_1M -#define WIFI_RSSI_1M -30 // Calibrate it with your router reading the RSSI at 1m +#define WIFI_RSSI_1M -30 // Calibrate it with your router reading the RSSI at 1m #endif #ifndef WIFI_PROPAGATION_CONST -#define WIFI_PROPAGATION_CONST 4 // This is typically something between 2.7 to 4.3 (free space is 2) +#define WIFI_PROPAGATION_CONST 4 // This is typically something between 2.7 to 4.3 (free space is 2) #endif // ----------------------------------------------------------------------------- @@ -344,32 +339,29 @@ // ----------------------------------------------------------------------------- #ifndef WEB_SUPPORT -#define WEB_SUPPORT 1 // Enable web support (http, api, 121.65Kb) +#define WEB_SUPPORT 1 // Enable web support (http, api, 121.65Kb) #endif #ifndef WEB_EMBEDDED -#define WEB_EMBEDDED 1 // Build the firmware with the web interface embedded in +#define WEB_EMBEDDED 1 // Build the firmware with the web interface embedded in #endif // This is not working at the moment!! // Requires ASYNC_TCP_SSL_ENABLED to 1 and ESP8266 Arduino Core 2.4.0 #ifndef WEB_SSL_ENABLED -#define WEB_SSL_ENABLED 0 // Use HTTPS web interface +#define WEB_SSL_ENABLED 0 // Use HTTPS web interface #endif -#define WEB_MODE_NORMAL 0 -#define WEB_MODE_PASSWORD 1 - #ifndef WEB_USERNAME -#define WEB_USERNAME "admin" // HTTP username +#define WEB_USERNAME "admin" // HTTP username #endif #ifndef WEB_FORCE_PASS_CHANGE -#define WEB_FORCE_PASS_CHANGE 1 // Force the user to change the password if default one +#define WEB_FORCE_PASS_CHANGE 1 // Force the user to change the password if default one #endif #ifndef WEB_PORT -#define WEB_PORT 80 // HTTP port +#define WEB_PORT 80 // HTTP port #endif // ----------------------------------------------------------------------------- @@ -378,19 +370,19 @@ // This will only be enabled if WEB_SUPPORT is 1 (this is the default value) #ifndef WS_AUTHENTICATION -#define WS_AUTHENTICATION 1 // WS authentication ON by default (see #507) +#define WS_AUTHENTICATION 1 // WS authentication ON by default (see #507) #endif #ifndef WS_BUFFER_SIZE -#define WS_BUFFER_SIZE 5 // Max number of secured websocket connections +#define WS_BUFFER_SIZE 5 // Max number of secured websocket connections #endif #ifndef WS_TIMEOUT -#define WS_TIMEOUT 1800000 // Timeout for secured websocket +#define WS_TIMEOUT 1800000 // Timeout for secured websocket #endif #ifndef WS_UPDATE_INTERVAL -#define WS_UPDATE_INTERVAL 30000 // Update clients every 30 seconds +#define WS_UPDATE_INTERVAL 30000 // Update clients every 30 seconds #endif // ----------------------------------------------------------------------------- @@ -399,15 +391,15 @@ // This will only be enabled if WEB_SUPPORT is 1 (this is the default value) #ifndef API_ENABLED -#define API_ENABLED 0 // Do not enable API by default +#define API_ENABLED 0 // Do not enable API by default #endif #ifndef API_BUFFER_SIZE -#define API_BUFFER_SIZE 15 // Size of the buffer for HTTP GET API responses +#define API_BUFFER_SIZE 15 // Size of the buffer for HTTP GET API responses #endif #ifndef API_REAL_TIME_VALUES -#define API_REAL_TIME_VALUES 0 // Show filtered/median values by default (0 => median, 1 => real time) +#define API_REAL_TIME_VALUES 0 // Show filtered/median values by default (0 => median, 1 => real time) #endif @@ -416,29 +408,29 @@ // ----------------------------------------------------------------------------- #ifndef MDNS_SERVER_SUPPORT -#define MDNS_SERVER_SUPPORT 1 // Publish services using mDNS by default (1.48Kb) +#define MDNS_SERVER_SUPPORT 1 // Publish services using mDNS by default (1.48Kb) #endif #ifndef MDNS_CLIENT_SUPPORT -#define MDNS_CLIENT_SUPPORT 0 // Resolve mDNS names (3.44Kb) +#define MDNS_CLIENT_SUPPORT 0 // Resolve mDNS names (3.44Kb) #endif #ifndef LLMNR_SUPPORT -#define LLMNR_SUPPORT 0 // Publish device using LLMNR protocol by default (1.95Kb) - requires 2.4.0 +#define LLMNR_SUPPORT 0 // Publish device using LLMNR protocol by default (1.95Kb) - requires 2.4.0 #endif #ifndef NETBIOS_SUPPORT -#define NETBIOS_SUPPORT 0 // Publish device using NetBIOS protocol by default (1.26Kb) - requires 2.4.0 +#define NETBIOS_SUPPORT 0 // Publish device using NetBIOS protocol by default (1.26Kb) - requires 2.4.0 #endif #ifndef SSDP_SUPPORT -#define SSDP_SUPPORT 0 // Publish device using SSDP protocol by default (4.59Kb) - // Not compatible with ALEXA_SUPPORT at the moment +#define SSDP_SUPPORT 0 // Publish device using SSDP protocol by default (4.59Kb) + // Not compatible with ALEXA_SUPPORT at the moment #endif #ifndef SSDP_DEVICE_TYPE -#define SSDP_DEVICE_TYPE "upnp:rootdevice" -//#define SSDP_DEVICE_TYPE "urn:schemas-upnp-org:device:BinaryLight:1" +#define SSDP_DEVICE_TYPE "upnp:rootdevice" +//#define SSDP_DEVICE_TYPE "urn:schemas-upnp-org:device:BinaryLight:1" #endif @@ -447,7 +439,7 @@ // ----------------------------------------------------------------------------- #ifndef SPIFFS_SUPPORT -#define SPIFFS_SUPPORT 0 // Do not add support for SPIFFS by default +#define SPIFFS_SUPPORT 0 // Do not add support for SPIFFS by default #endif // ----------------------------------------------------------------------------- @@ -455,29 +447,29 @@ // ----------------------------------------------------------------------------- #ifndef OTA_PORT -#define OTA_PORT 8266 // OTA port +#define OTA_PORT 8266 // OTA port #endif -#define OTA_GITHUB_FP "D7:9F:07:61:10:B3:92:93:E3:49:AC:89:84:5B:03:80:C1:9E:2F:8B" +#define OTA_GITHUB_FP "D7:9F:07:61:10:B3:92:93:E3:49:AC:89:84:5B:03:80:C1:9E:2F:8B" // ----------------------------------------------------------------------------- // NOFUSS // ----------------------------------------------------------------------------- #ifndef NOFUSS_SUPPORT -#define NOFUSS_SUPPORT 0 // Do not enable support for NoFuss by default (12.65Kb) +#define NOFUSS_SUPPORT 0 // Do not enable support for NoFuss by default (12.65Kb) #endif #ifndef NOFUSS_ENABLED -#define NOFUSS_ENABLED 0 // Do not perform NoFUSS updates by default +#define NOFUSS_ENABLED 0 // Do not perform NoFUSS updates by default #endif #ifndef NOFUSS_SERVER -#define NOFUSS_SERVER "" // Default NoFuss Server +#define NOFUSS_SERVER "" // Default NoFuss Server #endif #ifndef NOFUSS_INTERVAL -#define NOFUSS_INTERVAL 3600000 // Check for updates every hour +#define NOFUSS_INTERVAL 3600000 // Check for updates every hour #endif // ----------------------------------------------------------------------------- @@ -485,42 +477,42 @@ // ----------------------------------------------------------------------------- #ifndef UART_MQTT_SUPPORT -#define UART_MQTT_SUPPORT 0 // No support by default +#define UART_MQTT_SUPPORT 0 // No support by default #endif #ifndef UART_MQTT_USE_SOFT -#define UART_MQTT_USE_SOFT 0 // Use SoftwareSerial +#define UART_MQTT_USE_SOFT 0 // Use SoftwareSerial #endif #ifndef UART_MQTT_HW_PORT -#define UART_MQTT_HW_PORT Serial // Hardware serial port (if UART_MQTT_USE_SOFT == 0) +#define UART_MQTT_HW_PORT Serial // Hardware serial port (if UART_MQTT_USE_SOFT == 0) #endif #ifndef UART_MQTT_RX_PIN -#define UART_MQTT_RX_PIN 4 // RX PIN (if UART_MQTT_USE_SOFT == 1) +#define UART_MQTT_RX_PIN 4 // RX PIN (if UART_MQTT_USE_SOFT == 1) #endif #ifndef UART_MQTT_TX_PIN -#define UART_MQTT_TX_PIN 5 // TX PIN (if UART_MQTT_USE_SOFT == 1) +#define UART_MQTT_TX_PIN 5 // TX PIN (if UART_MQTT_USE_SOFT == 1) #endif #ifndef UART_MQTT_BAUDRATE -#define UART_MQTT_BAUDRATE 115200 // Serial speed +#define UART_MQTT_BAUDRATE 115200 // Serial speed #endif -#define UART_MQTT_BUFFER_SIZE 100 // UART buffer size +#define UART_MQTT_BUFFER_SIZE 100 // UART buffer size // ----------------------------------------------------------------------------- // MQTT // ----------------------------------------------------------------------------- #ifndef MQTT_SUPPORT -#define MQTT_SUPPORT 1 // MQTT support (22.38Kb async, 12.48Kb sync) +#define MQTT_SUPPORT 1 // MQTT support (22.38Kb async, 12.48Kb sync) #endif #ifndef MQTT_USE_ASYNC -#define MQTT_USE_ASYNC 1 // Use AysncMQTTClient (1) or PubSubClient (0) +#define MQTT_USE_ASYNC 1 // Use AysncMQTTClient (1) or PubSubClient (0) #endif // MQTT OVER SSL @@ -630,78 +622,78 @@ #ifndef MQTT_ENQUEUE_IP #define MQTT_ENQUEUE_IP 1 #endif + #ifndef MQTT_ENQUEUE_MAC #define MQTT_ENQUEUE_MAC 1 #endif + #ifndef MQTT_ENQUEUE_HOSTNAME #define MQTT_ENQUEUE_HOSTNAME 1 #endif + #ifndef MQTT_ENQUEUE_DATETIME #define MQTT_ENQUEUE_DATETIME 1 #endif + #ifndef MQTT_ENQUEUE_MESSAGE_ID #define MQTT_ENQUEUE_MESSAGE_ID 1 #endif // These particles will be concatenated to the MQTT_TOPIC base to form the actual topic -#define MQTT_TOPIC_JSON "data" -#define MQTT_TOPIC_ACTION "action" -#define MQTT_TOPIC_RELAY "relay" -#define MQTT_TOPIC_LED "led" -#define MQTT_TOPIC_BUTTON "button" -#define MQTT_TOPIC_IP "ip" -#define MQTT_TOPIC_VERSION "version" -#define MQTT_TOPIC_UPTIME "uptime" -#define MQTT_TOPIC_DATETIME "datetime" -#define MQTT_TOPIC_FREEHEAP "freeheap" -#define MQTT_TOPIC_VCC "vcc" -#define MQTT_TOPIC_STATUS "status" -#define MQTT_TOPIC_MAC "mac" -#define MQTT_TOPIC_RSSI "rssi" -#define MQTT_TOPIC_MESSAGE_ID "id" -#define MQTT_TOPIC_APP "app" -#define MQTT_TOPIC_INTERVAL "interval" -#define MQTT_TOPIC_HOSTNAME "host" -#define MQTT_TOPIC_TIME "time" -#define MQTT_TOPIC_RFOUT "rfout" -#define MQTT_TOPIC_RFIN "rfin" -#define MQTT_TOPIC_RFLEARN "rflearn" -#define MQTT_TOPIC_RFRAW "rfraw" -#define MQTT_TOPIC_UARTIN "uartin" -#define MQTT_TOPIC_UARTOUT "uartout" -#define MQTT_TOPIC_LOADAVG "loadavg" -#define MQTT_TOPIC_BOARD "board" +#define MQTT_TOPIC_JSON "data" +#define MQTT_TOPIC_ACTION "action" +#define MQTT_TOPIC_RELAY "relay" +#define MQTT_TOPIC_LED "led" +#define MQTT_TOPIC_BUTTON "button" +#define MQTT_TOPIC_IP "ip" +#define MQTT_TOPIC_VERSION "version" +#define MQTT_TOPIC_UPTIME "uptime" +#define MQTT_TOPIC_DATETIME "datetime" +#define MQTT_TOPIC_FREEHEAP "freeheap" +#define MQTT_TOPIC_VCC "vcc" +#define MQTT_TOPIC_STATUS "status" +#define MQTT_TOPIC_MAC "mac" +#define MQTT_TOPIC_RSSI "rssi" +#define MQTT_TOPIC_MESSAGE_ID "id" +#define MQTT_TOPIC_APP "app" +#define MQTT_TOPIC_INTERVAL "interval" +#define MQTT_TOPIC_HOSTNAME "host" +#define MQTT_TOPIC_TIME "time" +#define MQTT_TOPIC_RFOUT "rfout" +#define MQTT_TOPIC_RFIN "rfin" +#define MQTT_TOPIC_RFLEARN "rflearn" +#define MQTT_TOPIC_RFRAW "rfraw" +#define MQTT_TOPIC_UARTIN "uartin" +#define MQTT_TOPIC_UARTOUT "uartout" +#define MQTT_TOPIC_LOADAVG "loadavg" +#define MQTT_TOPIC_BOARD "board" // Light module -#define MQTT_TOPIC_CHANNEL "channel" -#define MQTT_TOPIC_COLOR_RGB "rgb" -#define MQTT_TOPIC_COLOR_HSV "hsv" -#define MQTT_TOPIC_ANIM_MODE "anim_mode" -#define MQTT_TOPIC_ANIM_SPEED "anim_speed" -#define MQTT_TOPIC_BRIGHTNESS "brightness" -#define MQTT_TOPIC_MIRED "mired" -#define MQTT_TOPIC_KELVIN "kelvin" - -#define MQTT_STATUS_ONLINE "1" // Value for the device ON message -#define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will) +#define MQTT_TOPIC_CHANNEL "channel" +#define MQTT_TOPIC_COLOR_RGB "rgb" +#define MQTT_TOPIC_COLOR_HSV "hsv" +#define MQTT_TOPIC_ANIM_MODE "anim_mode" +#define MQTT_TOPIC_ANIM_SPEED "anim_speed" +#define MQTT_TOPIC_BRIGHTNESS "brightness" +#define MQTT_TOPIC_MIRED "mired" +#define MQTT_TOPIC_KELVIN "kelvin" -#define MQTT_ACTION_RESET "reboot" // RESET MQTT topic particle +#define MQTT_STATUS_ONLINE "1" // Value for the device ON message +#define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will) -// Internal MQTT events (do not change) -#define MQTT_CONNECT_EVENT 0 -#define MQTT_DISCONNECT_EVENT 1 -#define MQTT_MESSAGE_EVENT 2 +#define MQTT_ACTION_RESET "reboot" // RESET MQTT topic particle -#define MQTT_MESSAGE_ID_SHIFT 1000 // Store MQTT message id into EEPROM every these many +#define MQTT_MESSAGE_ID_SHIFT 1000 // Store MQTT message id into EEPROM every these many // Custom get and set postfixes // Use something like "/status" or "/set", with leading slash // Since 1.9.0 the default value is "" for getter and "/set" for setter #ifndef MQTT_GETTER -#define MQTT_GETTER "" +#define MQTT_GETTER "" #endif + #ifndef MQTT_SETTER -#define MQTT_SETTER "/set" +#define MQTT_SETTER "/set" #endif // ----------------------------------------------------------------------------- @@ -879,29 +871,37 @@ // ----------------------------------------------------------------------------- #ifndef THINGSPEAK_SUPPORT -#define THINGSPEAK_SUPPORT 1 // Enable Thingspeak support by default (2.56Kb) +#define THINGSPEAK_SUPPORT 1 // Enable Thingspeak support by default (2.56Kb) #endif -#define THINGSPEAK_ENABLED 0 // Thingspeak disabled by default -#define THINGSPEAK_APIKEY "" // Default API KEY +#ifndef THINGSPEAK_ENABLED +#define THINGSPEAK_ENABLED 0 // Thingspeak disabled by default +#endif -#define THINGSPEAK_USE_ASYNC 1 // Use AsyncClient instead of WiFiClientSecure +#ifndef THINGSPEAK_APIKEY +#define THINGSPEAK_APIKEY "" // Default API KEY +#endif + +#define THINGSPEAK_USE_ASYNC 1 // Use AsyncClient instead of WiFiClientSecure // THINGSPEAK OVER SSL // Using THINGSPEAK over SSL works well but generates problems with the web interface, // so you should compile it with WEB_SUPPORT to 0. // When THINGSPEAK_USE_ASYNC is 1, requires ASYNC_TCP_SSL_ENABLED to 1 and ESP8266 Arduino Core 2.4.0. -#define THINGSPEAK_USE_SSL 0 // Use secure connection -#define THINGSPEAK_FINGERPRINT "78 60 18 44 81 35 BF DF 77 84 D4 0A 22 0D 9B 4E 6C DC 57 2C" +#define THINGSPEAK_USE_SSL 0 // Use secure connection + +#define THINGSPEAK_FINGERPRINT "78 60 18 44 81 35 BF DF 77 84 D4 0A 22 0D 9B 4E 6C DC 57 2C" -#define THINGSPEAK_HOST "api.thingspeak.com" +#define THINGSPEAK_HOST "api.thingspeak.com" #if THINGSPEAK_USE_SSL -#define THINGSPEAK_PORT 443 +#define THINGSPEAK_PORT 443 #else -#define THINGSPEAK_PORT 80 +#define THINGSPEAK_PORT 80 #endif -#define THINGSPEAK_URL "/update" -#define THINGSPEAK_MIN_INTERVAL 15000 // Minimum interval between POSTs (in millis) + +#define THINGSPEAK_URL "/update" + +#define THINGSPEAK_MIN_INTERVAL 15000 // Minimum interval between POSTs (in millis) // ----------------------------------------------------------------------------- // SCHEDULER @@ -911,46 +911,48 @@ #define SCHEDULER_SUPPORT 1 // Enable scheduler (1.77Kb) #endif +#ifndef SCHEDULER_MAX_SCHEDULES #define SCHEDULER_MAX_SCHEDULES 10 // Max schedules alowed +#endif // ----------------------------------------------------------------------------- // NTP // ----------------------------------------------------------------------------- #ifndef NTP_SUPPORT -#define NTP_SUPPORT 1 // Build with NTP support by default (6.78Kb) +#define NTP_SUPPORT 1 // Build with NTP support by default (6.78Kb) #endif #ifndef NTP_SERVER -#define NTP_SERVER "pool.ntp.org" // Default NTP server +#define NTP_SERVER "pool.ntp.org" // Default NTP server #endif #ifndef NTP_TIMEOUT -#define NTP_TIMEOUT 2000 // Set NTP request timeout to 2 seconds (issue #452) +#define NTP_TIMEOUT 1000 // Set NTP request timeout to 2 seconds (issue #452) #endif #ifndef NTP_TIME_OFFSET -#define NTP_TIME_OFFSET 60 // Default timezone offset (GMT+1) +#define NTP_TIME_OFFSET 60 // Default timezone offset (GMT+1) #endif #ifndef NTP_DAY_LIGHT -#define NTP_DAY_LIGHT true // Enable daylight time saving by default +#define NTP_DAY_LIGHT 1 // Enable daylight time saving by default #endif #ifndef NTP_SYNC_INTERVAL -#define NTP_SYNC_INTERVAL 60 // NTP initial check every minute +#define NTP_SYNC_INTERVAL 60 // NTP initial check every minute #endif #ifndef NTP_UPDATE_INTERVAL -#define NTP_UPDATE_INTERVAL 1800 // NTP check every 30 minutes +#define NTP_UPDATE_INTERVAL 1800 // NTP check every 30 minutes #endif #ifndef NTP_START_DELAY -#define NTP_START_DELAY 1000 // Delay NTP start 1 second +#define NTP_START_DELAY 1000 // Delay NTP start 1 second #endif #ifndef NTP_DST_REGION -#define NTP_DST_REGION 0 // 0 for Europe, 1 for USA (defined in NtpClientLib) +#define NTP_DST_REGION 0 // 0 for Europe, 1 for USA (defined in NtpClientLib) #endif // ----------------------------------------------------------------------------- @@ -959,13 +961,15 @@ // This setting defines whether Alexa support should be built into the firmware #ifndef ALEXA_SUPPORT -#define ALEXA_SUPPORT 1 // Enable Alexa support by default (10.84Kb) +#define ALEXA_SUPPORT 1 // Enable Alexa support by default (10.84Kb) #endif // This is default value for the alexaEnabled setting that defines whether // this device should be discoberable and respond to Alexa commands. // Both ALEXA_SUPPORT and alexaEnabled should be 1 for Alexa support to work. -#define ALEXA_ENABLED 1 +#ifndef ALEXA_ENABLED +#define ALEXA_ENABLED 1 +#endif // ----------------------------------------------------------------------------- // RFBRIDGE @@ -973,20 +977,20 @@ // ----------------------------------------------------------------------------- #ifndef RF_SEND_TIMES -#define RF_SEND_TIMES 4 // How many times to send the message +#define RF_SEND_TIMES 4 // How many times to send the message #endif #ifndef RF_SEND_DELAY -#define RF_SEND_DELAY 500 // Interval between sendings in ms +#define RF_SEND_DELAY 500 // Interval between sendings in ms #endif #ifndef RF_RECEIVE_DELAY -#define RF_RECEIVE_DELAY 500 // Interval between recieving in ms (avoid debouncing) +#define RF_RECEIVE_DELAY 500 // Interval between recieving in ms (avoid debouncing) #endif #ifndef RF_RAW_SUPPORT -#define RF_RAW_SUPPORT 0 // RF raw codes require a specific firmware for the EFM8BB1 +#define RF_RAW_SUPPORT 0 // RF raw codes require a specific firmware for the EFM8BB1 // https://github.com/rhx/RF-Bridge-EFM8BB1 #endif @@ -996,16 +1000,16 @@ // ----------------------------------------------------------------------------- #ifndef IR_SUPPORT -#define IR_SUPPORT 0 // Do not build with IR support by default (10.25Kb) +#define IR_SUPPORT 0 // Do not build with IR support by default (10.25Kb) #endif #ifndef IR_PIN -#define IR_PIN 4 // IR LED +#define IR_PIN 4 // IR LED #endif // 24 Buttons Set of the IR Remote #ifndef IR_BUTTON_SET -#define IR_BUTTON_SET 1 // IR button set to use (see below) +#define IR_BUTTON_SET 1 // IR button set to use (see below) #endif //Remote Buttons SET 1 (for the original Remote shipped with the controller) @@ -1129,7 +1133,7 @@ // Custom RF module // Check http://tinkerman.cat/adding-rf-to-a-non-rf-itead-sonoff/ // Enable support by passing RF_SUPPORT=1 build flag -// This module is not compatible with RFBRIDGE +// This module is not compatible with RFBRIDGE or SONOFF RF //-------------------------------------------------------------------------------- #ifndef RF_SUPPORT diff --git a/code/espurna/config/progmem.h b/code/espurna/config/progmem.h index 12c6a24e..1bd2347c 100644 --- a/code/espurna/config/progmem.h +++ b/code/espurna/config/progmem.h @@ -1,7 +1,10 @@ //-------------------------------------------------------------------------------- -// General PROGMEM definitions +// PROGMEM definitions //-------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------- +// Reset reasons +//-------------------------------------------------------------------------------- PROGMEM const char custom_reset_hardware[] = "Hardware button"; PROGMEM const char custom_reset_web[] = "Reboot from web interface"; @@ -20,6 +23,10 @@ PROGMEM const char* const custom_reset_string[] = { custom_reset_factory }; +//-------------------------------------------------------------------------------- +// Sensors +//-------------------------------------------------------------------------------- + #if SENSOR_SUPPORT PROGMEM const unsigned char magnitude_decimals[] = { @@ -28,7 +35,7 @@ PROGMEM const unsigned char magnitude_decimals[] = { 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0 + 0, 0, 3, 3 }; PROGMEM const char magnitude_unknown_topic[] = "unknown"; diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index 6351f205..ba8e0723 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -117,19 +117,5 @@ template void domoticzSend(const char * key, T nvalue, const char * char * ltrim(char * s); void nice_delay(unsigned long ms); -// ----------------------------------------------------------------------------- -// Macros -// ----------------------------------------------------------------------------- - #define ARRAYINIT(type, name, ...) \ type name[] = {__VA_ARGS__}; - -#if DEBUG_SUPPORT - #define DEBUG_MSG(...) debugSend(__VA_ARGS__) - #define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__) -#endif - -#ifndef DEBUG_MSG - #define DEBUG_MSG(...) - #define DEBUG_MSG_P(...) -#endif diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index a0ede390..2d77dfd8 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -66,7 +66,6 @@ #define ANALOG_SUPPORT 0 #endif - //------------------------------------------------------------------------------ // BH1750 // Enable support by passing BH1750_SUPPORT=1 build flag @@ -83,7 +82,6 @@ #define BH1750_MODE BH1750_CONTINUOUS_HIGH_RES_MODE - //------------------------------------------------------------------------------ // BME280/BMP280 // Enable support by passing BMX280_SUPPORT=1 build flag @@ -381,7 +379,6 @@ #define PZEM004T_HW_PORT Serial1 // Hardware serial port (if PZEM004T_USE_SOFT == 0) #endif - //------------------------------------------------------------------------------ // SHT3X I2C (Wemos) temperature & humidity sensor // Enable support by passing SHT3X_SUPPORT=1 build flag @@ -421,11 +418,6 @@ #define TMP3X_TYPE TMP3X_TMP35 #endif -#if TMP3X_SUPPORT -#undef ADC_VCC_ENABLED -#define ADC_VCC_ENABLED 0 -#endif - //------------------------------------------------------------------------------ // V9261F based power sensor // Enable support by passing SI7021_SUPPORT=1 build flag @@ -497,6 +489,15 @@ #endif #endif +// ----------------------------------------------------------------------------- +// ADC +// ----------------------------------------------------------------------------- + +// Default ADC mode is to monitor internal power supply +#ifndef ADC_MODE_VALUE +#define ADC_MODE_VALUE ADC_VCC +#endif + // ----------------------------------------------------------------------------- // I2C // ----------------------------------------------------------------------------- @@ -520,16 +521,6 @@ #define I2C_CLEAR_BUS 0 // Clear I2C bus on boot #define I2C_PERFORM_SCAN 1 // Perform a bus scan on boot -//-------------------------------------------------------------------------------- -// Internal power monitor -// Enable support by passing ADC_VCC_ENABLED=1 build flag -// Do not enable this if using the analog GPIO for any other thing -//-------------------------------------------------------------------------------- - -#ifndef ADC_VCC_ENABLED -#define ADC_VCC_ENABLED 1 -#endif - //-------------------------------------------------------------------------------- // Class loading //-------------------------------------------------------------------------------- diff --git a/code/espurna/config/types.h b/code/espurna/config/types.h index 9ab72171..03125aef 100644 --- a/code/espurna/config/types.h +++ b/code/espurna/config/types.h @@ -1,10 +1,12 @@ //------------------------------------------------------------------------------ // Type definitions +// Do not touch this definitions //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // BUTTONS //------------------------------------------------------------------------------ + #define BUTTON_EVENT_NONE 0 #define BUTTON_EVENT_PRESSED 1 #define BUTTON_EVENT_RELEASED 2 @@ -24,10 +26,10 @@ // Needed for ESP8285 boards under Windows using PlatformIO (?) #ifndef BUTTON_PUSHBUTTON -#define BUTTON_PUSHBUTTON 0 -#define BUTTON_SWITCH 1 -#define BUTTON_DEFAULT_HIGH 2 -#define BUTTON_SET_PULLUP 4 +#define BUTTON_PUSHBUTTON 0 +#define BUTTON_SWITCH 1 +#define BUTTON_DEFAULT_HIGH 2 +#define BUTTON_SET_PULLUP 4 #endif //------------------------------------------------------------------------------ @@ -59,6 +61,15 @@ #define RELAY_PROVIDER_RFBRIDGE 3 #define RELAY_PROVIDER_STM 4 +//------------------------------------------------------------------------------ +// MQTT +//------------------------------------------------------------------------------ + +// Internal MQTT events +#define MQTT_CONNECT_EVENT 0 +#define MQTT_DISCONNECT_EVENT 1 +#define MQTT_MESSAGE_EVENT 2 + //------------------------------------------------------------------------------ // LED //------------------------------------------------------------------------------ @@ -78,22 +89,21 @@ // UI // ----------------------------------------------------------------------------- -#define UI_TAG_INPUT 0 -#define UI_TAG_CHECKBOX 1 -#define UI_TAG_SELECT 2 - -#define WEB_MODE_NORMAL 0 -#define WEB_MODE_PASSWORD 1 +#define UI_TAG_INPUT 0 +#define UI_TAG_CHECKBOX 1 +#define UI_TAG_SELECT 2 +#define WEB_MODE_NORMAL 0 +#define WEB_MODE_PASSWORD 1 // ----------------------------------------------------------------------------- // LIGHT // ----------------------------------------------------------------------------- -// Available light providers (do not change) -#define LIGHT_PROVIDER_NONE 0 -#define LIGHT_PROVIDER_MY92XX 1 // works with MY9291 and MY9231 -#define LIGHT_PROVIDER_DIMMER 2 +// Available light providers +#define LIGHT_PROVIDER_NONE 0 +#define LIGHT_PROVIDER_MY92XX 1 // works with MY9291 and MY9231 +#define LIGHT_PROVIDER_DIMMER 2 // ----------------------------------------------------------------------------- // SCHEDULER @@ -120,23 +130,22 @@ #define LIGHT_EFFECT_FADE 3 #define LIGHT_EFFECT_SMOOTH 4 - //------------------------------------------------------------------------------ // RESET //------------------------------------------------------------------------------ -#define CUSTOM_RESET_HARDWARE 1 // Reset from hardware button -#define CUSTOM_RESET_WEB 2 // Reset from web interface -#define CUSTOM_RESET_TERMINAL 3 // Reset from terminal -#define CUSTOM_RESET_MQTT 4 // Reset via MQTT -#define CUSTOM_RESET_RPC 5 // Reset via RPC (HTTP) -#define CUSTOM_RESET_OTA 6 // Reset after successful OTA update -#define CUSTOM_RESET_HTTP 7 // Reset via HTTP GET -#define CUSTOM_RESET_NOFUSS 8 // Reset after successful NOFUSS update -#define CUSTOM_RESET_UPGRADE 9 // Reset after update from web interface -#define CUSTOM_RESET_FACTORY 10 // Factory reset from terminal +#define CUSTOM_RESET_HARDWARE 1 // Reset from hardware button +#define CUSTOM_RESET_WEB 2 // Reset from web interface +#define CUSTOM_RESET_TERMINAL 3 // Reset from terminal +#define CUSTOM_RESET_MQTT 4 // Reset via MQTT +#define CUSTOM_RESET_RPC 5 // Reset via RPC (HTTP) +#define CUSTOM_RESET_OTA 6 // Reset after successful OTA update +#define CUSTOM_RESET_HTTP 7 // Reset via HTTP GET +#define CUSTOM_RESET_NOFUSS 8 // Reset after successful NOFUSS update +#define CUSTOM_RESET_UPGRADE 9 // Reset after update from web interface +#define CUSTOM_RESET_FACTORY 10 // Factory reset from terminal -#define CUSTOM_RESET_MAX 10 +#define CUSTOM_RESET_MAX 10 //------------------------------------------------------------------------------ // ENVIRONMENTAL @@ -146,90 +155,90 @@ // Comfortable: 30% - 60% // Recommended: 45% - 55% // High : 55% - 80% -#define HUMIDITY_NORMAL 0 // > %30 -#define HUMIDITY_COMFORTABLE 1 // > %45 -#define HUMIDITY_DRY 2 // < %30 -#define HUMIDITY_WET 3 // > %70 + +#define HUMIDITY_NORMAL 0 // > %30 +#define HUMIDITY_COMFORTABLE 1 // > %45 +#define HUMIDITY_DRY 2 // < %30 +#define HUMIDITY_WET 3 // > %70 // United States Environmental Protection Agency - UV Index Scale // One UV Index unit is equivalent to 25 milliWatts per square meter. -#define UV_INDEX_LOW 0 // 0 to 2 means low danger from the sun's UV rays for the average person. -#define UV_INDEX_MODERATE 1 // 3 to 5 means moderate risk of harm from unprotected sun exposure. -#define UV_INDEX_HIGH 2 // 6 to 7 means high risk of harm from unprotected sun exposure. Protection against skin and eye damage is needed. -#define UV_INDEX_VERY_HIGH 3 // 8 to 10 means very high risk of harm from unprotected sun exposure. - // Take extra precautions because unprotected skin and eyes will be damaged and can burn quickly. -#define UV_INDEX_EXTREME 4 // 11 or more means extreme risk of harm from unprotected sun exposure. - // Take all precautions because unprotected skin and eyes can burn in minutes. +#define UV_INDEX_LOW 0 // 0 to 2 means low danger from the sun's UV rays for the average person. +#define UV_INDEX_MODERATE 1 // 3 to 5 means moderate risk of harm from unprotected sun exposure. +#define UV_INDEX_HIGH 2 // 6 to 7 means high risk of harm from unprotected sun exposure. Protection against skin and eye damage is needed. +#define UV_INDEX_VERY_HIGH 3 // 8 to 10 means very high risk of harm from unprotected sun exposure. + // Take extra precautions because unprotected skin and eyes will be damaged and can burn quickly. +#define UV_INDEX_EXTREME 4 // 11 or more means extreme risk of harm from unprotected sun exposure. + // Take all precautions because unprotected skin and eyes can burn in minutes. //------------------------------------------------------------------------------ // UNITS //------------------------------------------------------------------------------ -#define POWER_WATTS 0 -#define POWER_KILOWATTS 1 +#define POWER_WATTS 0 +#define POWER_KILOWATTS 1 -#define ENERGY_JOULES 0 -#define ENERGY_KWH 1 - -#define TMP_CELSIUS 0 -#define TMP_FAHRENHEIT 1 +#define ENERGY_JOULES 0 +#define ENERGY_KWH 1 +#define TMP_CELSIUS 0 +#define TMP_FAHRENHEIT 1 +#define TMP_KELVIN 2 //-------------------------------------------------------------------------------- // Sensor ID // These should remain over time, do not modify them, only add new ones at the end //-------------------------------------------------------------------------------- -#define SENSOR_DHTXX_ID 0x01 -#define SENSOR_DALLAS_ID 0x02 -#define SENSOR_EMON_ANALOG_ID 0x03 -#define SENSOR_EMON_ADC121_ID 0x04 -#define SENSOR_EMON_ADS1X15_ID 0x05 -#define SENSOR_HLW8012_ID 0x06 -#define SENSOR_V9261F_ID 0x07 -#define SENSOR_ECH1560_ID 0x08 -#define SENSOR_ANALOG_ID 0x09 -#define SENSOR_DIGITAL_ID 0x10 -#define SENSOR_EVENTS_ID 0x11 -#define SENSOR_PMSX003_ID 0x12 -#define SENSOR_BMX280_ID 0x13 -#define SENSOR_MHZ19_ID 0x14 -#define SENSOR_SI7021_ID 0x15 -#define SENSOR_SHT3X_I2C_ID 0x16 -#define SENSOR_BH1750_ID 0x17 -#define SENSOR_PZEM004T_ID 0x18 -#define SENSOR_AM2320_ID 0x19 -#define SENSOR_GUVAS12SD_ID 0x20 -#define SENSOR_CSE7766_ID 0x21 -#define SENSOR_TMP3X_ID 0x22 -#define SENSOR_HCSR04_ID 0x23 - +#define SENSOR_DHTXX_ID 0x01 +#define SENSOR_DALLAS_ID 0x02 +#define SENSOR_EMON_ANALOG_ID 0x03 +#define SENSOR_EMON_ADC121_ID 0x04 +#define SENSOR_EMON_ADS1X15_ID 0x05 +#define SENSOR_HLW8012_ID 0x06 +#define SENSOR_V9261F_ID 0x07 +#define SENSOR_ECH1560_ID 0x08 +#define SENSOR_ANALOG_ID 0x09 +#define SENSOR_DIGITAL_ID 0x10 +#define SENSOR_EVENTS_ID 0x11 +#define SENSOR_PMSX003_ID 0x12 +#define SENSOR_BMX280_ID 0x13 +#define SENSOR_MHZ19_ID 0x14 +#define SENSOR_SI7021_ID 0x15 +#define SENSOR_SHT3X_I2C_ID 0x16 +#define SENSOR_BH1750_ID 0x17 +#define SENSOR_PZEM004T_ID 0x18 +#define SENSOR_AM2320_ID 0x19 +#define SENSOR_GUVAS12SD_ID 0x20 +#define SENSOR_CSE7766_ID 0x21 +#define SENSOR_TMP3X_ID 0x22 +#define SENSOR_HCSR04_ID 0x23 //-------------------------------------------------------------------------------- // Magnitudes //-------------------------------------------------------------------------------- -#define MAGNITUDE_NONE 0 -#define MAGNITUDE_TEMPERATURE 1 -#define MAGNITUDE_HUMIDITY 2 -#define MAGNITUDE_PRESSURE 3 -#define MAGNITUDE_CURRENT 4 -#define MAGNITUDE_VOLTAGE 5 -#define MAGNITUDE_POWER_ACTIVE 6 -#define MAGNITUDE_POWER_APPARENT 7 -#define MAGNITUDE_POWER_REACTIVE 8 -#define MAGNITUDE_POWER_FACTOR 9 -#define MAGNITUDE_ENERGY 10 -#define MAGNITUDE_ENERGY_DELTA 11 -#define MAGNITUDE_ANALOG 12 -#define MAGNITUDE_DIGITAL 13 -#define MAGNITUDE_EVENTS 14 -#define MAGNITUDE_PM1dot0 15 -#define MAGNITUDE_PM2dot5 16 -#define MAGNITUDE_PM10 17 -#define MAGNITUDE_CO2 18 -#define MAGNITUDE_LUX 19 -#define MAGNITUDE_UV 20 -#define MAGNITUDE_DISTANCE 21 - -#define MAGNITUDE_MAX 22 +#define MAGNITUDE_NONE 0 +#define MAGNITUDE_TEMPERATURE 1 +#define MAGNITUDE_HUMIDITY 2 +#define MAGNITUDE_PRESSURE 3 +#define MAGNITUDE_CURRENT 4 +#define MAGNITUDE_VOLTAGE 5 +#define MAGNITUDE_POWER_ACTIVE 6 +#define MAGNITUDE_POWER_APPARENT 7 +#define MAGNITUDE_POWER_REACTIVE 8 +#define MAGNITUDE_POWER_FACTOR 9 +#define MAGNITUDE_ENERGY 10 +#define MAGNITUDE_ENERGY_DELTA 11 +#define MAGNITUDE_ANALOG 12 +#define MAGNITUDE_DIGITAL 13 +#define MAGNITUDE_EVENTS 14 +#define MAGNITUDE_PM1dot0 15 +#define MAGNITUDE_PM2dot5 16 +#define MAGNITUDE_PM10 17 +#define MAGNITUDE_CO2 18 +#define MAGNITUDE_LUX 19 +#define MAGNITUDE_UV 20 +#define MAGNITUDE_DISTANCE 21 + +#define MAGNITUDE_MAX 22 diff --git a/code/espurna/sensors/AnalogSensor.h b/code/espurna/sensors/AnalogSensor.h index 920538c9..e988ab96 100644 --- a/code/espurna/sensors/AnalogSensor.h +++ b/code/espurna/sensors/AnalogSensor.h @@ -7,6 +7,10 @@ #pragma once +// Set ADC to TOUT pin +#undef ADC_MODE_VALUE +#define ADC_MODE_VALUE ADC_TOUT + #include "Arduino.h" #include "BaseSensor.h" diff --git a/code/espurna/sensors/EmonAnalogSensor.h b/code/espurna/sensors/EmonAnalogSensor.h index 45cd481e..e4041e93 100644 --- a/code/espurna/sensors/EmonAnalogSensor.h +++ b/code/espurna/sensors/EmonAnalogSensor.h @@ -7,9 +7,9 @@ #pragma once -#if ADC_VCC_ENABLED - ADC_MODE(ADC_VCC); -#endif +// Set ADC to TOUT pin +#undef ADC_MODE_VALUE +#define ADC_MODE_VALUE ADC_TOUT #include "Arduino.h" #include "EmonSensor.h" diff --git a/code/espurna/sensors/GUVAS12SDSensor.h b/code/espurna/sensors/GUVAS12SDSensor.h index 2d941975..1a0ee3ee 100644 --- a/code/espurna/sensors/GUVAS12SDSensor.h +++ b/code/espurna/sensors/GUVAS12SDSensor.h @@ -8,10 +8,9 @@ #pragma once -#if ADC_VCC_ENABLED - ADC_MODE(ADC_VCC); -#endif - +// Set ADC to TOUT pin +#undef ADC_MODE_VALUE +#define ADC_MODE_VALUE ADC_TOUT #include "Arduino.h" #include "BaseSensor.h" diff --git a/code/espurna/sensors/TMP3XSensor.h b/code/espurna/sensors/TMP3XSensor.h index c20444da..6052797e 100644 --- a/code/espurna/sensors/TMP3XSensor.h +++ b/code/espurna/sensors/TMP3XSensor.h @@ -7,10 +7,9 @@ #pragma once -#if ADC_VCC_ENABLED - ADC_MODE(ADC_VCC); -#endif - +// Set ADC to TOUT pin +#undef ADC_MODE_VALUE +#define ADC_MODE_VALUE ADC_TOUT #include "Arduino.h" #include "BaseSensor.h" diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 439a0e7b..d724433a 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -123,7 +123,7 @@ void heartbeat() { if (serial) { DEBUG_MSG_P(PSTR("[MAIN] Uptime: %lu seconds\n"), uptime_seconds); DEBUG_MSG_P(PSTR("[MAIN] Free heap: %lu bytes\n"), free_heap); - #if ADC_VCC_ENABLED + #if ADC_MODE_VALUE == ADC_VCC DEBUG_MSG_P(PSTR("[MAIN] Power: %lu mV\n"), ESP.getVcc()); #endif #if NTP_SUPPORT @@ -177,7 +177,7 @@ void heartbeat() { lightMQTT(); #endif #if (HEARTBEAT_REPORT_VCC) - #if ADC_VCC_ENABLED + #if ADC_MODE_VALUE == ADC_VCC mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str()); #endif #endif @@ -422,7 +422,7 @@ void info() { DEBUG_MSG_P(PSTR("[INIT] Settings size: %u bytes\n"), settingsSize()); DEBUG_MSG_P(PSTR("[INIT] Free heap: %u bytes\n"), getFreeHeap()); - #if ADC_VCC_ENABLED + #if ADC_MODE_VALUE == ADC_VCC DEBUG_MSG_P(PSTR("[INIT] Power: %u mV\n"), ESP.getVcc()); #endif @@ -525,3 +525,8 @@ void nice_delay(unsigned long ms) { unsigned long start = millis(); while (millis() - start < ms) delay(1); } + +// This method is called by the SDK to know where to connect the ADC +int __get_adc_mode() { + return (int) (ADC_MODE_VALUE); +} diff --git a/code/espurna/ws.ino b/code/espurna/ws.ino index 2ecd3977..265172f3 100644 --- a/code/espurna/ws.ino +++ b/code/espurna/ws.ino @@ -235,7 +235,9 @@ void _wsUpdate(JsonObject& root) { root["uptime"] = getUptime(); root["rssi"] = WiFi.RSSI(); root["loadaverage"] = systemLoadAverage(); - root["vcc"] = ESP.getVcc(); + #if ADC_MODE_VALUE == ADC_VCC + root["vcc"] = ESP.getVcc(); + #endif #if NTP_SUPPORT if (ntpSynced()) root["now"] = now(); #endif