Browse Source

Merge branch 'dev' into compact-ws

sensors
Max Prokhorov 5 years ago
committed by GitHub
parent
commit
860ecb7464
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 17580 additions and 17435 deletions
  1. +0
    -0
      CONTRIBUTING.md
  2. +8
    -0
      SUPPORT.md
  3. +36
    -12
      code/espurna/button.ino
  4. +2
    -2
      code/espurna/config/general.h
  5. +2
    -0
      code/espurna/config/prototypes.h
  6. +3
    -0
      code/espurna/config/types.h
  7. BIN
      code/espurna/data/index.all.html.gz
  8. BIN
      code/espurna/data/index.light.html.gz
  9. BIN
      code/espurna/data/index.rfbridge.html.gz
  10. BIN
      code/espurna/data/index.rfm69.html.gz
  11. BIN
      code/espurna/data/index.sensor.html.gz
  12. BIN
      code/espurna/data/index.small.html.gz
  13. +1
    -1
      code/espurna/encoder.ino
  14. +3
    -3
      code/espurna/espurna.ino
  15. +67
    -16
      code/espurna/homeassistant.ino
  16. +3147
    -3145
      code/espurna/static/index.all.html.gz.h
  17. +2992
    -2990
      code/espurna/static/index.light.html.gz.h
  18. +2603
    -2601
      code/espurna/static/index.rfbridge.html.gz.h
  19. +4056
    -4054
      code/espurna/static/index.rfm69.html.gz.h
  20. +2616
    -2613
      code/espurna/static/index.sensor.html.gz.h
  21. +1994
    -1992
      code/espurna/static/index.small.html.gz.h
  22. +10
    -0
      code/espurna/system.ino
  23. +1
    -1
      code/espurna/utils.ino
  24. +4
    -0
      code/espurna/ws.ino
  25. +11
    -2
      code/html/custom.js
  26. +2
    -3
      code/html/index.html
  27. +22
    -0
      code/platformio.ini

.github/contribute.md → CONTRIBUTING.md View File


+ 8
- 0
SUPPORT.md View File

@ -0,0 +1,8 @@
# ESPurna Support
If you're looking for support for ESPurna there are some options available:
* [Issues](https://github.com/xoseperez/espurna/issues?utf8=%E2%9C%93&q=is%3Aissue): this is the most dinamic channel at the moment, you might find an answer to your question by searching current or closed issues.
* [Wiki pages](https://github.com/xoseperez/espurna/wiki): might not be as up-to-date as we all would like (hey, you can also contribute in the documentation!).
* [Gitter channel](https://gitter.im/tinkerman-cat/espurna): you have better chances to get fast answers from me or other ESPurna users.
* [Issue a question](https://github.com/xoseperez/espurna/issues/new/choose): as a last resort, you can open new *question* issues on GitHub. Just remember: the more info you provide the more chances you'll have to get an accurate answer.

+ 36
- 12
code/espurna/button.ino View File

@ -105,37 +105,61 @@ void buttonEvent(unsigned int id, unsigned char event) {
} }
#endif #endif
if (action == BUTTON_MODE_TOGGLE) {
if (BUTTON_MODE_TOGGLE == action) {
if (_buttons[id].relayID > 0) { if (_buttons[id].relayID > 0) {
relayToggle(_buttons[id].relayID - 1); relayToggle(_buttons[id].relayID - 1);
} }
} }
if (action == BUTTON_MODE_ON) {
if (BUTTON_MODE_ON == action) {
if (_buttons[id].relayID > 0) { if (_buttons[id].relayID > 0) {
relayStatus(_buttons[id].relayID - 1, true); relayStatus(_buttons[id].relayID - 1, true);
} }
} }
if (action == BUTTON_MODE_OFF) {
if (BUTTON_MODE_OFF == action) {
if (_buttons[id].relayID > 0) { if (_buttons[id].relayID > 0) {
relayStatus(_buttons[id].relayID - 1, false); relayStatus(_buttons[id].relayID - 1, false);
} }
} }
if (action == BUTTON_MODE_AP) wifiStartAP();
#if defined(JUSTWIFI_ENABLE_WPS)
if (action == BUTTON_MODE_WPS) wifiStartWPS();
#endif // defined(JUSTWIFI_ENABLE_WPS)
#if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
if (action == BUTTON_MODE_SMART_CONFIG) wifiStartSmartConfig();
#endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
if (action == BUTTON_MODE_RESET) {
if (BUTTON_MODE_AP == action) {
wifiStartAP();
}
if (BUTTON_MODE_RESET == action) {
deferredReset(100, CUSTOM_RESET_HARDWARE); deferredReset(100, CUSTOM_RESET_HARDWARE);
} }
if (action == BUTTON_MODE_FACTORY) {
if (BUTTON_MODE_FACTORY == action) {
DEBUG_MSG_P(PSTR("\n\nFACTORY RESET\n\n")); DEBUG_MSG_P(PSTR("\n\nFACTORY RESET\n\n"));
resetSettings(); resetSettings();
deferredReset(100, CUSTOM_RESET_FACTORY); deferredReset(100, CUSTOM_RESET_FACTORY);
} }
#if defined(JUSTWIFI_ENABLE_WPS)
if (BUTTON_MODE_WPS == action) {
wifiStartWPS();
}
#endif // defined(JUSTWIFI_ENABLE_WPS)
#if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
if (BUTTON_MODE_SMART_CONFIG == action) {
wifiStartSmartConfig();
}
#endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
if (BUTTON_MODE_DIM_UP == action) {
lightBrightnessStep(1);
lightUpdate(true, true);
}
if (BUTTON_MODE_DIM_DOWN == action) {
lightBrightnessStep(-1);
lightUpdate(true, true);
}
#endif // LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
} }
void buttonSetup() { void buttonSetup() {


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

@ -235,8 +235,8 @@
#define HEARTBEAT_REPORT_HOSTNAME 1 #define HEARTBEAT_REPORT_HOSTNAME 1
#endif #endif
#ifndef HEARTBEAT_REPORT_DESCRITION
#define HEARTBEAT_REPORT_DESCRITION 1
#ifndef HEARTBEAT_REPORT_DESCRIPTION
#define HEARTBEAT_REPORT_DESCRIPTION 1
#endif #endif
#ifndef HEARTBEAT_REPORT_APP #ifndef HEARTBEAT_REPORT_APP


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

@ -194,6 +194,8 @@ void webRequestRegister(web_request_callback_f callback);
typedef std::function<bool(const char *, JsonVariant&)> ws_on_receive_callback_f; typedef std::function<bool(const char *, JsonVariant&)> ws_on_receive_callback_f;
void wsOnReceiveRegister(ws_on_receive_callback_f callback); void wsOnReceiveRegister(ws_on_receive_callback_f callback);
bool wsConnected();
bool wsConnected(uint32_t);
bool wsDebugSend(const char*, const char*); bool wsDebugSend(const char*, const char*);
#else #else
#define ws_on_send_callback_f void * #define ws_on_send_callback_f void *


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

@ -48,6 +48,9 @@
#define BUTTON_MODE_FACTORY 7 #define BUTTON_MODE_FACTORY 7
#define BUTTON_MODE_WPS 8 #define BUTTON_MODE_WPS 8
#define BUTTON_MODE_SMART_CONFIG 9 #define BUTTON_MODE_SMART_CONFIG 9
#define BUTTON_MODE_DIM_UP 10
#define BUTTON_MODE_DIM_DOWN 11
// Needed for ESP8285 boards under Windows using PlatformIO (?) // Needed for ESP8285 boards under Windows using PlatformIO (?)
#ifndef BUTTON_PUSHBUTTON #ifndef BUTTON_PUSHBUTTON


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


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


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


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


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


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


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

@ -105,7 +105,7 @@ void _encoderLoop() {
// action // action
if (encoder.button_pin == GPIO_NONE) { if (encoder.button_pin == GPIO_NONE) {
// if there is no button, the encoder driver the CHANNEL1
// if there is no button, the encoder drives CHANNEL1
lightChannelStep(encoder.channel1, delta); lightChannelStep(encoder.channel1, delta);
} else { } else {


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

@ -64,12 +64,12 @@ void setup() {
// Init EEPROM // Init EEPROM
eepromSetup(); eepromSetup();
// Init Serial, SPIFFS and system check
systemSetup();
// Init persistance // Init persistance
settingsSetup(); settingsSetup();
// Init Serial, SPIFFS and system check
systemSetup();
// Init terminal features // Init terminal features
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
terminalSetup(); terminalSetup();


+ 67
- 16
code/espurna/homeassistant.ino View File

@ -9,6 +9,7 @@ Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
#if HOMEASSISTANT_SUPPORT #if HOMEASSISTANT_SUPPORT
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <queue>
bool _haEnabled = false; bool _haEnabled = false;
bool _haSendFlag = false; bool _haSendFlag = false;
@ -147,9 +148,7 @@ void _haSendSwitches() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
String _haGetConfig() {
String output;
void _haDumpConfig(std::function<void(String&)> printer, bool wrapJson = false) {
#if (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) || (defined(ITEAD_SLAMPHER)) #if (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) || (defined(ITEAD_SLAMPHER))
String type = String("light"); String type = String("light");
@ -163,8 +162,16 @@ String _haGetConfig() {
JsonObject& config = jsonBuffer.createObject(); JsonObject& config = jsonBuffer.createObject();
_haSendSwitch(i, config); _haSendSwitch(i, config);
output += "\n" + type + ":\n";
String output;
output.reserve(config.measureLength() + 32);
if (wrapJson) {
output += "{\"haConfig\": \"";
}
output += "\n\n" + type + ":\n";
bool first = true; bool first = true;
for (auto kv : config) { for (auto kv : config) {
if (first) { if (first) {
output += " - "; output += " - ";
@ -172,11 +179,21 @@ String _haGetConfig() {
} else { } else {
output += " "; output += " ";
} }
output += kv.key + String(": ") + kv.value.as<String>() + String("\n");
output += kv.key;
output += ": ";
output += kv.value.as<String>();
output += "\n";
}
output += " ";
if (wrapJson) {
output += "\"}";
} }
jsonBuffer.clear(); jsonBuffer.clear();
printer(output);
} }
#if SENSOR_SUPPORT #if SENSOR_SUPPORT
@ -187,8 +204,16 @@ String _haGetConfig() {
JsonObject& config = jsonBuffer.createObject(); JsonObject& config = jsonBuffer.createObject();
_haSendMagnitude(i, config); _haSendMagnitude(i, config);
output += "\nsensor:\n";
String output;
output.reserve(config.measureLength() + 32);
if (wrapJson) {
output += "{\"haConfig\": \"";
}
output += "\n\nsensor:\n";
bool first = true; bool first = true;
for (auto kv : config) { for (auto kv : config) {
if (first) { if (first) {
output += " - "; output += " - ";
@ -198,18 +223,25 @@ String _haGetConfig() {
} }
String value = kv.value.as<String>(); String value = kv.value.as<String>();
value.replace("%", "'%'"); value.replace("%", "'%'");
output += kv.key + String(": ") + value + String("\n");
output += kv.key;
output += ": ";
output += value;
output += "\n";
}
output += " ";
if (wrapJson) {
output += "\"}";
} }
output += "\n";
jsonBuffer.clear(); jsonBuffer.clear();
printer(output);
} }
#endif #endif
return output;
} }
void _haSend() { void _haSend() {
@ -241,6 +273,8 @@ void _haConfigure() {
#if WEB_SUPPORT #if WEB_SUPPORT
std::queue<uint32_t> _ha_send_config;
bool _haWebSocketOnReceive(const char * key, JsonVariant& value) { bool _haWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "ha", 2) == 0); return (strncmp(key, "ha", 2) == 0);
} }
@ -253,11 +287,7 @@ void _haWebSocketOnSend(JsonObject& root) {
void _haWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& data) { void _haWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& data) {
if (strcmp(action, "haconfig") == 0) { if (strcmp(action, "haconfig") == 0) {
String output = _haGetConfig();
output.replace(" ", "&nbsp;");
output.replace("\n", "<br />");
output = String("{\"haConfig\": \"") + output + String("\"}");
wsSend(client_id, output.c_str());
_ha_send_config.push(client_id);
} }
} }
@ -268,7 +298,10 @@ void _haWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& d
void _haInitCommands() { void _haInitCommands() {
terminalRegisterCommand(F("HA.CONFIG"), [](Embedis* e) { terminalRegisterCommand(F("HA.CONFIG"), [](Embedis* e) {
DEBUG_MSG(_haGetConfig().c_str());
_haDumpConfig([](String& data) {
DEBUG_MSG(data.c_str());
});
DEBUG_MSG("\n");
terminalOK(); terminalOK();
}); });
@ -296,6 +329,23 @@ void _haInitCommands() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if WEB_SUPPORT
void _haLoop() {
if (_ha_send_config.empty()) return;
uint32_t client_id = _ha_send_config.front();
_ha_send_config.pop();
if (!wsConnected(client_id)) return;
// TODO check wsConnected after each "printer" call?
_haDumpConfig([client_id](String& output) {
wsSend(client_id, output.c_str());
yield();
}, true);
}
#endif
void haSetup() { void haSetup() {
_haConfigure(); _haConfigure();
@ -304,6 +354,7 @@ void haSetup() {
wsOnSendRegister(_haWebSocketOnSend); wsOnSendRegister(_haWebSocketOnSend);
wsOnActionRegister(_haWebSocketOnAction); wsOnActionRegister(_haWebSocketOnAction);
wsOnReceiveRegister(_haWebSocketOnReceive); wsOnReceiveRegister(_haWebSocketOnReceive);
espurnaRegisterLoop(_haLoop);
#endif #endif
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT


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


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


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


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


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


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


+ 10
- 0
code/espurna/system.ino View File

@ -86,6 +86,12 @@ void _systemSetupHeartbeat() {
_heartbeat_interval = getSetting("hbInterval", HEARTBEAT_INTERVAL).toInt(); _heartbeat_interval = getSetting("hbInterval", HEARTBEAT_INTERVAL).toInt();
} }
#if WEB_SUPPORT
bool _systemWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "hb", 2) == 0);
}
#endif
void systemLoop() { void systemLoop() {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@ -182,6 +188,10 @@ void systemSetup() {
systemCheck(false); systemCheck(false);
#endif #endif
#if WEB_SUPPORT
wsOnReceiveRegister(_systemWebSocketOnReceive);
#endif
// Init device-specific hardware // Init device-specific hardware
_systemSetupSpecificHardware(); _systemSetupSpecificHardware();


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

@ -181,7 +181,7 @@ namespace Heartbeat {
(Relay * (HEARTBEAT_REPORT_RELAY)) | \ (Relay * (HEARTBEAT_REPORT_RELAY)) | \
(Light * (HEARTBEAT_REPORT_LIGHT)) | \ (Light * (HEARTBEAT_REPORT_LIGHT)) | \
(Hostname * (HEARTBEAT_REPORT_HOSTNAME)) | \ (Hostname * (HEARTBEAT_REPORT_HOSTNAME)) | \
(Description * (HEARTBEAT_REPORT_DESCRITION)) | \
(Description * (HEARTBEAT_REPORT_DESCRIPTION)) | \
(App * (HEARTBEAT_REPORT_APP)) | \ (App * (HEARTBEAT_REPORT_APP)) | \
(Version * (HEARTBEAT_REPORT_VERSION)) | \ (Version * (HEARTBEAT_REPORT_VERSION)) | \
(Board * (HEARTBEAT_REPORT_BOARD)) | \ (Board * (HEARTBEAT_REPORT_BOARD)) | \


+ 4
- 0
code/espurna/ws.ino View File

@ -482,6 +482,10 @@ bool wsConnected() {
return (_ws.count() > 0); return (_ws.count() > 0);
} }
bool wsConnected(uint32_t client_id) {
return _ws.hasClient(client_id);
}
void wsOnSendRegister(ws_on_send_callback_f callback) { void wsOnSendRegister(ws_on_send_callback_f callback) {
_ws_on_send_callbacks.push_back(callback); _ws_on_send_callbacks.push_back(callback);
} }


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

@ -657,7 +657,10 @@ function doScan() {
} }
function doHAConfig() { function doHAConfig() {
$("#haConfig").html("");
$("#haConfig")
.text("")
.height(0)
.show();
sendAction("haconfig", {}); sendAction("haconfig", {});
return false; return false;
} }
@ -1384,7 +1387,11 @@ function processData(data) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
if ("haConfig" === key) { if ("haConfig" === key) {
$("#haConfig").show();
websock.send("{}");
$("#haConfig")
.append(new Text(value))
.height($("#haConfig")[0].scrollHeight);
return;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -1736,6 +1743,8 @@ $(function() {
$(document).on("change", "input", hasChanged); $(document).on("change", "input", hasChanged);
$(document).on("change", "select", hasChanged); $(document).on("change", "select", hasChanged);
$("textarea").on("dblclick", function() { this.select(); });
// don't autoconnect when opening from filesystem // don't autoconnect when opening from filesystem
if (window.location.protocol === "file:") { return; } if (window.location.protocol === "file:") { return; }


+ 2
- 3
code/html/index.html View File

@ -633,13 +633,12 @@
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Heartbeat message</label> <label class="pure-u-1 pure-u-lg-1-4">Heartbeat message</label>
<select class="pure-u-1 pure-u-lg-1-4" name="hbMode" tabindex="15" >
<select class="pure-u-1 pure-u-lg-3-4" name="hbMode" tabindex="15" >
<option value="0">Disabled</option> <option value="0">Disabled</option>
<option value="1">On device startup</option> <option value="1">On device startup</option>
<option value="2">Repeat after defined interval</option> <option value="2">Repeat after defined interval</option>
<option value="3">Repeat only device status</option> <option value="3">Repeat only device status</option>
</select> </select>
<div class="pure-u-0 pure-u-lg-1-2"></div>
<div class="pure-u-0 pure-u-lg-1-4"></div> <div class="pure-u-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint"> <div class="pure-u-1 pure-u-lg-3-4 hint">
Define when heartbeat message will be sent. Define when heartbeat message will be sent.
@ -1115,7 +1114,7 @@
</div> </div>
</div> </div>
<div class="pure-g"> <div class="pure-g">
<span class="pure-u-1 terminal" id="haConfig" name="haConfig"></span>
<textarea class="pure-u-1 terminal" id="haConfig" name="haConfig" wrap="off" readonly></textarea>
</div> </div>


+ 22
- 0
code/platformio.ini View File

@ -435,6 +435,17 @@ build_flags = ${common.build_flags_1m0m} -DITEAD_SONOFF_BASIC -DDHT_SUPPORT=1
monitor_speed = ${common.monitor_speed} monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts} extra_scripts = ${common.extra_scripts}
[env:itead-sonoff-basic-r2-dht]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_1m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m0m} -DITEAD_SONOFF_BASIC -DDHT_SUPPORT=1 -DDHT_PIN=2
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:itead-sonoff-basic-dht-ota] [env:itead-sonoff-basic-dht-ota]
platform = ${common.platform} platform = ${common.platform}
framework = ${common.framework} framework = ${common.framework}
@ -460,6 +471,17 @@ build_flags = ${common.build_flags_1m0m} -DITEAD_SONOFF_BASIC -DDALLAS_SUPPORT=1
monitor_speed = ${common.monitor_speed} monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts} extra_scripts = ${common.extra_scripts}
[env:itead-sonoff-basic-r2-dallas]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_1m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m0m} -DITEAD_SONOFF_BASIC -DDALLAS_SUPPORT=1 -DDALLAS_PIN=2
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:itead-sonoff-rf] [env:itead-sonoff-rf]
platform = ${common.platform} platform = ${common.platform}
framework = ${common.framework} framework = ${common.framework}


Loading…
Cancel
Save