Browse Source

Merge branch 'dev' into ssl

Conflicts:
	code/espurna/static/index.html.gz.h
	code/espurna/web.ino
fastled
Xose Pérez 7 years ago
parent
commit
5c58f011c1
35 changed files with 3933 additions and 3522 deletions
  1. +48
    -0
      code/espurna/alexa.ino
  2. +13
    -9
      code/espurna/analog.ino
  3. +1
    -1
      code/espurna/button.ino
  4. +16
    -15
      code/espurna/config/arduino.h
  5. +95
    -39
      code/espurna/config/general.h
  6. +81
    -45
      code/espurna/config/hardware.h
  7. +4
    -0
      code/espurna/config/prototypes.h
  8. +88
    -64
      code/espurna/config/sensors.h
  9. BIN
      code/espurna/data/index.html.gz
  10. +5
    -5
      code/espurna/debug.ino
  11. +20
    -13
      code/espurna/dht.ino
  12. +4
    -4
      code/espurna/domoticz.ino
  13. +19
    -13
      code/espurna/ds18b20.ino
  14. +29
    -25
      code/espurna/emon.ino
  15. +39
    -36
      code/espurna/espurna.ino
  16. +0
    -44
      code/espurna/fauxmo.ino
  17. +47
    -38
      code/espurna/hardware.ino
  18. +35
    -31
      code/espurna/hlw8012.ino
  19. +1
    -1
      code/espurna/i2c.ino
  20. +3
    -3
      code/espurna/influxdb.ino
  21. +6
    -6
      code/espurna/led.ino
  22. +60
    -54
      code/espurna/light.ino
  23. +1
    -1
      code/espurna/mqtt.ino
  24. +1
    -1
      code/espurna/nofuss.ino
  25. +7
    -3
      code/espurna/ntp.ino
  26. +7
    -3
      code/espurna/ota.ino
  27. +58
    -23
      code/espurna/relay.ino
  28. +1
    -1
      code/espurna/rf.ino
  29. +22
    -14
      code/espurna/rfbridge.ino
  30. +2857
    -2854
      code/espurna/static/index.html.gz.h
  31. +155
    -163
      code/espurna/web.ino
  32. +51
    -7
      code/espurna/wifi.ino
  33. +27
    -0
      code/html/custom.js
  34. +4
    -4
      code/html/index.html
  35. +128
    -2
      code/platformio.ini

+ 48
- 0
code/espurna/alexa.ino View File

@ -0,0 +1,48 @@
/*
ALEXA MODULE
Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ALEXA_SUPPORT
#include <fauxmoESP.h>
fauxmoESP alexa;
// -----------------------------------------------------------------------------
// ALEXA
// -----------------------------------------------------------------------------
void alexaConfigure() {
alexa.enable(getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1);
}
void alexaSetup() {
// Backwards compatibility
moveSetting("fauxmoEnabled", "alexaEnabled");
alexaConfigure();
unsigned int relays = relayCount();
String hostname = getSetting("hostname");
if (relays == 1) {
alexa.addDevice(hostname.c_str());
} else {
for (unsigned int i=0; i<relays; i++) {
alexa.addDevice((hostname + "_" + i).c_str());
}
}
alexa.onMessage([relays](unsigned char device_id, const char * name, bool state) {
DEBUG_MSG_P(PSTR("[ALEXA] %s state: %s\n"), name, state ? "ON" : "OFF");
relayStatus(device_id, state);
});
}
void alexaLoop() {
alexa.handle();
}
#endif

+ 13
- 9
code/espurna/analog.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_ANALOG
#if ANALOG_SUPPORT
// -----------------------------------------------------------------------------
// ANALOG
@ -20,9 +20,11 @@ void analogSetup() {
pinMode(ANALOG_PIN, INPUT);
apiRegister(ANALOG_TOPIC, ANALOG_TOPIC, [](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), getAnalog());
});
#if WEB_SUPPORT
apiRegister(ANALOG_TOPIC, ANALOG_TOPIC, [](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), getAnalog());
});
#endif
}
@ -41,19 +43,21 @@ void analogLoop() {
mqttSend(getSetting("analogTopic", ANALOG_TOPIC).c_str(), String(analog).c_str());
// Send to Domoticz
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
domoticzSend("dczAnaIdx", 0, String(analog).c_str());
#endif
// Send to InfluxDB
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
influxDBSend(MQTT_TOPIC_ANALOG, analog);
#endif
// Update websocket clients
char buffer[100];
sprintf_P(buffer, PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), analog);
wsSend(buffer);
#if WEB_SUPPORT
char buffer[100];
snprintf_P(buffer, sizeof(buffer), PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), analog);
wsSend(buffer);
#endif
}


+ 1
- 1
code/espurna/button.ino View File

@ -25,7 +25,7 @@ std::vector<button_t> _buttons;
void buttonMQTT(unsigned char id, uint8_t event) {
if (id >= _buttons.size()) return;
char payload[2];
sprintf_P(payload, PSTR("%d"), event);
snprintf_P(payload, sizeof(payload), PSTR("%d"), event);
mqttSend(MQTT_TOPIC_BUTTON, id, payload);
}
#endif


+ 16
- 15
code/espurna/config/arduino.h View File

@ -44,18 +44,19 @@
// Features (values below are non-default values)
//--------------------------------------------------------------------------------
//#define ENABLE_ANALOG 1
//#define ENABLE_DHT 1
//#define ENABLE_DOMOTICZ 0
//#define ENABLE_DS18B20 1
//#define ENABLE_EMON 1
//#define ENABLE_I2C 1
//#define ENABLE_INFLUXDB 0
//#define ENABLE_FAUXMO 0
//#define ENABLE_MDNS 0
//#define ENABLE_NOFUSS 1
//#define ENABLE_RF 1
//#define ENABLE_SERIAL_DEBUG 0
//#define ENABLE_SPIFFS 1
//#define ENABLE_TERMINAL 0
//#define ENABLE_UDP_DEBUG 1
//#define ALEXA_SUPPORT 0
//#define ANALOG_SUPPORT 1
//#define DEBUG_SERIAL_SUPPORT 0
//#define DEBUG_UDP_SUPPORT 1
//#define DHT_SUPPORT 1
//#define DOMOTICZ_SUPPORT 0
//#define DS18B20_SUPPORT 1
//#define EMON_SUPPORT 1
//#define I2C_SUPPORT 1
//#define INFLUXDB_SUPPORT 0
//#define MDNS_SUPPORT 0
//#define NOFUSS_SUPPORT 1
//#define RF_SUPPORT 1
//#define SPIFFS_SUPPORT 1
//#define TERMINAL_SUPPORT 0
//#define WEB_SUPPORT 0

+ 95
- 39
code/espurna/config/general.h View File

@ -3,14 +3,20 @@
// Configuration settings are in the settings.h file
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// GENERAL
//------------------------------------------------------------------------------
#define ADMIN_PASS "fibonacci" // Default password (WEB, OTA, WIFI)
//------------------------------------------------------------------------------
// DEBUG
//------------------------------------------------------------------------------
// Serial debug log
#ifndef ENABLE_SERIAL_DEBUG
#define ENABLE_SERIAL_DEBUG 1 // Enable serial debug log
#ifndef DEBUG_SERIAL_SUPPORT
#define DEBUG_SERIAL_SUPPORT 1 // Enable serial debug log
#endif
#ifndef DEBUG_PORT
#define DEBUG_PORT Serial // Default debugging port
@ -22,8 +28,8 @@
// To receive the message son the destination computer use nc:
// nc -ul 8111
#ifndef ENABLE_UDP_DEBUG
#define ENABLE_UDP_DEBUG 0 // Enable UDP debug log
#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
@ -33,7 +39,7 @@
// General debug options and macros
#define DEBUG_MESSAGE_MAX_LENGTH 80
#if (ENABLE_SERIAL_DEBUG==1) || (ENABLE_UDP_DEBUG==1)
#if (DEBUG_SERIAL_SUPPORT==1) || (DEBUG_UDP_SUPPORT==1)
#define DEBUG_MSG(...) debugSend(__VA_ARGS__)
#define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__)
#endif
@ -47,8 +53,8 @@
// TERMINAL
//------------------------------------------------------------------------------
#ifndef ENABLE_TERMINAL
#define ENABLE_TERMINAL 1 // Enable terminal commands
#ifndef TERMINAL_SUPPORT
#define TERMINAL_SUPPORT 1 // Enable terminal commands
#endif
//------------------------------------------------------------------------------
@ -151,6 +157,10 @@ PROGMEM const char* const custom_reset_string[] = {
#define RELAY_MODE_SAME 2
#define RELAY_MODE_TOOGLE 3
#define RELAY_TYPE_NORMAL 0
#define RELAY_TYPE_INVERSE 1
#define RELAY_TYPE_LATCHED 2
#define RELAY_SYNC_ANY 0
#define RELAY_SYNC_NONE_OR_ONE 1
#define RELAY_SYNC_ONE 2
@ -183,6 +193,9 @@ PROGMEM const char* const custom_reset_string[] = {
// Allowed actual relay changes inside requests flood protection window
#define RELAY_FLOOD_CHANGES 5
// Pulse with in milliseconds for a latched relay
#define RELAY_LATCHING_PULSE 10
//------------------------------------------------------------------------------
// I18N
//------------------------------------------------------------------------------
@ -201,27 +214,40 @@ PROGMEM const char* const custom_reset_string[] = {
#define LED_AUTO 1
// LED # to use as WIFI status indicator
#ifndef WIFI_LED
#define WIFI_LED 1
#ifndef LED_WIFI
#define LED_WIFI 1
#endif
// -----------------------------------------------------------------------------
// WIFI & WEB
// WIFI
// -----------------------------------------------------------------------------
#define WIFI_CONNECT_TIMEOUT 30000 // Connecting timeout for WIFI in ms
#define WIFI_RECONNECT_INTERVAL 120000 // If could not connect to WIFI, retry after this time in ms
#define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations
#define HTTP_USERNAME "admin" // HTTP username
#define ADMIN_PASS "fibonacci" // Default password
#define FORCE_CHANGE_PASS 1 // Force the user to change the password if default one
#define WS_BUFFER_SIZE 5 // Max number of secured websocket connections
#define WS_TIMEOUT 1800000 // Timeout for secured websocket
#define WEBSERVER_PORT 80 // HTTP port
#define DNS_PORT 53 // MDNS port
#define ENABLE_MDNS 1 // Enable MDNS by default
#define ENABLE_API 0 // Do not enable API by default
#define API_BUFFER_SIZE 10 // Size of the buffer for HTTP GET API responses
#define WIFI_AP_MODE AP_MODE_ALONE
// Optional hardcoded configuration (up to 2 different networks)
//#define WIFI1_SSID "..."
//#define WIFI1_PASS "..."
//#define WIFI1_IP "192.168.1.201"
//#define WIFI1_GW "192.168.1.1"
//#define WIFI1_MASK "255.255.255.0"
//#define WIFI1_DNS "8.8.8.8"
//#define WIFI2_SSID "..."
//#define WIFI2_PASS "..."
// -----------------------------------------------------------------------------
// WEB
// -----------------------------------------------------------------------------
#ifndef WEB_SUPPORT
#define WEB_SUPPORT 1 // This enables web support (http, api)
#endif
#ifndef WEB_EMBEDDED
#define WEB_EMBEDDED 1 // This option builds the firmware with the web interface embedded.
#endif
// This is not working at the moment
// Requires ASYNC_TCP_SSL_ENABLED to 1
@ -230,27 +256,53 @@ PROGMEM const char* const custom_reset_string[] = {
#define WEB_MODE_NORMAL 0
#define WEB_MODE_PASSWORD 1
#define AP_MODE AP_MODE_ALONE
#define WEB_USERNAME "admin" // HTTP username
#define WEB_FORCE_PASS_CHANGE 1 // Force the user to change the password if default one
#define WEB_PORT 80 // HTTP port
// This option builds the firmware with the web interface embedded.
#ifndef EMBEDDED_WEB
#define EMBEDDED_WEB 1
#endif
// -----------------------------------------------------------------------------
// WEBSOCKETS
// -----------------------------------------------------------------------------
// This will only be enabled if WEB_SUPPORT is 1 (this is the default value)
#define WS_BUFFER_SIZE 5 // Max number of secured websocket connections
#define WS_TIMEOUT 1800000 // Timeout for secured websocket
// -----------------------------------------------------------------------------
// API
// -----------------------------------------------------------------------------
// This will only be enabled if WEB_SUPPORT is 1 (this is the default value)
#define API_ENABLED 0 // Do not enable API by default
#define API_BUFFER_SIZE 10 // Size of the buffer for HTTP GET API responses
// -----------------------------------------------------------------------------
// MDNS
// -----------------------------------------------------------------------------
#define MDNS_SUPPORT 1 // Enable MDNS by default
// -----------------------------------------------------------------------------
// SPIFFS
// -----------------------------------------------------------------------------
// Do not add support for SPIFFS by default
#ifndef ENABLE_SPIFFS
#define ENABLE_SPIFFS 0
#ifndef SPIFFS_SUPPORT
#define SPIFFS_SUPPORT 0
#endif
// -----------------------------------------------------------------------------
// OTA & NOFUSS
// OTA
// -----------------------------------------------------------------------------
#define OTA_PORT 8266 // OTA port
// -----------------------------------------------------------------------------
// NOFUSS
// -----------------------------------------------------------------------------
#define NOFUSS_SERVER "" // Default NoFuss Server
#define NOFUSS_INTERVAL 3600000 // Check for updates every hour
@ -324,6 +376,7 @@ PROGMEM const char* const custom_reset_string[] = {
// 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
#define MQTT_USE_GETTER ""
#define MQTT_USE_SETTER "/set"
@ -331,9 +384,10 @@ PROGMEM const char* const custom_reset_string[] = {
// I2C
// -----------------------------------------------------------------------------
#ifndef ENABLE_I2C
#define ENABLE_I2C 0 // I2C enabled
#ifndef I2C_SUPPORT
#define I2C_SUPPORT 0 // I2C enabled
#endif
#define I2C_SDA_PIN 4 // SDA GPIO
#define I2C_SCL_PIN 14 // SCL GPIO
#define I2C_CLOCK_STRETCH_TIME 200 // BRZO clock stretch time
@ -370,9 +424,10 @@ PROGMEM const char* const custom_reset_string[] = {
// DOMOTICZ
// -----------------------------------------------------------------------------
#ifndef ENABLE_DOMOTICZ
#define ENABLE_DOMOTICZ 1 // Build with domoticz support
#ifndef DOMOTICZ_SUPPORT
#define DOMOTICZ_SUPPORT 1 // Build with domoticz support
#endif
#define DOMOTICZ_ENABLED 1 // Enable domoticz by default
#define DOMOTICZ_IN_TOPIC "domoticz/in" // Default subscription topic
#define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic
@ -381,9 +436,10 @@ PROGMEM const char* const custom_reset_string[] = {
// INFLUXDB
// -----------------------------------------------------------------------------
#ifndef ENABLE_INFLUXDB
#define ENABLE_INFLUXDB 1 // Enable InfluxDB support by default
#ifndef INFLUXDB_SUPPORT
#define INFLUXDB_SUPPORT 1 // Enable InfluxDB support by default
#endif
#define INFLUXDB_PORT 8086 // Default InfluxDB port
// -----------------------------------------------------------------------------
@ -400,14 +456,14 @@ PROGMEM const char* const custom_reset_string[] = {
// -----------------------------------------------------------------------------
// This setting defines whether Alexa support should be built into the firmware
#ifndef ENABLE_FAUXMO
#define ENABLE_FAUXMO 1
#ifndef ALEXA_SUPPORT
#define ALEXA_SUPPORT 1
#endif
// This is default value for the fauxmoEnabled setting that defines whether
// This is default value for the alexaEnabled setting that defines whether
// this device should be discoberable and respond to Alexa commands.
// Both ENABLE_FAUXMO and fauxmoEnabled should be 1 for Alexa support to work.
#define FAUXMO_ENABLED 1
// Both ALEXA_SUPPORT and alexaEnabled should be 1 for Alexa support to work.
#define ALEXA_ENABLED 1
// -----------------------------------------------------------------------------


+ 81
- 45
code/espurna/config/hardware.h View File

@ -36,7 +36,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 2
@ -53,7 +53,7 @@
// Relays
#define RELAY1_PIN 5
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 2
@ -68,7 +68,7 @@
// Info
#define MANUFACTURER "TINKERMAN"
#define DEVICE "ESPURNA_H"
#define ENABLE_HLW8012 1
#define HLW8012_SUPPORT 1
// Buttons
#define BUTTON1_PIN 4
@ -77,14 +77,14 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 1
#define RELAY1_TYPE RELAY_TYPE_INVERSE
// LEDs
#define LED1_PIN 5
#define LED1_PIN_INVERSE 0
// HLW8012
#define ENABLE_HLW8012 1
#define HLW8012_SUPPORT 1
#define HLW8012_SEL_PIN 2
#define HLW8012_CF1_PIN 13
#define HLW8012_CF_PIN 14
@ -106,7 +106,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -125,7 +125,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -144,7 +144,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -163,7 +163,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -182,7 +182,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -201,7 +201,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -220,7 +220,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -231,7 +231,7 @@
// Info
#define MANUFACTURER "ITEAD_STUDIO"
#define DEVICE "SONOFF_POW"
#define ENABLE_HLW8012 1
#define HLW8012_SUPPORT 1
// Buttons
#define BUTTON1_PIN 0
@ -240,14 +240,14 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 15
#define LED1_PIN_INVERSE 0
// HLW8012
#define ENABLE_HLW8012 1
#define HLW8012_SUPPORT 1
#define HLW8012_SEL_PIN 5
#define HLW8012_CF1_PIN 13
#define HLW8012_CF_PIN 14
@ -260,8 +260,8 @@
#define SERIAL_BAUDRATE 19230
#define RELAY_PROVIDER RELAY_PROVIDER_DUAL
#define DUMMY_RELAY_COUNT 2
#define ENABLE_SERIAL_DEBUG 0
#define ENABLE_TERMINAL 0
#define DEBUG_SERIAL_SUPPORT 0
#define TERMINAL_SUPPORT 0
// Buttons
#define BUTTON3_RELAY 1
@ -298,10 +298,10 @@
#define RELAY3_PIN 4
#define RELAY4_PIN 15
#define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN_INVERSE 0
#define RELAY3_PIN_INVERSE 0
#define RELAY4_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_TYPE RELAY_TYPE_NORMAL
#define RELAY3_TYPE RELAY_TYPE_NORMAL
#define RELAY4_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -335,10 +335,10 @@
#define RELAY3_PIN 4
#define RELAY4_PIN 15
#define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN_INVERSE 0
#define RELAY3_PIN_INVERSE 0
#define RELAY4_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_TYPE RELAY_TYPE_NORMAL
#define RELAY3_TYPE RELAY_TYPE_NORMAL
#define RELAY4_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -366,7 +366,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -385,7 +385,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -417,7 +417,7 @@
#define RELAY_PROVIDER RELAY_PROVIDER_RFBRIDGE
#define DUMMY_RELAY_COUNT 6
#define TRACK_RELAY_STATUS 0
#define ENABLE_TERMINAL 0
#define TERMINAL_SUPPORT 0
// Buttons
#define BUTTON1_PIN 0
@ -472,7 +472,7 @@
// Relays
#define RELAY1_PIN 5
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -498,8 +498,8 @@
#define RELAY1_PIN 12
#define RELAY2_PIN 4
#define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -529,9 +529,9 @@
#define RELAY2_PIN 5
#define RELAY3_PIN 4
#define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN_INVERSE 0
#define RELAY3_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_TYPE RELAY_TYPE_NORMAL
#define RELAY3_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 13
@ -561,8 +561,8 @@
#define RELAY1_PIN 12
#define RELAY2_PIN 13
#define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 16
@ -585,7 +585,7 @@
// Relays
#define RELAY1_PIN 15
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 2
@ -690,8 +690,8 @@
#define RELAY1_PIN 2
#define RELAY2_PIN 14
#define RELAY1_PIN_INVERSE 1
#define RELAY2_PIN_INVERSE 1
#define RELAY1_TYPE RELAY_TYPE_INVERSE
#define RELAY2_TYPE RELAY_TYPE_INVERSE
#elif defined(JANGOE_WIFI_RELAY_NO)
@ -713,8 +713,8 @@
#define RELAY1_PIN 2
#define RELAY2_PIN 14
#define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_TYPE RELAY_TYPE_NORMAL
// -----------------------------------------------------------------------------
// Jorge García Wifi+Relays Board Kit
@ -732,8 +732,8 @@
#define RELAY1_PIN 0
#define RELAY2_PIN 2
#define RELAY1_PIN_INVERSE 1
#define RELAY2_PIN_INVERSE 1
#define RELAY1_TYPE RELAY_TYPE_INVERSE
#define RELAY2_TYPE RELAY_TYPE_INVERSE
// -----------------------------------------------------------------------------
// WiFi MQTT Relay / Thermostat
@ -752,7 +752,7 @@
// Relays
#define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 16
@ -779,12 +779,35 @@
// Relays
#define RELAY1_PIN 15
#define RELAY1_PIN_INVERSE 0
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 2
#define LED1_PIN_INVERSE 0
// -----------------------------------------------------------------------------
// EX-Store Wifi Relay v3.1
// https://ex-store.de/ESP8266-WiFi-Relay-V31
// -----------------------------------------------------------------------------
#elif defined(EXS_WIFI_RELAY_V31)
// Untested
// Info
#define MANUFACTURER "EXS"
#define DEVICE "WIFI_RELAY_V31"
// Buttons
#define BUTTON1_PIN 0
#define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
// Relays
#define RELAY1_PIN 13
#define RELAY1_TYPE RELAY_TYPE_LATCHED
#define RELAY1_RESET_PIN 12
// -----------------------------------------------------------------------------
// Unknown hardware
// -----------------------------------------------------------------------------
@ -875,6 +898,19 @@
#define BUTTON4_RELAY 0
#endif
#ifndef RELAY1_RESET_PIN
#define RELAY1_RESET_PIN 0
#endif
#ifndef RELAY2_RESET_PIN
#define RELAY2_RESET_PIN 0
#endif
#ifndef RELAY3_RESET_PIN
#define RELAY3_RESET_PIN 0
#endif
#ifndef RELAY4_RESET_PIN
#define RELAY4_RESET_PIN 0
#endif
#ifndef RELAY1_DELAY_ON
#define RELAY1_DELAY_ON 0
#endif


+ 4
- 0
code/espurna/config/prototypes.h View File

@ -8,13 +8,17 @@
typedef std::function<void(char *, size_t)> apiGetCallbackFunction;
typedef std::function<void(const char *)> apiPutCallbackFunction;
void apiRegister(const char * url, const char * key, apiGetCallbackFunction getFn, apiPutCallbackFunction putFn = NULL);
void mqttRegister(void (*callback)(unsigned int, const char *, const char *));
String mqttSubtopic(char * topic);
template<typename T> bool setSetting(const String& key, T value);
template<typename T> bool setSetting(const String& key, unsigned int index, T value);
template<typename T> String getSetting(const String& key, T defaultValue);
template<typename T> String getSetting(const String& key, unsigned int index, T defaultValue);
template<typename T> void domoticzSend(const char * key, T value);
template<typename T> void domoticzSend(const char * key, T nvalue, const char * svalue);
template<typename T> bool influxDBSend(const char * topic, T payload);
char * ltrim(char * s);

+ 88
- 64
code/espurna/config/sensors.h View File

@ -1,65 +1,85 @@
//--------------------------------------------------------------------------------
// Custom RF module
// Check http://tinkerman.cat/adding-rf-to-a-non-rf-itead-sonoff/
// Enable support by passing ENABLE_RF=1 build flag
// Enable support by passing RF_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define RF_PIN 14
#define RF_CHANNEL 31
#define RF_DEVICE 1
#ifndef RF_SUPPORT
#define RF_SUPPORT 0
#endif
#define RF_PIN 14
#define RF_CHANNEL 31
#define RF_DEVICE 1
//--------------------------------------------------------------------------------
// DHTXX temperature/humidity sensor
// Enable support by passing ENABLE_DHT=1 build flag
// Enable support by passing DHT_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define DHT_PIN 14
#define DHT_UPDATE_INTERVAL 60000
#define DHT_TYPE DHT22
#define DHT_TIMING 11
#define DHT_TEMPERATURE_TOPIC "temperature"
#define DHT_HUMIDITY_TOPIC "humidity"
#ifndef DHT_SUPPORT
#define DHT_SUPPORT 0
#endif
#define DHT_PIN 14
#define DHT_UPDATE_INTERVAL 60000
#define DHT_TYPE DHT22
#define DHT_TIMING 11
#define DHT_TEMPERATURE_TOPIC "temperature"
#define DHT_HUMIDITY_TOPIC "humidity"
#define HUMIDITY_NORMAL 0
#define HUMIDITY_COMFORTABLE 1
#define HUMIDITY_DRY 2
#define HUMIDITY_WET 3
#define HUMIDITY_NORMAL 0
#define HUMIDITY_COMFORTABLE 1
#define HUMIDITY_DRY 2
#define HUMIDITY_WET 3
//--------------------------------------------------------------------------------
// Analog sensor
// Enable support by passing ENABLE_ANALOG=1 build flag
// Enable support by passing ANALOG_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define ANALOG_PIN 0
#define ANALOG_UPDATE_INTERVAL 60000
#define ANALOG_TOPIC "analog"
#ifndef ANALOG_SUPPORT
#define ANALOG_SUPPORT 0
#endif
#define ANALOG_PIN 0
#define ANALOG_UPDATE_INTERVAL 60000
#define ANALOG_TOPIC "analog"
#if ENABLE_ANALOG
#undef ENABLE_ADC_VCC
#define ENABLE_ADC_VCC 0
#if ANALOG_SUPPORT
#undef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 0
#endif
//--------------------------------------------------------------------------------
// DS18B20 temperature sensor
// Enable support by passing ENABLE_DS18B20=1 build flag
// Enable support by passing DS18B20_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define DS_PIN 14
#define DS_UPDATE_INTERVAL 60000
#define DS_TEMPERATURE_TOPIC "temperature"
#ifndef DS18B20_SUPPORT
#define DS18B20_SUPPORT 0
#endif
#define DS18B20_PIN 14
#define DS18B20_UPDATE_INTERVAL 60000
#define DS18B20_TEMPERATURE_TOPIC "temperature"
//--------------------------------------------------------------------------------
// Custom current sensor
// Check http://tinkerman.cat/your-laundry-is-done/
// Check http://tinkerman.cat/power-monitoring-sonoff-th-adc121/
// Enable support by passing ENABLE_EMON=1 build flag
// Enable support by passing EMON_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define EMON_ANALOG_PROVIDER 0
#define EMON_ADC121_PROVIDER 1
#ifndef EMON_SUPPORT
#define EMON_SUPPORT 0
#endif
#define EMON_ANALOG_PROVIDER 0
#define EMON_ADC121_PROVIDER 1
// If you select EMON_ADC121_PROVIDER you need to enable and configure I2C in general.h
#define EMON_PROVIDER EMON_ANALOG_PROVIDER
#define EMON_PROVIDER EMON_ANALOG_PROVIDER
#if EMON_PROVIDER == EMON_ANALOG_PROVIDER
#define EMON_CURRENT_PIN 0
@ -67,9 +87,9 @@
#define EMON_REFERENCE_VOLTAGE 1.0
#define EMON_CURRENT_PRECISION 1
#define EMON_CURRENT_OFFSET 0.25
#if ENABLE_EMON
#undef ENABLE_ADC_VCC
#define ENABLE_ADC_VCC 0
#if EMON_SUPPORT
#undef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 0
#endif
#endif
@ -81,51 +101,55 @@
#define EMON_CURRENT_OFFSET 0.10
#endif
#define EMON_CURRENT_RATIO 30
#define EMON_SAMPLES 1000
#define EMON_INTERVAL 10000
#define EMON_MEASUREMENTS 6
#define EMON_MAINS_VOLTAGE 230
#define EMON_APOWER_TOPIC "apower"
#define EMON_ENERGY_TOPIC "energy"
#define EMON_CURRENT_TOPIC "current"
#define EMON_CURRENT_RATIO 30
#define EMON_SAMPLES 1000
#define EMON_INTERVAL 10000
#define EMON_MEASUREMENTS 6
#define EMON_MAINS_VOLTAGE 230
#define EMON_APOWER_TOPIC "apower"
#define EMON_ENERGY_TOPIC "energy"
#define EMON_CURRENT_TOPIC "current"
//--------------------------------------------------------------------------------
// HLW8012 power sensor (Sonoff POW, Espurna H)
// Enable support by passing ENABLE_HLW8012=1 build flag
// Enable support by passing HLW8012_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#ifndef HLW8012_SUPPORT
#define HLW8012_SUPPORT 0
#endif
// GPIOs defined in the hardware.h file
#define HLW8012_USE_INTERRUPTS 1
#define HLW8012_SEL_CURRENT HIGH
#define HLW8012_CURRENT_R 0.001
#define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Real: 2280k
#define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Real 1.009k
#define HLW8012_POWER_TOPIC "power"
#define HLW8012_CURRENT_TOPIC "current"
#define HLW8012_VOLTAGE_TOPIC "voltage"
#define HLW8012_APOWER_TOPIC "apower"
#define HLW8012_RPOWER_TOPIC "rpower"
#define HLW8012_PFACTOR_TOPIC "pfactor"
#define HLW8012_ENERGY_TOPIC "energy"
#define HLW8012_UPDATE_INTERVAL 5000
#define HLW8012_REPORT_EVERY 12
#define HLW8012_MIN_POWER 5
#define HLW8012_MAX_POWER 2500
#define HLW8012_MIN_CURRENT 0.05
#define HLW8012_MAX_CURRENT 10
#define HLW8012_USE_INTERRUPTS 1
#define HLW8012_SEL_CURRENT HIGH
#define HLW8012_CURRENT_R 0.001
#define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Real: 2280k
#define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Real 1.009k
#define HLW8012_POWER_TOPIC "power"
#define HLW8012_CURRENT_TOPIC "current"
#define HLW8012_VOLTAGE_TOPIC "voltage"
#define HLW8012_APOWER_TOPIC "apower"
#define HLW8012_RPOWER_TOPIC "rpower"
#define HLW8012_PFACTOR_TOPIC "pfactor"
#define HLW8012_ENERGY_TOPIC "energy"
#define HLW8012_UPDATE_INTERVAL 5000
#define HLW8012_REPORT_EVERY 12
#define HLW8012_MIN_POWER 5
#define HLW8012_MAX_POWER 2500
#define HLW8012_MIN_CURRENT 0.05
#define HLW8012_MAX_CURRENT 10
//--------------------------------------------------------------------------------
// Internal power montior
// Enable support by passing ENABLE_ADC_VCC=1 build flag
// Enable support by passing ADC_VCC_ENABLED=1 build flag
// Do not enable this if using the analog GPIO for any other thing
//--------------------------------------------------------------------------------
#ifndef ENABLE_ADC_VCC
#define ENABLE_ADC_VCC 1
#ifndef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 1
#endif
#if ENABLE_ADC_VCC
#if ADC_VCC_ENABLED
ADC_MODE(ADC_VCC);
#endif

BIN
code/espurna/data/index.html.gz View File


+ 5
- 5
code/espurna/debug.ino View File

@ -9,7 +9,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <stdio.h>
#include <stdarg.h>
#ifdef ENABLE_UDP_DEBUG
#ifdef DEBUG_UDP_SUPPORT
#include <WiFiUdp.h>
WiFiUDP udpDebug;
#endif
@ -23,14 +23,14 @@ void debugSend(const char * format, ...) {
int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, format, args);
va_end(args);
#ifdef ENABLE_SERIAL_DEBUG
#ifdef DEBUG_SERIAL_SUPPORT
DEBUG_PORT.printf(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) {
DEBUG_PORT.printf(" (...)\n");
}
#endif
#ifdef ENABLE_UDP_DEBUG
#ifdef DEBUG_UDP_SUPPORT
udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
udpDebug.write(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) {
@ -54,14 +54,14 @@ void debugSend_P(PGM_P format, ...) {
int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args);
va_end(args);
#ifdef ENABLE_SERIAL_DEBUG
#ifdef DEBUG_SERIAL_SUPPORT
DEBUG_PORT.printf(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) {
DEBUG_PORT.printf(" (...)\n");
}
#endif
#ifdef ENABLE_UDP_DEBUG
#ifdef DEBUG_UDP_SUPPORT
udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
udpDebug.write(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) {


+ 20
- 13
code/espurna/dht.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_DHT
#if DHT_SUPPORT
#include <DHT.h>
#include <Adafruit_Sensor.h>
@ -29,13 +29,18 @@ unsigned int getDHTHumidity() {
}
void dhtSetup() {
dht.begin();
apiRegister(DHT_TEMPERATURE_TOPIC, DHT_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dhtTemperature, len-1, 1, buffer);
});
apiRegister(DHT_HUMIDITY_TOPIC, DHT_HUMIDITY_TOPIC, [](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), _dhtHumidity);
});
#if WEB_SUPPORT
apiRegister(DHT_TEMPERATURE_TOPIC, DHT_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dhtTemperature, len-1, 1, buffer);
});
apiRegister(DHT_HUMIDITY_TOPIC, DHT_HUMIDITY_TOPIC, [](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), _dhtHumidity);
});
#endif
}
void dhtLoop() {
@ -74,7 +79,7 @@ void dhtLoop() {
mqttSend(getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), humidity);
// Send to Domoticz
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
{
domoticzSend("dczTmpIdx", 0, temperature);
int status;
@ -88,20 +93,22 @@ void dhtLoop() {
status = HUMIDITY_DRY;
}
char buffer[2];
sprintf_P(buffer, PSTR("%d"), status);
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), status);
domoticzSend("dczHumIdx", humidity, buffer);
}
#endif
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
influxDBSend(getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), temperature);
influxDBSend(getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), humidity);
#endif
// Update websocket clients
char buffer[100];
sprintf_P(buffer, PSTR("{\"dhtVisible\": 1, \"dhtTmp\": %s, \"dhtHum\": %s, \"tmpUnits\": %d}"), temperature, humidity, tmpUnits);
wsSend(buffer);
#if WEB_SUPPORT
char buffer[100];
snprintf_P(buffer, sizeof(buffer), PSTR("{\"dhtVisible\": 1, \"dhtTmp\": %s, \"dhtHum\": %s, \"tmpUnits\": %d}"), temperature, humidity, tmpUnits);
wsSend(buffer);
#endif
}


+ 4
- 4
code/espurna/domoticz.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
#include <ArduinoJson.h>
@ -72,7 +72,7 @@ template<typename T> void domoticzSend(const char * key, T nvalue, const char *
unsigned int idx = getSetting(key).toInt();
if (idx > 0) {
char payload[128];
snprintf(payload, 128, "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue);
snprintf(payload, sizeof(payload), "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue);
mqttSendRaw(getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC).c_str(), payload);
}
}
@ -84,13 +84,13 @@ template<typename T> void domoticzSend(const char * key, T nvalue) {
void domoticzSendRelay(unsigned int relayID) {
if (!_dczEnabled) return;
char buffer[15];
sprintf_P(buffer, PSTR("dczRelayIdx%d"), relayID);
snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%d"), relayID);
domoticzSend(buffer, relayStatus(relayID) ? "1" : "0");
}
int domoticzIdx(unsigned int relayID) {
char buffer[15];
sprintf_P(buffer, PSTR("dczRelayIdx%d"), relayID);
snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%d"), relayID);
return getSetting(buffer).toInt();
}


+ 19
- 13
code/espurna/ds18b20.ino View File

@ -6,12 +6,12 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_DS18B20
#if DS18B20_SUPPORT
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(DS_PIN);
OneWire oneWire(DS18B20_PIN);
DallasTemperature ds18b20(&oneWire);
bool _dsIsConnected = false;
@ -34,12 +34,16 @@ const char* getDSTemperatureStr() {
}
void dsSetup() {
ds18b20.begin();
ds18b20.setWaitForConversion(false);
apiRegister(DS_TEMPERATURE_TOPIC, DS_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dsTemperature, len-1, 1, buffer);
});
#if WEB_SUPPORT
apiRegister(DS18B20_TEMPERATURE_TOPIC, DS18B20_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dsTemperature, len-1, 1, buffer);
});
#endif
}
void dsLoop() {
@ -47,7 +51,7 @@ void dsLoop() {
// Check if we should read new data
static unsigned long last_update = 0;
static bool requested = false;
if ((millis() - last_update > DS_UPDATE_INTERVAL) || (last_update == 0)) {
if ((millis() - last_update > DS18B20_UPDATE_INTERVAL) || (last_update == 0)) {
if (!requested) {
ds18b20.requestTemperatures();
requested = true;
@ -92,21 +96,23 @@ void dsLoop() {
(_dsIsConnected ? ((tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF") : ""));
// Send MQTT messages
mqttSend(getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
mqttSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
// Send to Domoticz
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
domoticzSend("dczTmpIdx", 0, _dsTemperatureStr);
#endif
#if ENABLE_INFLUXDB
influxDBSend(getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
#if INFLUXDB_SUPPORT
influxDBSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
#endif
// Update websocket clients
char buffer[100];
sprintf_P(buffer, PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits);
wsSend(buffer);
#if WEB_SUPPORT
char buffer[100];
snprintf_P(buffer, sizeof(buffer), PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits);
wsSend(buffer);
#endif
}


+ 29
- 25
code/espurna/emon.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_EMON
#if EMON_SUPPORT
#include <EmonLiteESP.h>
#include <EEPROM.h>
@ -111,21 +111,25 @@ void powerMonitorSetup() {
brzo_i2c_end_transaction();
#endif
apiRegister(EMON_APOWER_TOPIC, EMON_APOWER_TOPIC, [](char * buffer, size_t len) {
if (_emonReady) {
snprintf_P(buffer, len, PSTR("%d"), _emonPower);
} else {
buffer = NULL;
}
});
#if WEB_SUPPORT
apiRegister(EMON_CURRENT_TOPIC, EMON_CURRENT_TOPIC, [](char * buffer, size_t len) {
if (_emonReady) {
dtostrf(_emonCurrent, len-1, 3, buffer);
} else {
buffer = NULL;
}
});
apiRegister(EMON_APOWER_TOPIC, EMON_APOWER_TOPIC, [](char * buffer, size_t len) {
if (_emonReady) {
snprintf_P(buffer, len, PSTR("%d"), _emonPower);
} else {
buffer = NULL;
}
});
apiRegister(EMON_CURRENT_TOPIC, EMON_CURRENT_TOPIC, [](char * buffer, size_t len) {
if (_emonReady) {
dtostrf(_emonCurrent, len-1, 3, buffer);
} else {
buffer = NULL;
}
});
#endif // WEB_SUPPORT
}
@ -163,11 +167,11 @@ void powerMonitorLoop() {
DEBUG_MSG_P(PSTR("[ENERGY] Power: %dW\n"), int(current * voltage));
// Update websocket clients
if (wsConnected()) {
char text[100];
sprintf_P(text, PSTR("{\"emonVisible\": 1, \"emonApparentPower\": %d, \"emonCurrent\": %s}"), int(current * voltage), String(current, 3).c_str());
wsSend(text);
}
#if WEB_SUPPORT
char buffer[100];
snprintf_P(buffer, sizeof(buffer), PSTR("{\"emonVisible\": 1, \"emonApparentPower\": %d, \"emonCurrent\": %s}"), int(current * voltage), String(current, 3).c_str());
wsSend(buffer);
#endif
}
@ -188,19 +192,19 @@ void powerMonitorLoop() {
mqttSend(getSetting("emonEnergyTopic", EMON_ENERGY_TOPIC).c_str(), String(energy_delta, 3).c_str());
// Report values to Domoticz
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
{
char buffer[20];
snprintf_P(buffer, 20, PSTR("%d;%s"), _emonPower, String(energy_delta, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%d;%s"), _emonPower, String(energy_delta, 3).c_str());
domoticzSend("dczPowIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%s"), String(energy_delta, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%s"), String(energy_delta, 3).c_str());
domoticzSend("dczEnergyIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%s"), String(_emonCurrent, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%s"), String(_emonCurrent, 3).c_str());
domoticzSend("dczCurrentIdx", 0, buffer);
}
#endif
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
influxDBSend(getSetting("emonPowerTopic", EMON_APOWER_TOPIC).c_str(), _emonPower);
influxDBSend(getSetting("emonCurrTopic", EMON_CURRENT_TOPIC).c_str(), String(_emonCurrent, 3).c_str());
influxDBSend(getSetting("emonEnergyTopic", EMON_ENERGY_TOPIC).c_str(), String(energy_delta, 3).c_str());


+ 39
- 36
code/espurna/espurna.ino View File

@ -27,9 +27,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------
String getIdentifier() {
char identifier[20];
sprintf_P(identifier, PSTR("%s_%06X"), DEVICE, ESP.getChipId());
return String(identifier);
char buffer[20];
snprintf_P(buffer, sizeof(buffer), PSTR("%s_%06X"), DEVICE, ESP.getChipId());
return String(buffer);
}
void heartbeat() {
@ -46,7 +46,7 @@ void heartbeat() {
if (!mqttConnected()) {
DEBUG_MSG_P(PSTR("[MAIN] Uptime: %ld seconds\n"), uptime_seconds);
DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), free_heap);
#if ENABLE_ADC_VCC
#if ADC_VCC_ENABLED
DEBUG_MSG_P(PSTR("[MAIN] Power: %d mV\n"), ESP.getVcc());
#endif
}
@ -75,13 +75,13 @@ void heartbeat() {
#endif
#if (HEARTBEAT_REPORT_UPTIME)
mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
influxDBSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
#endif
#endif
#if (HEARTBEAT_REPORT_FREEHEAP)
mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
influxDBSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#endif
#endif
@ -92,7 +92,7 @@ void heartbeat() {
lightMQTT();
#endif
#if (HEARTBEAT_REPORT_VCC)
#if ENABLE_ADC_VCC
#if ADC_VCC_ENABLED
mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str());
#endif
#endif
@ -121,7 +121,7 @@ void hardwareSetup() {
EEPROM.begin(EEPROM_SIZE);
#if ENABLE_SERIAL_DEBUG
#if DEBUG_SERIAL_SUPPORT
DEBUG_PORT.begin(SERIAL_BAUDRATE);
if (customReset() == CUSTOM_RESET_HARDWARE) {
DEBUG_PORT.setDebugOutput(true);
@ -130,7 +130,7 @@ void hardwareSetup() {
Serial.begin(SERIAL_BAUDRATE);
#endif
#if ENABLE_SPIFFS
#if SPIFFS_SUPPORT
SPIFFS.begin();
#endif
@ -172,11 +172,11 @@ void welcome() {
DEBUG_MSG_P(PSTR("Flash mode: %s\n"), mode == FM_QIO ? "QIO" : mode == FM_QOUT ? "QOUT" : mode == FM_DIO ? "DIO" : mode == FM_DOUT ? "DOUT" : "UNKNOWN");
DEBUG_MSG_P(PSTR("\n"));
DEBUG_MSG_P(PSTR("Flash sector size: %8u bytes\n"), SPI_FLASH_SEC_SIZE);
DEBUG_MSG_P(PSTR("Flash size (SDK): %8u bytes\n"), ESP.getFlashChipSize());
DEBUG_MSG_P(PSTR("Flash size (CHIP): %8u bytes / %4d sectors\n"), ESP.getFlashChipRealSize(), sectors(ESP.getFlashChipRealSize()));
DEBUG_MSG_P(PSTR("Flash size (CHIP): %8u bytes\n"), ESP.getFlashChipRealSize());
DEBUG_MSG_P(PSTR("Flash size (SDK): %8u bytes / %4d sectors\n"), ESP.getFlashChipSize(), sectors(ESP.getFlashChipSize()));
DEBUG_MSG_P(PSTR("Firmware size: %8u bytes / %4d sectors\n"), ESP.getSketchSize(), sectors(ESP.getSketchSize()));
DEBUG_MSG_P(PSTR("OTA size: %8u bytes / %4d sectors\n"), ESP.getFreeSketchSpace(), sectors(ESP.getFreeSketchSpace()));
#if ENABLE_SPIFFS
#if SPIFFS_SUPPORT
FSInfo fs_info;
bool fs = SPIFFS.info(fs_info);
if (fs) {
@ -188,7 +188,7 @@ void welcome() {
DEBUG_MSG_P(PSTR("EEPROM size: %8u bytes / %4d sectors\n"), settingsMaxSize(), sectors(settingsMaxSize()));
DEBUG_MSG_P(PSTR("Empty space: %8u bytes / 4 sectors\n"), 4 * SPI_FLASH_SEC_SIZE);
#if ENABLE_SPIFFS
#if SPIFFS_SUPPORT
if (fs) {
DEBUG_MSG_P(PSTR("\n"));
DEBUG_MSG_P(PSTR("SPIFFS total size: %8u bytes\n"), fs_info.totalBytes);
@ -226,7 +226,10 @@ void setup() {
saveSettings();
}
webSetup();
#if WEB_SUPPORT
webSetup();
#endif
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
lightSetup();
#endif
@ -245,37 +248,37 @@ void setup() {
rfbSetup();
#endif
#if ENABLE_I2C
#if I2C_SUPPORT
i2cSetup();
#endif
#if ENABLE_FAUXMO
fauxmoSetup();
#if ALEXA_SUPPORT
alexaSetup();
#endif
#if ENABLE_NOFUSS
#if NOFUSS_SUPPORT
nofussSetup();
#endif
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
influxDBSetup();
#endif
#if ENABLE_HLW8012
#if HLW8012_SUPPORT
hlw8012Setup();
#endif
#if ENABLE_DS18B20
#if DS18B20_SUPPORT
dsSetup();
#endif
#if ENABLE_ANALOG
#if ANALOG_SUPPORT
analogSetup();
#endif
#if ENABLE_DHT
#if DHT_SUPPORT
dhtSetup();
#endif
#if ENABLE_RF
#if RF_SUPPORT
rfSetup();
#endif
#if ENABLE_EMON
#if EMON_SUPPORT
powerMonitorSetup();
#endif
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
domoticzSetup();
#endif
@ -299,31 +302,31 @@ void loop() {
rfbLoop();
#endif
#if ENABLE_TERMINAL
#if TERMINAL_SUPPORT
settingsLoop();
#endif
#if ENABLE_FAUXMO
fauxmoLoop();
#if ALEXA_SUPPORT
alexaLoop();
#endif
#if ENABLE_NOFUSS
#if NOFUSS_SUPPORT
nofussLoop();
#endif
#if ENABLE_HLW8012
#if HLW8012_SUPPORT
hlw8012Loop();
#endif
#if ENABLE_DS18B20
#if DS18B20_SUPPORT
dsLoop();
#endif
#if ENABLE_ANALOG
#if ANALOG_SUPPORT
analogLoop();
#endif
#if ENABLE_DHT
#if DHT_SUPPORT
dhtLoop();
#endif
#if ENABLE_RF
#if RF_SUPPORT
rfLoop();
#endif
#if ENABLE_EMON
#if EMON_SUPPORT
powerMonitorLoop();
#endif


+ 0
- 44
code/espurna/fauxmo.ino View File

@ -1,44 +0,0 @@
/*
FAUXMO MODULE
Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_FAUXMO
#include <fauxmoESP.h>
fauxmoESP fauxmo;
// -----------------------------------------------------------------------------
// FAUXMO
// -----------------------------------------------------------------------------
void fauxmoConfigure() {
fauxmo.enable(getSetting("fauxmoEnabled", FAUXMO_ENABLED).toInt() == 1);
}
void fauxmoSetup() {
fauxmoConfigure();
unsigned int relays = relayCount();
String hostname = getSetting("hostname");
if (relays == 1) {
fauxmo.addDevice(hostname.c_str());
} else {
for (unsigned int i=0; i<relays; i++) {
fauxmo.addDevice((hostname + "_" + i).c_str());
}
}
fauxmo.onMessage([relays](unsigned char device_id, const char * name, bool state) {
DEBUG_MSG_P(PSTR("[FAUXMO] %s state: %s\n"), name, state ? "ON" : "OFF");
relayStatus(device_id, state);
});
}
void fauxmoLoop() {
fauxmo.handle();
}
#endif

+ 47
- 38
code/espurna/hardware.ino View File

@ -26,7 +26,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(WEMOS_D1_MINI_RELAYSHIELD)
@ -34,7 +34,7 @@ void hwUpwardsCompatibility() {
setSetting("ledGPIO", 1, 2);
setSetting("ledLogic", 1, 1);
setSetting("relayGPIO", 1, 5);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_BASIC)
@ -44,7 +44,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_TH)
@ -54,7 +54,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_SV)
@ -64,7 +64,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_TOUCH)
@ -74,7 +74,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_POW)
@ -84,7 +84,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("selGPIO", 5);
setSetting("cf1GPIO", 13);
setSetting("cfGPIO", 14);
@ -106,7 +106,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_4CH)
@ -125,10 +125,10 @@ void hwUpwardsCompatibility() {
setSetting("relayGPIO", 2, 5);
setSetting("relayGPIO", 3, 4);
setSetting("relayGPIO", 4, 15);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
setSetting("relayLogic", 3, 0);
setSetting("relayLogic", 4, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("relayType", 2, RELAY_TYPE_NORMAL);
setSetting("relayType", 3, RELAY_TYPE_NORMAL);
setSetting("relayType", 4, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SLAMPHER)
@ -138,7 +138,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_S20)
@ -148,7 +148,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ELECTRODRAGON_WIFI_IOT)
@ -161,8 +161,8 @@ void hwUpwardsCompatibility() {
setSetting("btnRelay", 2, 2);
setSetting("relayGPIO", 1, 12);
setSetting("relayGPIO", 2, 13);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("relayType", 2, RELAY_TYPE_NORMAL);
#elif defined(WORKCHOICE_ECOPLUG)
@ -172,7 +172,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 13);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 15);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(JANGOE_WIFI_RELAY_NC)
@ -183,8 +183,8 @@ void hwUpwardsCompatibility() {
setSetting("btnRelay", 2, 2);
setSetting("relayGPIO", 1, 2);
setSetting("relayGPIO", 2, 14);
setSetting("relayLogic", 1, 1);
setSetting("relayLogic", 2, 1);
setSetting("relayType", 1, RELAY_TYPE_INVERSE);
setSetting("relayType", 2, RELAY_TYPE_INVERSE);
#elif defined(JANGOE_WIFI_RELAY_NO)
@ -195,8 +195,8 @@ void hwUpwardsCompatibility() {
setSetting("btnRelay", 2, 2);
setSetting("relayGPIO", 1, 2);
setSetting("relayGPIO", 2, 14);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("relayType", 2, RELAY_TYPE_NORMAL);
#elif defined(OPENENERGYMONITOR_MQTT_RELAY)
@ -206,15 +206,15 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(JORGEGARCIA_WIFI_RELAYS)
setSetting("board", 19);
setSetting("relayGPIO", 1, 0);
setSetting("relayLogic", 1, 1);
setSetting("relayGPIO", 2, 2);
setSetting("relayLogic", 2, 1);
setSetting("relayType", 1, RELAY_TYPE_INVERSE);
setSetting("relayType", 2, RELAY_TYPE_INVERSE);
#elif defined(AITHINKER_AI_LIGHT)
@ -250,7 +250,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(TINKERMAN_ESPURNA_H)
@ -260,7 +260,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 4);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 1);
setSetting("relayType", 1, RELAY_TYPE_INVERSE);
setSetting("selGPIO", 2);
setSetting("cf1GPIO", 13);
setSetting("cfGPIO", 14);
@ -321,10 +321,10 @@ void hwUpwardsCompatibility() {
setSetting("relayGPIO", 2, 5);
setSetting("relayGPIO", 3, 4);
setSetting("relayGPIO", 4, 15);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
setSetting("relayLogic", 3, 0);
setSetting("relayLogic", 4, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("relayType", 2, RELAY_TYPE_NORMAL);
setSetting("relayType", 3, RELAY_TYPE_NORMAL);
setSetting("relayType", 4, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_B1)
@ -356,7 +356,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 9);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 5);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_T1_2CH)
@ -369,8 +369,8 @@ void hwUpwardsCompatibility() {
setSetting("btnRelay", 2, 2);
setSetting("relayGPIO", 1, 12);
setSetting("relayGPIO", 2, 4);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("relayType", 2, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_T1_3CH)
@ -386,9 +386,9 @@ void hwUpwardsCompatibility() {
setSetting("relayGPIO", 1, 12);
setSetting("relayGPIO", 2, 5);
setSetting("relayGPIO", 3, 4);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
setSetting("relayLogic", 3, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("relayType", 2, RELAY_TYPE_NORMAL);
setSetting("relayType", 3, RELAY_TYPE_NORMAL);
#elif defined(ITEAD_SONOFF_RF)
@ -398,7 +398,7 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(WION_50055)
@ -408,7 +408,16 @@ void hwUpwardsCompatibility() {
setSetting("btnGPIO", 1, 13);
setSetting("btnRelay", 1,1);
setSetting("relayGPIO", 1, 15);
setSetting("relayLogic", 1, 0);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#elif defined(EXS_WIFI_RELAY_V31)
setSetting("board", 35);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 13);
setSetting("relayResetGPIO", 1, 12);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
#else


+ 35
- 31
code/espurna/hlw8012.ino View File

@ -7,7 +7,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_HLW8012
#if HLW8012_SUPPORT
#include <HLW8012.h>
#include <Hash.h>
@ -158,27 +158,31 @@ void hlw8012Setup() {
hlw8012RetrieveCalibration();
// API definitions
apiRegister(HLW8012_POWER_TOPIC, HLW8012_POWER_TOPIC, [](char * buffer, size_t len) {
if (_hlwReady) {
snprintf_P(buffer, len, PSTR("%d"), _hlwPower);
} else {
buffer = NULL;
}
});
apiRegister(HLW8012_CURRENT_TOPIC, HLW8012_CURRENT_TOPIC, [](char * buffer, size_t len) {
if (_hlwReady) {
dtostrf(_hlwCurrent, len-1, 3, buffer);
} else {
buffer = NULL;
}
});
apiRegister(HLW8012_VOLTAGE_TOPIC, HLW8012_VOLTAGE_TOPIC, [](char * buffer, size_t len) {
if (_hlwReady) {
snprintf_P(buffer, len, PSTR("%d"), _hlwVoltage);
} else {
buffer = NULL;
}
});
#if WEB_SUPPORT
apiRegister(HLW8012_POWER_TOPIC, HLW8012_POWER_TOPIC, [](char * buffer, size_t len) {
if (_hlwReady) {
snprintf_P(buffer, len, PSTR("%d"), _hlwPower);
} else {
buffer = NULL;
}
});
apiRegister(HLW8012_CURRENT_TOPIC, HLW8012_CURRENT_TOPIC, [](char * buffer, size_t len) {
if (_hlwReady) {
dtostrf(_hlwCurrent, len-1, 3, buffer);
} else {
buffer = NULL;
}
});
apiRegister(HLW8012_VOLTAGE_TOPIC, HLW8012_VOLTAGE_TOPIC, [](char * buffer, size_t len) {
if (_hlwReady) {
snprintf_P(buffer, len, PSTR("%d"), _hlwVoltage);
} else {
buffer = NULL;
}
});
#endif // WEB_SUPPORT
}
@ -244,8 +248,8 @@ void hlw8012Loop() {
}
voltage_previous = voltage;
if (wsConnected()) {
#if WEB_SUPPORT
{
unsigned int apparent = getApparentPower();
double factor = getPowerFactor();
unsigned int reactive = getReactivePower();
@ -264,8 +268,8 @@ void hlw8012Loop() {
String output;
root.printTo(output);
wsSend(output.c_str());
}
#endif
if (--report_count == 0) {
@ -292,21 +296,21 @@ void hlw8012Loop() {
mqttSend(getSetting("powPFactorTopic", HLW8012_PFACTOR_TOPIC).c_str(), String(factor, 2).c_str());
// Report values to Domoticz
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
{
char buffer[20];
snprintf_P(buffer, 20, PSTR("%d;%s"), _hlwPower, String(energy_delta, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%d;%s"), _hlwPower, String(energy_delta, 3).c_str());
domoticzSend("dczPowIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%s"), String(energy_delta, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%s"), String(energy_delta, 3).c_str());
domoticzSend("dczEnergyIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%d"), _hlwVoltage);
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _hlwVoltage);
domoticzSend("dczVoltIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%s"), String(_hlwCurrent).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%s"), String(_hlwCurrent).c_str());
domoticzSend("dczCurrentIdx", 0, buffer);
}
#endif
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
influxDBSend(getSetting("powPowerTopic", HLW8012_POWER_TOPIC).c_str(), String(_hlwPower).c_str());
influxDBSend(getSetting("powCurrentTopic", HLW8012_CURRENT_TOPIC).c_str(), String(_hlwCurrent, 3).c_str());
influxDBSend(getSetting("powVoltageTopic", HLW8012_VOLTAGE_TOPIC).c_str(), String(_hlwVoltage).c_str());


+ 1
- 1
code/espurna/i2c.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_I2C
#if I2C_SUPPORT
#include "brzo_i2c.h"


+ 3
- 3
code/espurna/influxdb.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
#include "ESPAsyncTCP.h"
#include "SyncClient.h"
@ -28,11 +28,11 @@ template<typename T> bool influxDBSend(const char * topic, T payload) {
}
char data[128];
sprintf(data, "%s,device=%s value=%s", topic, getSetting("hostname").c_str(), String(payload).c_str());
snprintf(data, sizeof(data), "%s,device=%s value=%s", topic, getSetting("hostname").c_str(), String(payload).c_str());
DEBUG_MSG("[INFLUXDB] Data: %s\n", data);
char request[256];
sprintf(request, "POST /write?db=%s&u=%s&p=%s HTTP/1.1\r\nHost: %s:%d\r\nContent-Length: %d\r\n\r\n%s",
snprintf(request, sizeof(request), "POST /write?db=%s&u=%s&p=%s HTTP/1.1\r\nHost: %s:%d\r\nContent-Length: %d\r\n\r\n%s",
getSetting("idbDatabase").c_str(), getSetting("idbUsername").c_str(), getSetting("idbPassword").c_str(),
getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt(),
strlen(data), data);


+ 6
- 6
code/espurna/led.ino View File

@ -44,16 +44,16 @@ void ledBlink(unsigned char id, unsigned long delayOff, unsigned long delayOn) {
}
}
#if WIFI_LED
#if LED_WIFI
void showStatus() {
if (wifiConnected()) {
if (WiFi.getMode() == WIFI_AP) {
ledBlink(WIFI_LED - 1, 2500, 2500);
ledBlink(LED_WIFI - 1, 2500, 2500);
} else {
ledBlink(WIFI_LED - 1, 4900, 100);
ledBlink(LED_WIFI - 1, 4900, 100);
}
} else {
ledBlink(WIFI_LED - 1, 500, 500);
ledBlink(LED_WIFI - 1, 500, 500);
}
}
#endif
@ -64,7 +64,7 @@ void ledMQTTCallback(unsigned int type, const char * topic, const char * payload
if (type == MQTT_CONNECT_EVENT) {
char buffer[strlen(MQTT_TOPIC_LED) + 3];
sprintf_P(buffer, PSTR("%s/+"), MQTT_TOPIC_LED);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_LED);
mqttSubscribe(buffer);
}
@ -138,7 +138,7 @@ void ledSetup() {
}
void ledLoop() {
#if WIFI_LED
#if LED_WIFI
if (ledAuto) showStatus();
#endif
}

+ 60
- 54
code/espurna/light.ino View File

@ -293,7 +293,7 @@ void _lightMQTTCallback(unsigned int type, const char * topic, const char * payl
}
char buffer[strlen(MQTT_TOPIC_CHANNEL) + 3];
sprintf_P(buffer, PSTR("%s/+"), MQTT_TOPIC_CHANNEL);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_CHANNEL);
mqttSubscribe(buffer);
}
@ -370,14 +370,14 @@ void lightMQTT() {
mqttSend(MQTT_TOPIC_COLOR, buffer);
// Brightness
sprintf_P(buffer, PSTR("%d"), _brightness);
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _brightness);
mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer);
}
// Channels
for (unsigned int i=0; i < _channels.size(); i++) {
sprintf_P(buffer, PSTR("%d"), _channels[i].value);
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _channels[i].value);
mqttSend(MQTT_TOPIC_CHANNEL, i, buffer);
}
@ -391,6 +391,7 @@ void lightUpdate(bool save, bool forward) {
if (forward) lightMQTT();
// Report color to WS clients (using current brightness setting)
#if WEB_SUPPORT
{
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
@ -410,6 +411,7 @@ void lightUpdate(bool save, bool forward) {
root.printTo(output);
wsSend(output.c_str());
}
#endif
// Delay saving to EEPROM 5 seconds to avoid wearing it out unnecessarily
if (save) colorTicker.once(LIGHT_SAVE_DELAY, _lightColorSave);
@ -461,66 +463,70 @@ void lightBrightness(unsigned int b) {
void _lightAPISetup() {
// API entry points (protected with apikey)
if (lightHasColor()) {
#if WEB_SUPPORT
apiRegister(MQTT_TOPIC_COLOR, MQTT_TOPIC_COLOR,
[](char * buffer, size_t len) {
_toRGB(buffer, len, false);
},
[](const char * payload) {
lightColor(payload);
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_BRIGHTNESS, MQTT_TOPIC_BRIGHTNESS,
[](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), _brightness);
},
[](const char * payload) {
lightBrightness(atoi(payload));
lightUpdate(true, true);
}
);
// API entry points (protected with apikey)
if (lightHasColor()) {
apiRegister(MQTT_TOPIC_KELVIN, MQTT_TOPIC_KELVIN,
[](char * buffer, size_t len) {},
[](const char * payload) {
_fromKelvin(atol(payload));
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_COLOR, MQTT_TOPIC_COLOR,
[](char * buffer, size_t len) {
_toRGB(buffer, len, false);
},
[](const char * payload) {
lightColor(payload);
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_BRIGHTNESS, MQTT_TOPIC_BRIGHTNESS,
[](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), _brightness);
},
[](const char * payload) {
lightBrightness(atoi(payload));
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_KELVIN, MQTT_TOPIC_KELVIN,
[](char * buffer, size_t len) {},
[](const char * payload) {
_fromKelvin(atol(payload));
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_MIRED, MQTT_TOPIC_MIRED,
[](char * buffer, size_t len) {},
[](const char * payload) {
_fromMireds(atol(payload));
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_MIRED, MQTT_TOPIC_MIRED,
[](char * buffer, size_t len) {},
[](const char * payload) {
_fromMireds(atol(payload));
lightUpdate(true, true);
}
);
}
}
for (unsigned int id=0; id<lightChannels(); id++) {
for (unsigned int id=0; id<lightChannels(); id++) {
char url[15];
snprintf_P(url, sizeof(url), PSTR("%s/%d"), MQTT_TOPIC_CHANNEL, id);
char url[15];
sprintf_P(url, PSTR("%s/%d"), MQTT_TOPIC_CHANNEL, id);
char key[10];
snprintf_P(key, sizeof(key), PSTR("%s%d"), MQTT_TOPIC_CHANNEL, id);
char key[10];
sprintf_P(key, PSTR("%s%d"), MQTT_TOPIC_CHANNEL, id);
apiRegister(url, key,
[id](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), lightChannel(id));
},
[id](const char * payload) {
lightChannel(id, atoi(payload));
lightUpdate(true, true);
}
);
apiRegister(url, key,
[id](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), lightChannel(id));
},
[id](const char * payload) {
lightChannel(id, atoi(payload));
lightUpdate(true, true);
}
);
}
}
#endif // WEB_SUPPORT
}


+ 1
- 1
code/espurna/mqtt.ino View File

@ -129,7 +129,7 @@ void mqttSend(const char * topic, const char * message) {
void mqttSend(const char * topic, unsigned int index, const char * message, bool force) {
char buffer[strlen(topic)+5];
sprintf_P(buffer, PSTR("%s/%d"), topic, index);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/%d"), topic, index);
mqttSend(buffer, message, force);
}


+ 1
- 1
code/espurna/nofuss.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_NOFUSS
#if NOFUSS_SUPPORT
#include "NoFUSSClient.h"


+ 7
- 3
code/espurna/ntp.ino View File

@ -39,7 +39,7 @@ String ntpDateTime() {
int month = value.substring(12, 14).toInt();
int year = value.substring(15, 19).toInt();
char buffer[20];
sprintf_P(buffer, PSTR("%04d/%02d/%02dT%02d:%02d:%02d"), year, month, day, hour, minute, second);
snprintf_P(buffer, sizeof(buffer), PSTR("%04d/%02d/%02dT%02d:%02d:%02d"), year, month, day, hour, minute, second);
return String(buffer);
}
@ -51,10 +51,14 @@ void ntpSetup() {
} else if (error == invalidAddress) {
DEBUG_MSG_P(PSTR("[NTP] Error: Invalid NTP server address\n"));
}
wsSend("{\"ntpStatus\": false}");
#if WEB_SUPPORT
wsSend_P(PSTR("{\"ntpStatus\": false}"));
#endif
} else {
DEBUG_MSG_P(PSTR("[NTP] Time: %s\n"), (char *) ntpDateTime().c_str());
wsSend("{\"ntpStatus\": true}");
#if WEB_SUPPORT
wsSend_P(PSTR("{\"ntpStatus\": true}"));
#endif
}
});
}


+ 7
- 3
code/espurna/ota.ino View File

@ -24,13 +24,17 @@ void otaSetup() {
ArduinoOTA.onStart([]() {
DEBUG_MSG_P(PSTR("[OTA] Start\n"));
wsSend("{\"message\": \"OTA update started\"}");
#if WEB_SUPPORT
wsSend_P(PSTR("{\"message\": \"OTA update started\"}"));
#endif
});
ArduinoOTA.onEnd([]() {
customReset(CUSTOM_RESET_OTA);
DEBUG_MSG_P(PSTR("\n[OTA] End\n"));
wsSend("{\"action\": \"reload\"}");
#if WEB_SUPPORT
wsSend_P(PSTR("{\"action\": \"reload\"}"));
#endif
delay(100);
});
@ -39,7 +43,7 @@ void otaSetup() {
});
ArduinoOTA.onError([](ota_error_t error) {
#if ENABLE_SERIAL_DEBUG || ENABLE_UDP_DEBUG
#if DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT
DEBUG_MSG_P(PSTR("\n[OTA] Error #%u: "), error);
if (error == OTA_AUTH_ERROR) DEBUG_MSG_P(PSTR("Auth Failed\n"));
else if (error == OTA_BEGIN_ERROR) DEBUG_MSG_P(PSTR("Begin Failed\n"));


+ 58
- 23
code/espurna/relay.ino View File

@ -14,7 +14,8 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
typedef struct {
unsigned char pin;
bool reverse;
unsigned char type;
unsigned char reset_pin;
unsigned char led;
unsigned long delay_on;
unsigned long delay_off;
@ -61,7 +62,22 @@ void relayProviderStatus(unsigned char id, bool status) {
#endif
#if RELAY_PROVIDER == RELAY_PROVIDER_RELAY
digitalWrite(_relays[id].pin, _relays[id].reverse ? !status : status);
if (_relays[id].type == RELAY_TYPE_NORMAL) {
digitalWrite(_relays[id].pin, status);
} else if (_relays[id].type == RELAY_TYPE_INVERSE) {
digitalWrite(_relays[id].pin, !status);
} else if (_relays[id].type == RELAY_TYPE_LATCHED) {
digitalWrite(_relays[id].pin, LOW);
digitalWrite(_relays[id].reset_pin, LOW);
if (status) {
digitalWrite(_relays[id].pin, HIGH);
} else {
digitalWrite(_relays[id].reset_pin, HIGH);
}
delay(RELAY_LATCHING_PULSE);
digitalWrite(_relays[id].pin, LOW);
digitalWrite(_relays[id].reset_pin, LOW);
}
#endif
}
@ -83,8 +99,13 @@ bool relayProviderStatus(unsigned char id) {
#endif
#if RELAY_PROVIDER == RELAY_PROVIDER_RELAY
bool status = (digitalRead(_relays[id].pin) == HIGH);
return _relays[id].reverse ? !status : status;
if (_relays[id].type == RELAY_TYPE_NORMAL) {
return (digitalRead(_relays[id].pin) == HIGH);
} else if (_relays[id].type == RELAY_TYPE_INVERSE) {
return (digitalRead(_relays[id].pin) == LOW);
} else if (_relays[id].type == RELAY_TYPE_LATCHED) {
return _relays[id].scheduledStatus;
}
#endif
}
@ -123,16 +144,18 @@ void relayPulseMode(unsigned int value, bool report) {
/*
if (report) {
char topic[strlen(MQTT_TOPIC_RELAY) + 10];
sprintf_P(topic, PSTR("%s/pulse"), MQTT_TOPIC_RELAY);
snprintf_P(topic, sizeof(topic), PSTR("%s/pulse"), MQTT_TOPIC_RELAY);
char value[2];
sprintf_P(value, PSTR("%d"), value);
snprintf_P(value, sizeof(value), PSTR("%d"), value);
mqttSend(topic, value);
}
*/
char message[20];
sprintf_P(message, PSTR("{\"relayPulseMode\": %d}"), value);
wsSend(message);
#if WEB_SUPPORT
char message[20];
snprintf_P(message, sizeof(message), PSTR("{\"relayPulseMode\": %d}"), value);
wsSend(message);
#endif
}
@ -293,16 +316,18 @@ unsigned char relayCount() {
// REST API
//------------------------------------------------------------------------------
#if WEB_SUPPORT
void relaySetupAPI() {
// API entry points (protected with apikey)
for (unsigned int relayID=0; relayID<relayCount(); relayID++) {
char url[15];
sprintf_P(url, PSTR("%s/%d"), MQTT_TOPIC_RELAY, relayID);
snprintf_P(url, sizeof(url), PSTR("%s/%d"), MQTT_TOPIC_RELAY, relayID);
char key[10];
sprintf_P(key, PSTR("%s%d"), MQTT_TOPIC_RELAY, relayID);
snprintf_P(key, sizeof(key), PSTR("%s%d"), MQTT_TOPIC_RELAY, relayID);
apiRegister(url, key,
[relayID](char * buffer, size_t len) {
@ -322,10 +347,14 @@ void relaySetupAPI() {
}
#endif // WEB_SUPPORT
//------------------------------------------------------------------------------
// WebSockets
//------------------------------------------------------------------------------
#if WEB_SUPPORT
void relayWS() {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
@ -338,6 +367,8 @@ void relayWS() {
wsSend(output.c_str());
}
#endif
//------------------------------------------------------------------------------
// MQTT
//------------------------------------------------------------------------------
@ -362,7 +393,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
#endif
char buffer[strlen(MQTT_TOPIC_RELAY) + 3];
sprintf_P(buffer, PSTR("%s/+"), MQTT_TOPIC_RELAY);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_RELAY);
mqttSubscribe(buffer);
}
@ -408,11 +439,11 @@ void relaySetupMQTT() {
// InfluxDB
//------------------------------------------------------------------------------
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
void relayInfluxDB(unsigned char id) {
if (id >= _relays.size()) return;
char buffer[10];
sprintf_P(buffer, PSTR("%s,id=%d"), MQTT_TOPIC_RELAY, id);
snprintf_P(buffer, sizeof(buffer), PSTR("%s,id=%d"), MQTT_TOPIC_RELAY, id);
influxDBSend(buffer, relayStatus(id) ? "1" : "0");
}
#endif
@ -428,23 +459,23 @@ void relaySetup() {
#ifdef DUMMY_RELAY_COUNT
for (unsigned char i=0; i < DUMMY_RELAY_COUNT; i++) {
_relays.push_back((relay_t) {0, 0});
_relays.push_back((relay_t) {0, RELAY_TYPE_NORMAL});
_relays[i].scheduled = false;
}
#else
#ifdef RELAY1_PIN
_relays.push_back((relay_t) { RELAY1_PIN, RELAY1_PIN_INVERSE, RELAY1_LED, RELAY1_DELAY_ON, RELAY1_DELAY_OFF });
_relays.push_back((relay_t) { RELAY1_PIN, RELAY1_TYPE, RELAY1_RESET_PIN, RELAY1_LED, RELAY1_DELAY_ON, RELAY1_DELAY_OFF });
#endif
#ifdef RELAY2_PIN
_relays.push_back((relay_t) { RELAY2_PIN, RELAY2_PIN_INVERSE, RELAY2_LED, RELAY2_DELAY_ON, RELAY2_DELAY_OFF });
_relays.push_back((relay_t) { RELAY2_PIN, RELAY2_TYPE, RELAY2_RESET_PIN, RELAY2_LED, RELAY2_DELAY_ON, RELAY2_DELAY_OFF });
#endif
#ifdef RELAY3_PIN
_relays.push_back((relay_t) { RELAY3_PIN, RELAY3_PIN_INVERSE, RELAY3_LED, RELAY3_DELAY_ON, RELAY3_DELAY_OFF });
_relays.push_back((relay_t) { RELAY3_PIN, RELAY3_TYPE, RELAY3_RESET_PIN, RELAY3_LED, RELAY3_DELAY_ON, RELAY3_DELAY_OFF });
#endif
#ifdef RELAY4_PIN
_relays.push_back((relay_t) { RELAY4_PIN, RELAY4_PIN_INVERSE, RELAY4_LED, RELAY4_DELAY_ON, RELAY4_DELAY_OFF });
_relays.push_back((relay_t) { RELAY4_PIN, RELAY4_TYPE, RELAY4_RESET_PIN, RELAY4_LED, RELAY4_DELAY_ON, RELAY4_DELAY_OFF });
#endif
#endif
@ -459,7 +490,9 @@ void relaySetup() {
if (relayMode == RELAY_MODE_TOOGLE) relayRetrieve(true);
relayLoop();
relaySetupAPI();
#if WEB_SUPPORT
relaySetupAPI();
#endif
relaySetupMQTT();
DEBUG_MSG_P(PSTR("[RELAY] Number of relays: %d\n"), _relays.size());
@ -496,14 +529,16 @@ void relayLoop(void) {
relayPulse(id);
relaySync(id);
relaySave();
relayWS();
#if WEB_SUPPORT
relayWS();
#endif
}
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
domoticzSendRelay(id);
#endif
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
relayInfluxDB(id);
#endif


+ 1
- 1
code/espurna/rf.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_RF
#if RF_SUPPORT
#include <RemoteReceiver.h>


+ 22
- 14
code/espurna/rfbridge.ino View File

@ -56,9 +56,11 @@ void _rfbLearn() {
Serial.flush();
Serial.println();
char wsb[100];
sprintf_P(wsb, PSTR("{\"action\": \"rfbLearn\", \"data\":{\"id\": %d, \"status\": %d}}"), _learnId, _learnStatus ? 1 : 0);
wsSend(wsb);
#if WEB_SUPPORT
char buffer[100];
snprintf_P(buffer, sizeof(buffer), PSTR("{\"action\": \"rfbLearn\", \"data\":{\"id\": %d, \"status\": %d}}"), _learnId, _learnStatus ? 1 : 0);
wsSend(buffer);
#endif
}
@ -99,7 +101,9 @@ void _rfbDecode() {
if (action == RF_CODE_LEARN_KO) {
_rfbAck();
DEBUG_MSG_P(PSTR("[RFBRIDGE] Learn timeout\n"));
wsSend("{\"action\": \"rfbTimeout\"}");
#if WEB_SUPPORT
wsSend_P(PSTR("{\"action\": \"rfbTimeout\"}"));
#endif
}
if (action == RF_CODE_LEARN_OK || action == RF_CODE_RFIN) {
@ -114,9 +118,11 @@ void _rfbDecode() {
rfbStore(_learnId, _learnStatus, buffer);
// Websocket update
char wsb[100];
sprintf_P(wsb, PSTR("{\"rfb\":[{\"id\": %d, \"status\": %d, \"data\": \"%s\"}]}"), _learnId, _learnStatus ? 1 : 0, buffer);
wsSend(wsb);
#if WEB_SUPPORT
char wsb[100];
snprintf_P(wsb, sizeof(wsb), PSTR("{\"rfb\":[{\"id\": %d, \"status\": %d, \"data\": \"%s\"}]}"), _learnId, _learnStatus ? 1 : 0, buffer);
wsSend(wsb);
#endif
}
@ -210,7 +216,7 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa
if (type == MQTT_CONNECT_EVENT) {
char buffer[strlen(MQTT_TOPIC_RFLEARN) + 3];
sprintf_P(buffer, PSTR("%s/+"), MQTT_TOPIC_RFLEARN);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_RFLEARN);
mqttSubscribe(buffer);
mqttSubscribe(MQTT_TOPIC_RFOUT);
}
@ -251,13 +257,13 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa
void rfbStore(unsigned char id, bool status, const char * code) {
DEBUG_MSG_P(PSTR("[RFBRIDGE] Storing %d-%s => '%s'\n"), id, status ? "ON" : "OFF", code);
char key[8] = {0};
sprintf_P(key, PSTR("rfb%d%s"), id, status ? "on" : "off");
snprintf_P(key, sizeof(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
setSetting(key, code);
}
String rfbRetrieve(unsigned char id, bool status) {
char key[8] = {0};
sprintf_P(key, PSTR("rfb%d%s"), id, status ? "on" : "off");
snprintf_P(key, sizeof(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
return getSetting(key);
}
@ -282,13 +288,15 @@ void rfbLearn(unsigned char id, bool status) {
void rfbForget(unsigned char id, bool status) {
char key[8] = {0};
sprintf_P(key, PSTR("rfb%d%s"), id, status ? "on" : "off");
snprintf_P(key, sizeof(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
delSetting(key);
// Websocket update
char wsb[100];
sprintf_P(wsb, PSTR("{\"rfb\":[{\"id\": %d, \"status\": %d, \"data\": \"\"}]}"), id, status ? 1 : 0);
wsSend(wsb);
#if WEB_SUPPORT
char wsb[100];
snprintf_P(wsb, sizeof(wsb), PSTR("{\"rfb\":[{\"id\": %d, \"status\": %d, \"data\": \"\"}]}"), id, status ? 1 : 0);
wsSend(wsb);
#endif
}


+ 2857
- 2854
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 155
- 163
code/espurna/web.ino View File

@ -6,17 +6,17 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if WEB_SUPPORT
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ESP8266mDNS.h>
#include <FS.h>
#include <Hash.h>
#include <AsyncJson.h>
#include <ArduinoJson.h>
#include <Ticker.h>
#include <vector>
#if EMBEDDED_WEB
#if WEB_EMBEDDED
#include "static/index.html.gz.h"
#endif
@ -25,16 +25,23 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include "static/server.key.h"
#endif
// -----------------------------------------------------------------------------
AsyncWebServer * _server;
AsyncWebSocket ws("/ws");
Ticker deferred;
char _last_modified[50];
Ticker _web_defer;
// -----------------------------------------------------------------------------
AsyncWebSocket _ws("/ws");
typedef struct {
IPAddress ip;
unsigned long timestamp = 0;
} ws_ticket_t;
ws_ticket_t _ticket[WS_BUFFER_SIZE];
// -----------------------------------------------------------------------------
typedef struct {
char * url;
char * key;
@ -42,34 +49,19 @@ typedef struct {
apiPutCallbackFunction putFn = NULL;
} web_api_t;
std::vector<web_api_t> _apis;
char _last_modified[50];
// -----------------------------------------------------------------------------
// WEBSOCKETS
// -----------------------------------------------------------------------------
bool wsConnected() {
return (ws.count() > 0);
}
bool wsSend(const char * payload) {
if (ws.count() > 0) {
ws.textAll(payload);
}
}
bool wsSend(uint32_t client_id, const char * payload) {
ws.text(client_id, payload);
}
void wsMQTTCallback(unsigned int type, const char * topic, const char * payload) {
void _wsMQTTCallback(unsigned int type, const char * topic, const char * payload) {
if (type == MQTT_CONNECT_EVENT) {
wsSend("{\"mqttStatus\": true}");
wsSend_P(PSTR("{\"mqttStatus\": true}"));
}
if (type == MQTT_DISCONNECT_EVENT) {
wsSend("{\"mqttStatus\": false}");
wsSend_P(PSTR("{\"mqttStatus\": false}"));
}
}
@ -81,7 +73,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
JsonObject& root = jsonBuffer.parseObject((char *) payload);
if (!root.success()) {
DEBUG_MSG_P(PSTR("[WEBSOCKET] Error parsing data\n"));
ws.text(client_id, "{\"message\": \"Error parsing data!\"}");
wsSend_P(client_id, PSTR("{\"message\": \"Error parsing data!\"}"));
return;
}
@ -116,7 +108,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
JsonObject& data = root["data"];
if (!data.containsKey("app") || (data["app"] != APP_NAME)) {
ws.text(client_id, "{\"message\": \"The file does not look like a valid configuration backup.\"}");
wsSend_P(client_id, PSTR("{\"message\": \"The file does not look like a valid configuration backup.\"}"));
return;
}
@ -132,14 +124,14 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
saveSettings();
ws.text(client_id, "{\"message\": \"Changes saved. You should reboot your board now.\"}");
wsSend_P(client_id, PSTR("{\"message\": \"Changes saved. You should reboot your board now.\"}"));
}
if (action.equals("reconnect")) {
// Let the HTTP request return and disconnect after 100ms
deferred.once_ms(100, wifiDisconnect);
_web_defer.once_ms(100, wifiDisconnect);
}
@ -203,21 +195,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
bool changed = false;
bool changedMQTT = false;
bool changedNTP = false;
bool apiEnabled = false;
bool dstEnabled = false;
bool mqttUseJson = false;
bool useColor = false;
bool useWhite = false;
bool useGamma = false;
#if ASYNC_TCP_SSL_ENABLED
bool mqttUseSSL = false;
#endif
#if ENABLE_FAUXMO
bool fauxmoEnabled = false;
#endif
#if ENABLE_DOMOTICZ
bool dczEnabled = false;
#endif
unsigned int network = 0;
unsigned int dczRelayIdx = 0;
String adminPass;
@ -230,7 +208,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
// Skip firmware filename
if (key.equals("filename")) continue;
#if ENABLE_HLW8012
#if HLW8012_SUPPORT
if (key == "powExpectedPower") {
hlw8012SetExpectedActivePower(value.toInt());
@ -256,7 +234,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
if (key.startsWith("pow")) continue;
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
if (key == "dczRelayIdx") {
if (dczRelayIdx >= relayCount()) continue;
@ -291,31 +269,14 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
}
if (key == "adminPass2") {
if (!value.equals(adminPass)) {
ws.text(client_id, "{\"message\": \"Passwords do not match!\"}");
wsSend_P(client_id, PSTR("{\"message\": \"Passwords do not match!\"}"));
return;
}
if (value.length() == 0) continue;
ws.text(client_id, "{\"action\": \"reload\"}");
wsSend_P(client_id, PSTR("{\"action\": \"reload\"}"));
key = String("adminPass");
}
// Checkboxes
if (key == "apiEnabled") { apiEnabled = true; continue; }
if (key == "ntpDST") { dstEnabled = true; continue; }
if (key == "mqttUseJson") { mqttUseJson = true; continue; }
if (key == "useColor") { useColor = true; continue; }
if (key == "useWhite") { useWhite = true; continue; }
if (key == "useGamma") { useGamma = true; continue; }
#if ASYNC_TCP_SSL_ENABLED
if (key == "mqttUseSSL") { mqttUseSSL = true; continue; }
#endif
#if ENABLE_FAUXMO
if (key == "fauxmoEnabled") { fauxmoEnabled = true; continue; }
#endif
#if ENABLE_DOMOTICZ
if (key == "dczEnabled") { dczEnabled = true; continue; }
#endif
if (key == "ssid") {
key = key + String(network);
}
@ -348,23 +309,6 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
if (webMode == WEB_MODE_NORMAL) {
// Checkboxes
setBoolSetting("apiEnabled", apiEnabled, ENABLE_API);
setBoolSetting("ntpDST", dstEnabled, NTP_DAY_LIGHT);
setBoolSetting("mqttUseJson", mqttUseJson, MQTT_USE_JSON);
setBoolSetting("useColor", useColor, LIGHT_USE_COLOR);
setBoolSetting("useWhite", useWhite, LIGHT_USE_WHITE);
setBoolSetting("useGamma", useGamma, LIGHT_USE_GAMMA);
#if ASYNC_TCP_SSL_ENABLED
setBoolSetting("mqttUseSSL", mqttUseSSL, MQTT_USE_SSL);
#endif
#if ENABLE_FAUXMO
setBoolSetting("fauxmoEnabled", fauxmoEnabled, FAUXMO_ENABLED);
#endif
#if ENABLE_DOMOTICZ
setBoolSetting("dczEnabled", dczEnabled, DOMOTICZ_ENABLED);
#endif
// Clean wifi networks
int i = 0;
while (i < network) {
@ -400,22 +344,22 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
saveSettings();
wifiConfigure();
otaConfigure();
#if ENABLE_FAUXMO
fauxmoConfigure();
#if ALEXA_SUPPORT
alexaConfigure();
#endif
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
influxDBConfigure();
#endif
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
domoticzConfigure();
#endif
mqttConfigure();
#if ENABLE_RF
#if RF_SUPPORT
rfBuildCodes();
#endif
#if ENABLE_EMON
#if EMON_SUPPORT
setCurrentRatio(getSetting("emonRatio").toFloat());
#endif
@ -432,9 +376,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
}
if (changed) {
ws.text(client_id, "{\"message\": \"Changes saved\"}");
wsSend_P(client_id, PSTR("{\"message\": \"Changes saved\"}"));
} else {
ws.text(client_id, "{\"message\": \"No changes detected\"}");
wsSend_P(client_id, PSTR("{\"message\": \"No changes detected\"}"));
}
}
@ -444,13 +388,13 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
void _wsStart(uint32_t client_id) {
char chipid[6];
sprintf_P(chipid, PSTR("%06X"), ESP.getChipId());
snprintf_P(chipid, sizeof(chipid), PSTR("%06X"), ESP.getChipId());
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
bool changePassword = false;
#if FORCE_CHANGE_PASS == 1
#if WEB_FORCE_PASS_CHANGE
String adminPass = getSetting("adminPass", ADMIN_PASS);
if (adminPass.equals(ADMIN_PASS)) changePassword = true;
#endif
@ -526,14 +470,14 @@ void _wsStart(uint32_t client_id) {
root["btnDelay"] = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt();
root["webPort"] = getSetting("webPort", WEBSERVER_PORT).toInt();
root["webPort"] = getSetting("webPort", WEB_PORT).toInt();
root["apiEnabled"] = getSetting("apiEnabled", ENABLE_API).toInt() == 1;
root["apiEnabled"] = getSetting("apiEnabled", API_ENABLED).toInt() == 1;
root["apiKey"] = getSetting("apiKey");
root["tmpUnits"] = getSetting("tmpUnits", TMP_UNITS).toInt();
#if ENABLE_DOMOTICZ
#if DOMOTICZ_SUPPORT
root["dczVisible"] = 1;
root["dczEnabled"] = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
@ -545,26 +489,26 @@ void _wsStart(uint32_t client_id) {
dczRelayIdx.add(domoticzIdx(i));
}
#if ENABLE_DHT
#if DHT_SUPPORT
root["dczTmpIdx"] = getSetting("dczTmpIdx").toInt();
root["dczHumIdx"] = getSetting("dczHumIdx").toInt();
#endif
#if ENABLE_DS18B20
#if DS18B20_SUPPORT
root["dczTmpIdx"] = getSetting("dczTmpIdx").toInt();
#endif
#if ENABLE_EMON
#if EMON_SUPPORT
root["dczPowIdx"] = getSetting("dczPowIdx").toInt();
root["dczEnergyIdx"] = getSetting("dczEnergyIdx").toInt();
root["dczCurrentIdx"] = getSetting("dczCurrentIdx").toInt();
#endif
#if ENABLE_ANALOG
#if ANALOG_SUPPORT
root["dczAnaIdx"] = getSetting("dczAnaIdx").toInt();
#endif
#if ENABLE_HLW8012
#if HLW8012_SUPPORT
root["dczPowIdx"] = getSetting("dczPowIdx").toInt();
root["dczEnergyIdx"] = getSetting("dczEnergyIdx").toInt();
root["dczVoltIdx"] = getSetting("dczVoltIdx").toInt();
@ -573,7 +517,7 @@ void _wsStart(uint32_t client_id) {
#endif
#if ENABLE_INFLUXDB
#if INFLUXDB_SUPPORT
root["idbVisible"] = 1;
root["idbHost"] = getSetting("idbHost");
root["idbPort"] = getSetting("idbPort", INFLUXDB_PORT).toInt();
@ -582,29 +526,29 @@ void _wsStart(uint32_t client_id) {
root["idbPassword"] = getSetting("idbPassword");
#endif
#if ENABLE_FAUXMO
root["fauxmoVisible"] = 1;
root["fauxmoEnabled"] = getSetting("fauxmoEnabled", FAUXMO_ENABLED).toInt() == 1;
#if ALEXA_SUPPORT
root["alexaVisible"] = 1;
root["alexaEnabled"] = getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1;
#endif
#if ENABLE_DS18B20
#if DS18B20_SUPPORT
root["dsVisible"] = 1;
root["dsTmp"] = getDSTemperatureStr();
#endif
#if ENABLE_DHT
#if DHT_SUPPORT
root["dhtVisible"] = 1;
root["dhtTmp"] = getDHTTemperature();
root["dhtHum"] = getDHTHumidity();
#endif
#if ENABLE_RF
#if RF_SUPPORT
root["rfVisible"] = 1;
root["rfChannel"] = getSetting("rfChannel", RF_CHANNEL);
root["rfDevice"] = getSetting("rfDevice", RF_DEVICE);
#endif
#if ENABLE_EMON
#if EMON_SUPPORT
root["emonVisible"] = 1;
root["emonApparentPower"] = getApparentPower();
root["emonCurrent"] = getCurrent();
@ -612,12 +556,12 @@ void _wsStart(uint32_t client_id) {
root["emonRatio"] = getSetting("emonRatio", EMON_CURRENT_RATIO);
#endif
#if ENABLE_ANALOG
#if ANALOG_SUPPORT
root["analogVisible"] = 1;
root["analogValue"] = getAnalog();
#endif
#if ENABLE_HLW8012
#if HLW8012_SUPPORT
root["powVisible"] = 1;
root["powActivePower"] = getActivePower();
root["powApparentPower"] = getApparentPower();
@ -658,7 +602,7 @@ void _wsStart(uint32_t client_id) {
String output;
root.printTo(output);
ws.text(client_id, (char *) output.c_str());
wsSend(client_id, (char *) output.c_str());
}
@ -674,7 +618,7 @@ bool _wsAuth(AsyncWebSocketClient * client) {
if (index == WS_BUFFER_SIZE) {
DEBUG_MSG_P(PSTR("[WEBSOCKET] Validation check failed\n"));
ws.text(client->id(), "{\"message\": \"Session expired, please reload page...\"}");
wsSend_P(client->id(), PSTR("{\"message\": \"Session expired, please reload page...\"}"));
return false;
}
@ -723,24 +667,50 @@ void _wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTy
}
// -----------------------------------------------------------------------------
// WEBSERVER
// -----------------------------------------------------------------------------
void webLogRequest(AsyncWebServerRequest *request) {
DEBUG_MSG_P(PSTR("[WEBSERVER] Request: %s %s\n"), request->methodToString(), request->url().c_str());
bool wsConnected() {
return (_ws.count() > 0);
}
bool _authenticate(AsyncWebServerRequest *request) {
String password = getSetting("adminPass", ADMIN_PASS);
char httpPassword[password.length() + 1];
password.toCharArray(httpPassword, password.length() + 1);
return request->authenticate(HTTP_USERNAME, httpPassword);
void wsSend(const char * payload) {
if (_ws.count() > 0) {
_ws.textAll(payload);
}
}
void wsSend_P(PGM_P payload) {
if (_ws.count() > 0) {
char buffer[strlen_P(payload)];
strcpy_P(buffer, payload);
_ws.textAll(buffer);
}
}
void wsSend(uint32_t client_id, const char * payload) {
_ws.text(client_id, payload);
}
void wsSend_P(uint32_t client_id, PGM_P payload) {
char buffer[strlen_P(payload)];
strcpy_P(buffer, payload);
_ws.text(client_id, buffer);
}
void wsSetup() {
_ws.onEvent(_wsEvent);
mqttRegister(_wsMQTTCallback);
_server->addHandler(&_ws);
_server->on("/auth", HTTP_GET, _onAuth);
}
// -----------------------------------------------------------------------------
// API
// -----------------------------------------------------------------------------
bool _authAPI(AsyncWebServerRequest *request) {
if (getSetting("apiEnabled", ENABLE_API).toInt() == 0) {
if (getSetting("apiEnabled", API_ENABLED).toInt() == 0) {
DEBUG_MSG_P(PSTR("[WEBSERVER] HTTP API is not enabled\n"));
request->send(403);
return false;
@ -776,7 +746,7 @@ ArRequestHandlerFunction _bindAPI(unsigned int apiID) {
return [apiID](AsyncWebServerRequest *request) {
webLogRequest(request);
_webLog(request);
if (!_authAPI(request)) return;
web_api_t api = _apis[apiID];
@ -805,7 +775,7 @@ ArRequestHandlerFunction _bindAPI(unsigned int apiID) {
// Format response according to the Accept header
if (_asJson(request)) {
char buffer[64];
sprintf_P(buffer, PSTR("{ \"%s\": %s }"), api.key, p);
snprintf_P(buffer, sizeof(buffer), PSTR("{ \"%s\": %s }"), api.key, p);
request->send(200, "application/json", buffer);
} else {
request->send(200, "text/plain", p);
@ -815,28 +785,9 @@ ArRequestHandlerFunction _bindAPI(unsigned int apiID) {
}
void apiRegister(const char * url, const char * key, apiGetCallbackFunction getFn, apiPutCallbackFunction putFn) {
// Store it
web_api_t api;
char buffer[40];
snprintf_P(buffer, 39, PSTR("/api/%s"), url);
api.url = strdup(buffer);
api.key = strdup(key);
api.getFn = getFn;
api.putFn = putFn;
_apis.push_back(api);
// Bind call
unsigned int methods = HTTP_GET;
if (putFn != NULL) methods += HTTP_PUT;
_server->on(buffer, methods, _bindAPI(_apis.size() - 1));
}
void _onAPIs(AsyncWebServerRequest *request) {
webLogRequest(request);
_webLog(request);
if (!_authAPI(request)) return;
@ -863,7 +814,7 @@ void _onAPIs(AsyncWebServerRequest *request) {
void _onRPC(AsyncWebServerRequest *request) {
webLogRequest(request);
_webLog(request);
if (!_authAPI(request)) return;
@ -878,7 +829,7 @@ void _onRPC(AsyncWebServerRequest *request) {
if (action.equals("reset")) {
response = 200;
deferred.once_ms(100, []() {
_web_defer.once_ms(100, []() {
customReset(CUSTOM_RESET_RPC);
ESP.restart();
});
@ -890,9 +841,50 @@ void _onRPC(AsyncWebServerRequest *request) {
}
// -----------------------------------------------------------------------------
void apiRegister(const char * url, const char * key, apiGetCallbackFunction getFn, apiPutCallbackFunction putFn) {
// Store it
web_api_t api;
char buffer[40];
snprintf_P(buffer, sizeof(buffer), PSTR("/api/%s"), url);
api.url = strdup(buffer);
api.key = strdup(key);
api.getFn = getFn;
api.putFn = putFn;
_apis.push_back(api);
// Bind call
unsigned int methods = HTTP_GET;
if (putFn != NULL) methods += HTTP_PUT;
_server->on(buffer, methods, _bindAPI(_apis.size() - 1));
}
void apiSetup() {
_server->on("/apis", HTTP_GET, _onAPIs);
_server->on("/rpc", HTTP_GET, _onRPC);
}
// -----------------------------------------------------------------------------
// WEBSERVER
// -----------------------------------------------------------------------------
void _webLog(AsyncWebServerRequest *request) {
DEBUG_MSG_P(PSTR("[WEBSERVER] Request: %s %s\n"), request->methodToString(), request->url().c_str());
}
bool _authenticate(AsyncWebServerRequest *request) {
String password = getSetting("adminPass", ADMIN_PASS);
char httpPassword[password.length() + 1];
password.toCharArray(httpPassword, password.length() + 1);
return request->authenticate(WEB_USERNAME, httpPassword);
}
void _onAuth(AsyncWebServerRequest *request) {
webLogRequest(request);
_webLog(request);
if (!_authenticate(request)) return request->requestAuthentication();
IPAddress ip = request->client()->remoteIP();
@ -915,7 +907,7 @@ void _onAuth(AsyncWebServerRequest *request) {
void _onGetConfig(AsyncWebServerRequest *request) {
webLogRequest(request);
_webLog(request);
if (!_authenticate(request)) return request->requestAuthentication();
AsyncJsonResponse * response = new AsyncJsonResponse();
@ -932,17 +924,17 @@ void _onGetConfig(AsyncWebServerRequest *request) {
}
char buffer[100];
sprintf_P(buffer, PSTR("attachment; filename=\"%s-backup.json\""), (char *) getSetting("hostname").c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("attachment; filename=\"%s-backup.json\""), (char *) getSetting("hostname").c_str());
response->addHeader("Content-Disposition", buffer);
response->setLength();
request->send(response);
}
#if EMBEDDED_WEB
#if WEB_EMBEDDED
void _onHome(AsyncWebServerRequest *request) {
webLogRequest(request);
_webLog(request);
if (request->header("If-Modified-Since").equals(_last_modified)) {
@ -1043,7 +1035,7 @@ void _onUpgrade(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", Update.hasError() ? "FAIL" : "OK");
response->addHeader("Connection", "close");
if (!Update.hasError()) {
deferred.once_ms(100, []() {
_web_defer.once_ms(100, []() {
customReset(CUSTOM_RESET_UPGRADE);
ESP.restart();
});
@ -1081,8 +1073,13 @@ void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t inde
}
}
// -----------------------------------------------------------------------------
void webSetup() {
// Cache the Last-Modifier header value
snprintf_P(_last_modified, sizeof(_last_modified), PSTR("%s %s GMT"), __DATE__, __TIME__);
// Create server
#if ASYNC_TCP_SSL_ENABLED & WEB_USE_SSL
unsigned int port = 443;
@ -1092,34 +1089,27 @@ void webSetup() {
_server = new AsyncWebServer(port);
// Setup websocket
ws.onEvent(_wsEvent);
mqttRegister(wsMQTTCallback);
// Cache the Last-Modifier header value
sprintf_P(_last_modified, PSTR("%s %s GMT"), __DATE__, __TIME__);
wsSetup();
// Setup webserver
_server->addHandler(&ws);
// API setup
apiSetup();
// Rewrites
_server->rewrite("/", "/index.html");
// Serve home (basic authentication protection)
#if EMBEDDED_WEB
#if WEB_EMBEDDED
_server->on("/index.html", HTTP_GET, _onHome);
#endif
_server->on("/config", HTTP_GET, _onGetConfig);
_server->on("/auth", HTTP_GET, _onAuth);
_server->on("/apis", HTTP_GET, _onAPIs);
_server->on("/rpc", HTTP_GET, _onRPC);
_server->on("/upgrade", HTTP_POST, _onUpgrade, _onUpgradeData);
// Serve static files
#if ENABLE_SPIFFS
#if SPIFFS_SUPPORT
_server->serveStatic("/", SPIFFS, "/")
.setLastModified(_last_modified)
.setFilter([](AsyncWebServerRequest *request) -> bool {
webLogRequest(request);
_webLog(request);
return true;
});
#endif
@ -1139,3 +1129,5 @@ void webSetup() {
DEBUG_MSG_P(PSTR("[WEBSERVER] Webserver running on port %d\n"), port);
}
#endif // WEB_SUPPORT

+ 51
- 7
code/espurna/wifi.ino View File

@ -7,6 +7,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#include "JustWifi.h"
#include <ESP8266mDNS.h>
// -----------------------------------------------------------------------------
// WIFI
@ -27,7 +28,7 @@ String getNetwork() {
}
void wifiDisconnect() {
#if ENABLE_HLW8012
#if HLW8012_SUPPORT
hlw8012Enable(false);
#endif
jw.disconnect();
@ -53,7 +54,7 @@ void wifiConfigure() {
jw.setSoftAP(getSetting("hostname").c_str(), getSetting("adminPass", ADMIN_PASS).c_str());
jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT);
jw.setReconnectTimeout(WIFI_RECONNECT_INTERVAL);
jw.setAPMode(AP_MODE);
jw.setAPMode(WIFI_AP_MODE);
jw.cleanNetworks();
int i;
@ -115,15 +116,58 @@ void wifiStatus() {
}
// Inject hardcoded networks
void wifiInject() {
#ifdef WIFI1_SSID
if (getSetting("ssid", 0, "").length() == 0) setSetting("ssid", 0, WIFI1_SSID);
#endif
#ifdef WIFI1_PASS
if (getSetting("pass", 0, "").length() == 0) setSetting("pass", 0, WIFI1_PASS);
#endif
#ifdef WIFI1_IP
if (getSetting("ip", 0, "").length() == 0) setSetting("ip", 0, WIFI1_IP);
#endif
#ifdef WIFI1_GW
if (getSetting("gw", 0, "").length() == 0) setSetting("gw", 0, WIFI1_GW);
#endif
#ifdef WIFI1_MASK
if (getSetting("mask", 0, "").length() == 0) setSetting("mask", 0, WIFI1_MASK);
#endif
#ifdef WIFI1_DNS
if (getSetting("dns", 0, "").length() == 0) setSetting("dns", 0, WIFI1_DNS);
#endif
#ifdef WIFI2_SSID
if (getSetting("ssid", 1, "").length() == 0) setSetting("ssid", 1, WIFI2_SSID);
#endif
#ifdef WIFI2_PASS
if (getSetting("pass", 1, "").length() == 0) setSetting("pass", 1, WIFI2_PASS);
#endif
#ifdef WIFI2_IP
if (getSetting("ip", 1, "").length() == 0) setSetting("ip", 1, WIFI2_IP);
#endif
#ifdef WIFI2_GW
if (getSetting("gw", 1, "").length() == 0) setSetting("gw", 1, WIFI2_GW);
#endif
#ifdef WIFI2_MASK
if (getSetting("mask", 1, "").length() == 0) setSetting("mask", 1, WIFI2_MASK);
#endif
#ifdef WIFI2_DNS
if (getSetting("dns", 1, "").length() == 0) setSetting("dns", 1, WIFI2_DNS);
#endif
}
void wifiSetup() {
WiFi.persistent(false);
wifiInject();
wifiConfigure();
// Message callbacks
jw.onMessage([](justwifi_messages_t code, char * parameter) {
#if ENABLE_SERIAL_DEBUG || ENABLE_UDP_DEBUG
#if DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT
if (code == MESSAGE_SCANNING) {
DEBUG_MSG_P(PSTR("[WIFI] Scanning\n"));
@ -180,10 +224,10 @@ void wifiSetup() {
#endif
// Configure mDNS
#if ENABLE_MDNS
#if MDNS_SUPPORT
if (code == MESSAGE_CONNECTED || code == MESSAGE_ACCESSPOINT_CREATED) {
if (MDNS.begin(WiFi.getMode() == WIFI_AP ? APP_NAME : (char *) WiFi.hostname().c_str())) {
MDNS.addService("http", "tcp", getSetting("webPort", WEBSERVER_PORT).toInt());
MDNS.addService("http", "tcp", getSetting("webPort", WEB_PORT).toInt());
DEBUG_MSG_P(PSTR("[MDNS] OK\n"));
} else {
DEBUG_MSG_P(PSTR("[MDNS] FAIL\n"));
@ -197,7 +241,7 @@ void wifiSetup() {
}
// Manage POW
#if ENABLE_HLW8012
#if HLW8012_SUPPORT
if (code == MESSAGE_CONNECTED) {
hlw8012Enable(true);
}


+ 27
- 0
code/html/custom.js View File

@ -33,18 +33,45 @@ function validateForm(form) {
}
function valueSet(data, name, value) {
for (var i in data) {
if (data[i]['name'] == name) {
data[i]['value'] = value;
return;
}
}
data.push({'name': name, 'value': value});
}
function doUpdate() {
var form = $("#formSave");
if (validateForm(form)) {
// Get data
var data = form.serializeArray();
// Post-process
delete(data['filename']);
$("input[type='checkbox']").each(function() {
var name = $(this).attr("name");
if (name) {
valueSet(data, name, $(this).is(':checked') ? 1 : 0);
}
});
websock.send(JSON.stringify({'config': data}));
$(".powExpected").val(0);
$("input[name='powExpectedReset']")
.prop("checked", false)
.iphoneStyle("refresh");
}
return false;
}
function doUpgrade() {


+ 4
- 4
code/html/index.html View File

@ -372,9 +372,9 @@
<div class="pure-u-1 pure-u-md-3-4 hint">Use gamma correction for RGB channels.<br />Will only work if "use colorpicker" above is also ON.</div>
</div>
<div class="pure-g module module-fauxmo">
<div class="pure-u-1 pure-u-sm-1-4"><label for="fauxmoEnabled">Alexa integration</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="fauxmoEnabled" tabindex="11" /></div>
<div class="pure-g module module-alexa">
<div class="pure-u-1 pure-u-sm-1-4"><label for="alexaEnabled">Alexa integration</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="alexaEnabled" tabindex="11" /></div>
</div>
<div class="pure-g module module-ds module-dht">
@ -542,7 +542,7 @@
</div>
</div>
<div class="pure-g module module-fauxmo">
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-4"><label for="mqttUseJson">Use JSON payload</label></div>
<div class="pure-u-1 pure-u-sm-3-4"><input type="checkbox" name="mqttUseJson" tabindex="26" /></div>
<div class="pure-u-1 pure-u-md-1-4">&nbsp;</div>


+ 128
- 2
code/platformio.ini View File

@ -21,9 +21,9 @@ lib_deps =
OneWire
DallasTemperature
Brzo I2C
https://bitbucket.org/xoseperez/justwifi.git#1.1.3
https://bitbucket.org/xoseperez/justwifi.git#1.1.4
https://bitbucket.org/xoseperez/hlw8012.git#1.0.1
https://bitbucket.org/xoseperez/fauxmoesp.git#2.1.0
https://bitbucket.org/xoseperez/fauxmoesp.git#2.1.1
https://bitbucket.org/xoseperez/nofuss.git#0.2.2
https://bitbucket.org/xoseperez/emonliteesp.git#0.1.2
https://bitbucket.org/xoseperez/debounceevent.git#2.0.1
@ -40,6 +40,8 @@ board = d1_mini
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DWEMOS_D1_MINI_RELAYSHIELD -DDEBUG_FAUXMO=Serial -DNOWSAUTH
upload_speed = 460800
monitor_baud = 115200
[env:wemos-d1mini-relayshield-ssl]
platform = espressif8266_stage
@ -59,6 +61,7 @@ build_flags = ${common.build_flags} -DWEMOS_D1_MINI_RELAYSHIELD -DDEBUG_FAUXMO=S
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:nodemcu-lolin]
platform = espressif8266
@ -67,6 +70,8 @@ board = nodemcuv2
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DNODEMCU_LOLIN -DDEBUG_FAUXMO=Serial -DNOWSAUTH
upload_speed = 460800
monitor_baud = 115200
[env:nodemcu-lolin-ssl]
platform = espressif8266_stage
@ -86,6 +91,7 @@ build_flags = ${common.build_flags} -DNODEMCU_LOLIN -DDEBUG_FAUXMO=Serial -DNOWS
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
# ------------------------------------------------------------------------------
@ -96,6 +102,8 @@ board = esp12e
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_H
upload_speed = 460800
monitor_baud = 115200
[env:tinkerman-espurna-h-ota]
platform = espressif8266
@ -107,6 +115,7 @@ build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_H
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
# ------------------------------------------------------------------------------
@ -118,6 +127,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_BASIC
monitor_baud = 115200
[env:itead-sonoff-basic-ota]
platform = espressif8266
@ -130,6 +140,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_BASIC
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-basic-dht22]
platform = espressif8266
@ -139,6 +150,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_BASIC -DENABLE_DHT=1
monitor_baud = 115200
[env:itead-sonoff-basic-ds18b20]
platform = espressif8266
@ -148,6 +160,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_BASIC -DENABLE_DS18B20=1
monitor_baud = 115200
[env:itead-sonoff-rf]
platform = espressif8266
@ -157,6 +170,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_RF
monitor_baud = 115200
[env:itead-sonoff-rf-ota]
platform = espressif8266
@ -169,6 +183,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_RF
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-pow]
platform = espressif8266
@ -178,6 +193,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_POW
monitor_baud = 115200
[env:itead-sonoff-pow-ota]
platform = espressif8266
@ -190,6 +206,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_POW
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-dual]
platform = espressif8266
@ -220,6 +237,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_4CH
monitor_baud = 115200
[env:itead-sonoff-4ch-ota]
platform = espressif8266
@ -232,6 +250,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_4CH
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-4ch-pro]
platform = espressif8266
@ -241,6 +260,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_4CH_PRO
monitor_baud = 115200
[env:itead-sonoff-4ch-pro-ota]
platform = espressif8266
@ -253,6 +273,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_4CH_PRO
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-touch]
platform = espressif8266
@ -262,6 +283,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_TOUCH
monitor_baud = 115200
[env:itead-sonoff-touch-ota]
platform = espressif8266
@ -274,6 +296,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_TOUCH
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-b1]
platform = espressif8266
@ -283,6 +306,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_B1
monitor_baud = 115200
[env:itead-sonoff-b1-ota]
platform = espressif8266
@ -295,6 +319,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_B1
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-t1-1ch]
platform = espressif8266
@ -304,6 +329,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_T1_1CH
monitor_baud = 115200
[env:itead-sonoff-t1-1ch-ota]
platform = espressif8266
@ -316,6 +342,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_T1_1CH
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-t1-2ch]
platform = espressif8266
@ -325,6 +352,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_T1_2CH
monitor_baud = 115200
[env:itead-sonoff-t1-2ch-ota]
platform = espressif8266
@ -337,6 +365,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_T1_2CH
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-t1-3ch]
platform = espressif8266
@ -346,6 +375,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_T1_3CH
monitor_baud = 115200
[env:itead-sonoff-t1-3ch-ota]
platform = espressif8266
@ -358,6 +388,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_T1_3CH
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-led]
platform = espressif8266
@ -367,6 +398,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_LED
monitor_baud = 115200
[env:itead-sonoff-led-ota]
platform = espressif8266
@ -379,6 +411,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_LED
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-rfbridge]
platform = espressif8266
@ -388,6 +421,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_RFBRIDGE
monitor_baud = 19200
[env:itead-sonoff-rfbridge-ota]
platform = espressif8266
@ -400,6 +434,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_RFBRIDGE
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=Algernon1 --port 8266
monitor_baud = 19200
# ------------------------------------------------------------------------------
@ -411,6 +446,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SLAMPHER
monitor_baud = 115200
[env:itead-slampher-ota]
platform = espressif8266
@ -423,6 +459,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_SLAMPHER
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-s20]
platform = espressif8266
@ -432,6 +469,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_S20
monitor_baud = 115200
[env:itead-s20-ota]
platform = espressif8266
@ -444,6 +482,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_S20
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-1ch-inching]
platform = espressif8266
@ -453,6 +492,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_1CH_INCHING
monitor_baud = 115200
[env:itead-1ch-inching-ota]
platform = espressif8266
@ -465,6 +505,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_1CH_INCHING
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-motor]
platform = espressif8266
@ -474,6 +515,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_MOTOR
monitor_baud = 115200
[env:itead-motor-ota]
platform = espressif8266
@ -486,6 +528,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_MOTOR
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
# ------------------------------------------------------------------------------
@ -496,6 +539,7 @@ board = esp12e
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DELECTRODRAGON_WIFI_IOT -DENABLE_DHT=1
monitor_baud = 115200
[env:electrodragon-wifi-iot-ota]
platform = espressif8266
@ -507,6 +551,7 @@ build_flags = ${common.build_flags} -DELECTRODRAGON_WIFI_IOT -DENABLE_DHT=1
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:workchoice-ecoplug]
platform = espressif8266
@ -516,6 +561,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DWORKCHOICE_ECOPLUG
monitor_baud = 115200
[env:workchoice-ecoplug-ota]
platform = espressif8266
@ -528,6 +574,7 @@ build_flags = ${common.build_flags_1m} -DWORKCHOICE_ECOPLUG
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:jangoe-wifi-relay]
platform = espressif8266
@ -536,6 +583,7 @@ board = esp12e
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DJANGOE_WIFI_RELAY_NC
monitor_baud = 115200
[env:jangoe-wifi-relay-ota]
platform = espressif8266
@ -547,6 +595,7 @@ build_flags = ${common.build_flags} -DJANGOE_WIFI_RELAY_NC
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:openenergymonitor-mqtt-relay]
platform = espressif8266
@ -555,6 +604,7 @@ board = esp_wroom_02
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DOPENENERGYMONITOR_MQTT_RELAY -DENABLE_DS18B20=1
monitor_baud = 115200
[env:openenergymonitor-mqtt-relay-ota]
platform = espressif8266
@ -566,6 +616,7 @@ build_flags = ${common.build_flags} -DOPENENERGYMONITOR_MQTT_RELAY -DENABLE_DS18
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:jorgegarcia-wifi-relays]
platform = espressif8266
@ -574,6 +625,7 @@ board = esp01_1m
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DJORGEGARCIA_WIFI_RELAYS
monitor_baud = 115200
[env:jorgegarcia-wifi-relays-ota]
platform = espressif8266
@ -585,6 +637,7 @@ build_flags = ${common.build_flags_1m} -DJORGEGARCIA_WIFI_RELAYS
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:aithinker-ai-light]
platform = espressif8266
@ -594,6 +647,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DAITHINKER_AI_LIGHT
monitor_baud = 115200
[env:aithinker-ai-light-ota]
platform = espressif8266
@ -606,6 +660,7 @@ build_flags = ${common.build_flags_1m} -DAITHINKER_AI_LIGHT
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:magichome-led-controller]
platform = espressif8266
@ -614,6 +669,7 @@ board = esp01_1m
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DMAGICHOME_LED_CONTROLLER
monitor_baud = 115200
[env:magichome-led-controller-ota]
platform = espressif8266
@ -625,6 +681,7 @@ build_flags = ${common.build_flags_1m} -DMAGICHOME_LED_CONTROLLER
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:huacanxing-h801]
platform = espressif8266
@ -634,6 +691,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = -g -Wl,-Tesp8266.flash.1m0.ld -DHUACANXING_H801 -DDEBUG_PORT=Serial1
monitor_baud = 115200
[env:huacanxing-h801-ota]
platform = espressif8266
@ -646,6 +704,7 @@ build_flags = -g -Wl,-Tesp8266.flash.1m0.ld -DHUACANXING_H801 -DDEBUG_PORT=Seria
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-bnsz01]
platform = espressif8266
@ -655,6 +714,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_BN_SZ01
monitor_baud = 115200
[env:itead-bnsz01-ota]
platform = espressif8266
@ -667,6 +727,7 @@ build_flags = ${common.build_flags_1m} -DITEAD_BN_SZ01
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:wion-50055]
platform = espressif8266
@ -676,6 +737,7 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DWION_50055
monitor_baud = 115200
[env:wion-50055-ota]
platform = espressif8266
@ -688,3 +750,67 @@ build_flags = ${common.build_flags_1m} -DWION_50055
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:exs-wifi-relay-v31]
platform = espressif8266
framework = arduino
board = esp07
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DEXS_WIFI_RELAY_V31
monitor_baud = 115200
[env:exs-wifi-relay-v31-ota]
platform = espressif8266
framework = arduino
board = esp07
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DEXS_WIFI_RELAY_V31
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
# ------------------------------------------------------------------------------
# GENERIC OTA ENVIRONMENTS
# ------------------------------------------------------------------------------
[env:esp8285-1m-ota]
platform = espressif8266
framework = arduino
board = esp8285
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -D${env.BOARD}
upload_speed = 115200
upload_port = "${env.IP}"
upload_flags = --auth=${env.AUTH} --port 8266
[env:esp8266-1m-ota]
platform = espressif8266
framework = arduino
board = esp01_1m
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -D${env.BOARD}
upload_speed = 115200
upload_port = "${env.IP}"
upload_flags = --auth=${env.AUTH} --port 8266
[env:esp8266-4m-ota]
platform = espressif8266
framework = arduino
board = esp12e
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -D${env.BOARD}
upload_speed = 115200
upload_port = "${env.IP}"
upload_flags = --auth=${env.AUTH} --port 8266

Loading…
Cancel
Save