Browse Source

Merge branch 'dev' into sensors

rfm69
Xose Pérez 6 years ago
parent
commit
85d0d0501a
16 changed files with 2717 additions and 2496 deletions
  1. +3
    -0
      code/espurna/config/arduino.h
  2. +2
    -0
      code/espurna/config/general.h
  3. +98
    -9
      code/espurna/config/hardware.h
  4. BIN
      code/espurna/data/index.html.gz
  5. +8
    -4
      code/espurna/debug.ino
  6. +38
    -0
      code/espurna/migrate.ino
  7. +87
    -54
      code/espurna/mqtt.ino
  8. +1
    -1
      code/espurna/relay.ino
  9. +19
    -14
      code/espurna/scheduler.ino
  10. +2412
    -2412
      code/espurna/static/index.html.gz.h
  11. +3
    -0
      code/espurna/utils.ino
  12. +2
    -2
      code/html/custom.js
  13. +44
    -0
      code/platformio.ini
  14. BIN
      images/devices/maxcio-15a.jpg
  15. BIN
      images/devices/tonbux-xs-ssa06.jpg
  16. BIN
      images/devices/yidian-16a.jpg

+ 3
- 0
code/espurna/config/arduino.h View File

@ -64,6 +64,9 @@
//#define EUROMATE_WIFI_STECKER_SCHUKO
//#define TONBUX_POWERSTRIP02
//#define LINGAN_SWA1
//#define HEYGO_HY02
//#define MAXCIO_WUS002S
//#define YIDIAN_XSSSA05
//--------------------------------------------------------------------------------
// Features (values below are non-default values)


+ 2
- 0
code/espurna/config/general.h View File

@ -181,6 +181,7 @@
#define HEARTBEAT_REPORT_HOSTNAME 1
#define HEARTBEAT_REPORT_APP 1
#define HEARTBEAT_REPORT_VERSION 1
#define HEARTBEAT_REPORT_BOARD 1
#define HEARTBEAT_REPORT_INTERVAL 0
//------------------------------------------------------------------------------
@ -617,6 +618,7 @@ PROGMEM const char* const custom_reset_string[] = {
#define MQTT_TOPIC_UARTIN "uartin"
#define MQTT_TOPIC_UARTOUT "uartout"
#define MQTT_TOPIC_LOADAVG "loadavg"
#define MQTT_TOPIC_BOARD "board"
// Light module
#define MQTT_TOPIC_CHANNEL "channel"


+ 98
- 9
code/espurna/config/hardware.h View File

@ -102,10 +102,6 @@
#define MANUFACTURER "WEMOS"
#define DEVICE "D1_TARPUNA_SHIELD"
// Relays
#define RELAY1_PIN 12
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// -----------------------------------------------------------------------------
// ESPurna
// -----------------------------------------------------------------------------
@ -772,7 +768,6 @@
#define LED1_PIN 13
#define LED1_PIN_INVERSE 1
// -----------------------------------------------------------------------------
// YJZK
// -----------------------------------------------------------------------------
@ -1258,7 +1253,6 @@
#define LIGHT_CH3_INVERSE 0
#define LIGHT_CH4_INVERSE 0
#elif defined(ARILUX_AL_LC02)
// Info
@ -1301,7 +1295,6 @@
#define LIGHT_CH4_INVERSE 0
#define LIGHT_CH5_INVERSE 0
#elif defined(ARILUX_AL_LC11)
// Info
@ -1324,7 +1317,6 @@
#define LIGHT_CH4_INVERSE 0
#define LIGHT_CH5_INVERSE 0
#elif defined(ARILUX_E27)
// Info
@ -1519,6 +1511,10 @@
#define RELAY8_PIN 15
#define RELAY8_TYPE RELAY_TYPE_NORMAL
// -----------------------------------------------------------------------------
// STM RELAY
// -----------------------------------------------------------------------------
#elif defined(STM_RELAY)
// Info
@ -1590,6 +1586,98 @@
#define LED1_PIN 4
#define LED1_PIN_INVERSE 1
// -----------------------------------------------------------------------------
// HEYGO HY02
// -----------------------------------------------------------------------------
#elif defined(HEYGO_HY02)
// Info
#define MANUFACTURER "HEYGO"
#define DEVICE "HY02"
// Buttons
#define BUTTON1_PIN 13
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON1_RELAY 1
// Relays
#define RELAY1_PIN 12
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 0
#define LED1_PIN_INVERSE 0
#define LED2_PIN 15
#define LED2_PIN_INVERSE 0
// HLW8012
#ifndef HLW8012_SUPPORT
#define HLW8012_SUPPORT 1
#endif
#define HLW8012_SEL_PIN 3
#define HLW8012_CF1_PIN 14
#define HLW8012_CF_PIN 5
#define HLW8012_VOLTAGE_R_UP ( 2 * 1200000 ) // Upstream voltage resistor
// -----------------------------------------------------------------------------
// Maxcio W-US002S
// -----------------------------------------------------------------------------
#elif defined(MAXCIO_WUS002S)
// Info
#define MANUFACTURER "MAXCIO"
#define DEVICE "WUS002S"
// Buttons
#define BUTTON1_PIN 2
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON1_RELAY 1
// Relays
#define RELAY1_PIN 13
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 3
#define LED1_PIN_INVERSE 0
// HLW8012
#ifndef HLW8012_SUPPORT
#define HLW8012_SUPPORT 1
#endif
#define HLW8012_SEL_PIN 12
#define HLW8012_CF1_PIN 5
#define HLW8012_CF_PIN 4
#define HLW8012_CURRENT_R 0.002 // Current resistor
#define HLW8012_VOLTAGE_R_UP ( 2 * 1000000 ) // Upstream voltage resistor
// -----------------------------------------------------------------------------
// YiDian XS-SSA05
// -----------------------------------------------------------------------------
#elif defined(YIDIAN_XSSSA05)
// Info
#define MANUFACTURER "YIDIAN"
#define DEVICE "XSSSA05"
// Buttons
#define BUTTON1_PIN 13
#define BUTTON1_MODE BUTTON_PUSHBUTTON
#define BUTTON1_RELAY 1
// Relays
#define RELAY1_PIN 12
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 4
#define LED1_PIN_INVERSE 0
// -----------------------------------------------------------------------------
// TEST boards (do not use!!)
// -----------------------------------------------------------------------------
@ -1616,7 +1704,8 @@
// A bit of I2C - pins 3,4
#define I2C_SDA_PIN 3
#define I2C_SCL_PIN 4
// and, as they say in "From Dusk till Dawn":
// And, as they say in "From Dusk till Dawn":
// This is a sensor blow out!
// Alright, we got white sensor, black sensor, spanish sensor, yellow sensor. We got hot sensor, cold sensor.
// We got wet sensor. We got smelly sensor. We got hairy sensor, bloody sensor. We got snapping sensor.


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


+ 8
- 4
code/espurna/debug.ino View File

@ -61,12 +61,16 @@ void _debugSend(char * message) {
#endif
#if DEBUG_WEB_SUPPORT
if (wsConnected()) {
char buffer[strlen(message) + 24];
if (wsConnected() && (getFreeHeap() > 10000)) {
String m = String(message);
m.replace("\"", """);
m.replace("{", "&#123");
m.replace("}", "&#125");
char buffer[m.length() + 24];
#if DEBUG_ADD_TIMESTAMP
snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s%s\"}"), timestamp, message);
snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s%s\"}"), timestamp, m.c_str());
#else
snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s\"}"), message);
snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s\"}"), m.c_str());
#endif
wsSend(buffer);
}


+ 38
- 0
code/espurna/migrate.ino View File

@ -769,6 +769,44 @@ void migrate() {
setSetting("relayGPIO", 0, 5);
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
#elif defined(HEYGO_HY02)
setSetting("board", 58);
setSetting("ledGPIO", 0, 0);
setSetting("ledLogic", 0, 0);
setSetting("ledGPIO", 1, 15);
setSetting("ledLogic", 1, 0);
setSetting("btnGPIO", 0, 13);
setSetting("btnRelay", 0, 0);
setSetting("relayGPIO", 0, 12);
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
setSetting("selGPIO", 3);
setSetting("cf1GPIO", 14);
setSetting("cfGPIO", 5);
#elif defined(MAXCIO_WUS002S)
setSetting("board", 59);
setSetting("ledGPIO", 0, 3);
setSetting("ledLogic", 0, 0);
setSetting("btnGPIO", 0, 2);
setSetting("btnRelay", 0, 0);
setSetting("relayGPIO", 0, 13);
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
setSetting("selGPIO", 12);
setSetting("cf1GPIO", 5);
setSetting("cfGPIO", 4);
#elif defined(YIDIAN_XSSSA05)
setSetting("board", 60);
setSetting("ledGPIO", 0, 4);
setSetting("ledLogic", 0, 0);
setSetting("btnGPIO", 0, 13);
setSetting("btnRelay", 0, 0);
setSetting("relayGPIO", 0, 12);
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
#else
// Allow users to define new settings without migration config


+ 87
- 54
code/espurna/mqtt.ino View File

@ -55,8 +55,9 @@ unsigned long _mqtt_connected_at = 0;
std::vector<mqtt_callback_f> _mqtt_callbacks;
typedef struct {
unsigned char parent = 255;
char * topic;
char * message;
char * message = NULL;
} mqtt_message_t;
std::vector<mqtt_message_t> _mqtt_queue;
Ticker _mqtt_flush_ticker;
@ -502,20 +503,85 @@ void mqttSendRaw(const char * topic, const char * message) {
mqttSendRaw (topic, message, _mqtt_retain);
}
void mqttFlush() {
void mqttSend(const char * topic, const char * message, bool force, bool retain) {
if (!_mqtt.connected()) return;
if (_mqtt_queue.size() == 0) return;
bool useJson = force ? false : _mqtt_use_json;
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
// Equeue message
if (useJson) {
// Set default queue topic
mqttQueueTopic(MQTT_TOPIC_JSON);
// Enqueue new message
mqttEnqueue(topic, message);
// Reset flush timer
_mqtt_flush_ticker.once_ms(MQTT_USE_JSON_DELAY, mqttFlush);
// Send it right away
} else {
mqttSendRaw(mqttTopic(topic, false).c_str(), message, retain);
}
}
void mqttSend(const char * topic, const char * message, bool force) {
mqttSend(topic, message, force, _mqtt_retain);
}
void mqttSend(const char * topic, const char * message) {
mqttSend(topic, message, false);
}
void mqttSend(const char * topic, unsigned int index, const char * message, bool force, bool retain) {
char buffer[strlen(topic)+5];
snprintf_P(buffer, sizeof(buffer), PSTR("%s/%d"), topic, index);
mqttSend(buffer, message, force, retain);
}
void mqttSend(const char * topic, unsigned int index, const char * message, bool force) {
mqttSend(topic, index, message, force, _mqtt_retain);
}
void mqttSend(const char * topic, unsigned int index, const char * message) {
mqttSend(topic, index, message, false);
}
// -----------------------------------------------------------------------------
unsigned char _mqttBuildTree(JsonObject& root, char parent) {
unsigned char count = 0;
// Add enqueued messages
for (unsigned char i=0; i<_mqtt_queue.size(); i++) {
mqtt_message_t element = _mqtt_queue[i];
root[element.topic] = element.message;
if (element.parent == parent) {
++count;
JsonObject& elements = root.createNestedObject(element.topic);
unsigned char num = _mqttBuildTree(elements, i);
if (0 == num) {
root.set(element.topic, element.message);
}
}
}
return count;
}
void mqttFlush() {
if (!_mqtt.connected()) return;
if (_mqtt_queue.size() == 0) return;
// Build tree recursively
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
_mqttBuildTree(root, 255);
// Add extra propeties
#if NTP_SUPPORT && MQTT_ENQUEUE_DATETIME
if (ntpSynced()) root[MQTT_TOPIC_TIME] = ntpDateTime();
@ -542,7 +608,9 @@ void mqttFlush() {
for (unsigned char i = 0; i < _mqtt_queue.size(); i++) {
mqtt_message_t element = _mqtt_queue[i];
free(element.topic);
free(element.message);
if (element.message) {
free(element.message);
}
}
_mqtt_queue.clear();
@ -556,67 +624,32 @@ void mqttQueueTopic(const char * topic) {
}
}
void mqttEnqueue(const char * topic, const char * message) {
int8_t mqttEnqueue(const char * topic, const char * message, unsigned char parent) {
// Queue is not meant to send message "offline"
// We must prevent the queue does not get full while offline
if (!_mqtt.connected()) return;
if (!_mqtt.connected()) return -1;
// Force flusing the queue if the MQTT_QUEUE_MAX_SIZE has been reached
if (_mqtt_queue.size() >= MQTT_QUEUE_MAX_SIZE) mqttFlush();
int8_t index = _mqtt_queue.size();
// Enqueue new message
mqtt_message_t element;
element.parent = parent;
element.topic = strdup(topic);
element.message = strdup(message);
_mqtt_queue.push_back(element);
}
void mqttSend(const char * topic, const char * message, bool force, bool retain) {
bool useJson = force ? false : _mqtt_use_json;
// Equeue message
if (useJson) {
// Set default queue topic
mqttQueueTopic(MQTT_TOPIC_JSON);
// Enqueue new message
mqttEnqueue(topic, message);
// Reset flush timer
_mqtt_flush_ticker.once_ms(MQTT_USE_JSON_DELAY, mqttFlush);
// Send it right away
} else {
mqttSendRaw(mqttTopic(topic, false).c_str(), message, retain);
if (NULL != message) {
element.message = strdup(message);
}
_mqtt_queue.push_back(element);
}
void mqttSend(const char * topic, const char * message, bool force) {
mqttSend(topic, message, force, _mqtt_retain);
}
void mqttSend(const char * topic, const char * message) {
mqttSend(topic, message, false);
}
void mqttSend(const char * topic, unsigned int index, const char * message, bool force, bool retain) {
char buffer[strlen(topic)+5];
snprintf_P(buffer, sizeof(buffer), PSTR("%s/%d"), topic, index);
mqttSend(buffer, message, force, retain);
}
return index;
void mqttSend(const char * topic, unsigned int index, const char * message, bool force) {
mqttSend(topic, index, message, force, _mqtt_retain);
}
void mqttSend(const char * topic, unsigned int index, const char * message) {
mqttSend(topic, index, message, false);
int8_t mqttEnqueue(const char * topic, const char * message) {
return mqttEnqueue(topic, message, 255);
}
// -----------------------------------------------------------------------------


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

@ -802,7 +802,7 @@ void _relayInitCommands() {
relayStatus(id, value == 1);
}
}
DEBUG_MSG_P(PSTR("Status: %s\n"), relayStatus(id) ? "true" : "false");
DEBUG_MSG_P(PSTR("Status: %s\n"), _relays[id].target_status ? "true" : "false");
DEBUG_MSG_P(PSTR("+OK\n"));
});


+ 19
- 14
code/espurna/scheduler.ino View File

@ -17,20 +17,25 @@ Adapted by Xose Pérez <xose dot perez at gmail dot com>
void _schWebSocketOnSend(JsonObject &root){
root["schVisible"] = 1;
root["maxSchedules"] = SCHEDULER_MAX_SCHEDULES;
JsonArray &sch = root.createNestedArray("schedule");
for (byte i = 0; i < SCHEDULER_MAX_SCHEDULES; i++) {
if (!hasSetting("schSwitch", i)) break;
JsonObject &scheduler = sch.createNestedObject();
scheduler["schEnabled"] = getSetting("schEnabled", i, 1).toInt() == 1;
scheduler["schSwitch"] = getSetting("schSwitch", i, 0).toInt();
scheduler["schAction"] = getSetting("schAction", i, 0).toInt();
scheduler["schType"] = getSetting("schType", i, 0);
scheduler["schHour"] = getSetting("schHour", i, 0).toInt();
scheduler["schMinute"] = getSetting("schMinute", i, 0).toInt();
scheduler["schWDs"] = getSetting("schWDs", i, "");
if (relayCount() > 0) {
root["schVisible"] = 1;
root["maxSchedules"] = SCHEDULER_MAX_SCHEDULES;
JsonArray &sch = root.createNestedArray("schedule");
for (byte i = 0; i < SCHEDULER_MAX_SCHEDULES; i++) {
if (!hasSetting("schSwitch", i)) break;
JsonObject &scheduler = sch.createNestedObject();
scheduler["schEnabled"] = getSetting("schEnabled", i, 1).toInt() == 1;
scheduler["schSwitch"] = getSetting("schSwitch", i, 0).toInt();
scheduler["schAction"] = getSetting("schAction", i, 0).toInt();
scheduler["schType"] = getSetting("schType", i, 0).toInt();
scheduler["schHour"] = getSetting("schHour", i, 0).toInt();
scheduler["schMinute"] = getSetting("schMinute", i, 0).toInt();
scheduler["schWDs"] = getSetting("schWDs", i, "");
}
}
}
#endif // WEB_SUPPORT
@ -159,7 +164,7 @@ void _schCheck() {
if ((minutes_to_trigger % 15 == 0) || (minutes_to_trigger < 15)) {
DEBUG_MSG_P(
PSTR("[SCH] %d minutes to trigger schedule #%d\n"),
minutes_to_trigger, sch_switch
minutes_to_trigger, i
);
}
#endif


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


+ 3
- 0
code/espurna/utils.ino View File

@ -137,6 +137,9 @@ void heartbeat() {
#if (HEARTBEAT_REPORT_VERSION)
mqttSend(MQTT_TOPIC_VERSION, APP_VERSION);
#endif
#if (HEARTBEAT_REPORT_BOARD)
mqttSend(MQTT_TOPIC_BOARD, getBoardName().c_str());
#endif
#if (HEARTBEAT_REPORT_HOSTNAME)
mqttSend(MQTT_TOPIC_HOSTNAME, getSetting("hostname").c_str());
#endif


+ 2
- 2
code/html/custom.js View File

@ -1349,8 +1349,8 @@ $(function() {
$(".button-add-network").on("click", function() {
$(".more", addNetwork()).toggle();
});
$(".button-add-switch-schedule").on("click", { schType: "1" }, addSchedule);
$(".button-add-light-schedule").on("click", { schType: "2" }, addSchedule);
$(".button-add-switch-schedule").on("click", { schType: 1 }, addSchedule);
$(".button-add-light-schedule").on("click", { schType: 2 }, addSchedule);
$(document).on("change", "input", hasChanged);
$(document).on("change", "select", hasChanged);


+ 44
- 0
code/platformio.ini View File

@ -190,6 +190,16 @@ build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_SWITCH
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
[env:wemos-d1-tarpunashield]
platform = ${common.platform}
framework = arduino
board = esp12e
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DWEMOS_D1_TARPUNA_SHIELD
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
# ------------------------------------------------------------------------------
[env:itead-sonoff-basic]
@ -1546,6 +1556,40 @@ upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
[env:heygo-hy02]
platform = ${common.platform}
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} -DHEYGO_HY02
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
[env:maxcio-wus0025]
platform = ${common.platform}
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} -DMAXCIO_WUS002S
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
[env:yidian-xsssa05]
platform = ${common.platform}
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} -DYIDIAN_XSSSA05
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
# ------------------------------------------------------------------------------
# GENERIC OTA ENVIRONMENTS
# ------------------------------------------------------------------------------


BIN
images/devices/maxcio-15a.jpg View File

Before After
Width: 400  |  Height: 400  |  Size: 3.5 KiB

BIN
images/devices/tonbux-xs-ssa06.jpg View File

Before After
Width: 400  |  Height: 400  |  Size: 7.3 KiB

BIN
images/devices/yidian-16a.jpg View File

Before After
Width: 400  |  Height: 400  |  Size: 6.0 KiB

Loading…
Cancel
Save