mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-11 10:47:10 +01:00
Updated support for NoFUSS integration
This commit is contained in:
@@ -311,9 +311,10 @@ PROGMEM const char* const custom_reset_string[] = {
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#ifndef NOFUSS_SUPPORT
|
||||
#define NOFUSS_SUPPORT 0 // Do not enable support for NoFuss by default
|
||||
#define NOFUSS_SUPPORT 0 // Do not enable support for NoFuss by default
|
||||
#endif
|
||||
|
||||
#define NOFUSS_ENABLED 0 // Do not perform NoFUSS updates by default
|
||||
#define NOFUSS_SERVER "" // Default NoFuss Server
|
||||
#define NOFUSS_INTERVAL 3600000 // Check for updates every hour
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#define APP_NAME "ESPurna"
|
||||
#define APP_NAME "ESPURNA"
|
||||
#define APP_VERSION "1.9.2b"
|
||||
#define APP_AUTHOR "xose.perez@gmail.com"
|
||||
#define APP_WEBSITE "http://tinkerman.cat"
|
||||
|
||||
Binary file not shown.
@@ -10,74 +10,125 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
|
||||
|
||||
#include "NoFUSSClient.h"
|
||||
|
||||
unsigned long _nofussLastCheck = 0;
|
||||
unsigned long _nofussInterval = 0;
|
||||
bool _nofussEnabled = false;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// NOFUSS
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void nofussRun() {
|
||||
NoFUSSClient.handle();
|
||||
_nofussLastCheck = millis();
|
||||
}
|
||||
|
||||
void nofussConfigure() {
|
||||
|
||||
String nofussServer = getSetting("nofussServer", NOFUSS_SERVER);
|
||||
if (nofussServer.length() == 0) {
|
||||
setSetting("nofussEnabled", 0);
|
||||
_nofussEnabled = false;
|
||||
} else {
|
||||
_nofussEnabled = getSetting("nofussEnabled", NOFUSS_ENABLED).toInt() == 1;
|
||||
}
|
||||
_nofussInterval = getSetting("nofussInterval", NOFUSS_INTERVAL).toInt();
|
||||
_nofussLastCheck = 0;
|
||||
|
||||
if (!_nofussEnabled) {
|
||||
|
||||
DEBUG_MSG_P(PSTR("[NOFUSS] Disabled\n"));
|
||||
|
||||
} else {
|
||||
|
||||
char buffer[20];
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("%s-%s"), APP_NAME, DEVICE);
|
||||
|
||||
NoFUSSClient.setServer(nofussServer);
|
||||
NoFUSSClient.setDevice(buffer);
|
||||
NoFUSSClient.setVersion(APP_VERSION);
|
||||
|
||||
DEBUG_MSG_P(PSTR("[NOFUSS] Server : %s\n"), nofussServer.c_str());
|
||||
DEBUG_MSG_P(PSTR("[NOFUSS] Dervice: %s\n"), buffer);
|
||||
DEBUG_MSG_P(PSTR("[NOFUSS] Version: %s\n"), APP_VERSION);
|
||||
DEBUG_MSG_P(PSTR("[NOFUSS] Enabled\n"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void nofussSetup() {
|
||||
|
||||
NoFUSSClient.setServer(getSetting("nofussServer", NOFUSS_SERVER));
|
||||
NoFUSSClient.setDevice(DEVICE);
|
||||
NoFUSSClient.setVersion(APP_VERSION);
|
||||
nofussConfigure();
|
||||
|
||||
NoFUSSClient.onMessage([](nofuss_t code) {
|
||||
NoFUSSClient.onMessage([](nofuss_t code) {
|
||||
|
||||
if (code == NOFUSS_START) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Start\n"));
|
||||
}
|
||||
if (code == NOFUSS_START) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Start\n"));
|
||||
}
|
||||
|
||||
if (code == NOFUSS_UPTODATE) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Already in the last version\n"));
|
||||
}
|
||||
if (code == NOFUSS_UPTODATE) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Already in the last version\n"));
|
||||
}
|
||||
|
||||
if (code == NOFUSS_PARSE_ERROR) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Error parsing server response\n"));
|
||||
}
|
||||
if (code == NOFUSS_NO_RESPONSE_ERROR) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Wrong server response: %d %s\n"), NoFUSSClient.getErrorNumber(), (char *) NoFUSSClient.getErrorString().c_str());
|
||||
}
|
||||
|
||||
if (code == NOFUSS_UPDATING) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Updating"));
|
||||
DEBUG_MSG_P(PSTR(" New version: %s\n"), (char *) NoFUSSClient.getNewVersion().c_str());
|
||||
DEBUG_MSG_P(PSTR(" Firmware: %s\n"), (char *) NoFUSSClient.getNewFirmware().c_str());
|
||||
DEBUG_MSG_P(PSTR(" File System: %s"), (char *) NoFUSSClient.getNewFileSystem().c_str());
|
||||
}
|
||||
if (code == NOFUSS_PARSE_ERROR) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Error parsing server response\n"));
|
||||
}
|
||||
|
||||
if (code == NOFUSS_FILESYSTEM_UPDATE_ERROR) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] File System Update Error: %s\n"), (char *) NoFUSSClient.getErrorString().c_str());
|
||||
}
|
||||
if (code == NOFUSS_UPDATING) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Updating\n"));
|
||||
DEBUG_MSG_P(PSTR(" New version: %s\n"), (char *) NoFUSSClient.getNewVersion().c_str());
|
||||
DEBUG_MSG_P(PSTR(" Firmware: %s\n"), (char *) NoFUSSClient.getNewFirmware().c_str());
|
||||
DEBUG_MSG_P(PSTR(" File System: %s\n"), (char *) NoFUSSClient.getNewFileSystem().c_str());
|
||||
#if WEB_SUPPORT
|
||||
wsSend_P(PSTR("{\"message\": \"Remote update started\"}"));
|
||||
#endif
|
||||
}
|
||||
|
||||
if (code == NOFUSS_FILESYSTEM_UPDATED) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] File System Updated\n"));
|
||||
}
|
||||
if (code == NOFUSS_FILESYSTEM_UPDATE_ERROR) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] File System Update Error: %s\n"), (char *) NoFUSSClient.getErrorString().c_str());
|
||||
}
|
||||
|
||||
if (code == NOFUSS_FIRMWARE_UPDATE_ERROR) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Firmware Update Error: %s\n"), (char *) NoFUSSClient.getErrorString().c_str());
|
||||
}
|
||||
if (code == NOFUSS_FILESYSTEM_UPDATED) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] File System Updated\n"));
|
||||
}
|
||||
|
||||
if (code == NOFUSS_FIRMWARE_UPDATED) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Firmware Updated\n"));
|
||||
}
|
||||
if (code == NOFUSS_FIRMWARE_UPDATE_ERROR) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Firmware Update Error: %s\n"), (char *) NoFUSSClient.getErrorString().c_str());
|
||||
}
|
||||
|
||||
if (code == NOFUSS_RESET) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Resetting board\n"));
|
||||
}
|
||||
if (code == NOFUSS_FIRMWARE_UPDATED) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Firmware Updated\n"));
|
||||
}
|
||||
|
||||
if (code == NOFUSS_END) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] End\n"));
|
||||
}
|
||||
if (code == NOFUSS_RESET) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] Resetting board\n"));
|
||||
#if WEB_SUPPORT
|
||||
wsSend_P(PSTR("{\"action\": \"reload\"}"));
|
||||
#endif
|
||||
delay(100);
|
||||
}
|
||||
|
||||
});
|
||||
if (code == NOFUSS_END) {
|
||||
DEBUG_MSG_P(PSTR("[NoFUSS] End\n"));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void nofussLoop() {
|
||||
|
||||
static unsigned long last_check = 0;
|
||||
if (!wifiConnected()) return;
|
||||
unsigned long interval = getSetting("nofussInterval", NOFUSS_INTERVAL).toInt();
|
||||
if ((last_check > 0) && ((millis() - last_check) < interval)) return;
|
||||
last_check = millis();
|
||||
NoFUSSClient.handle();
|
||||
if (!_nofussEnabled) return;
|
||||
if (!wifiConnected()) return;
|
||||
if ((_nofussLastCheck > 0) && ((millis() - _nofussLastCheck) < _nofussInterval)) return;
|
||||
|
||||
nofussRun();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // NOFUSS_SUPPORT
|
||||
|
||||
@@ -117,6 +117,11 @@ void settingsSetup() {
|
||||
ESP.restart();
|
||||
});
|
||||
|
||||
Embedis::command( F("NOFUSS"), [](Embedis* e) {
|
||||
e->response(Embedis::OK);
|
||||
nofussRun();
|
||||
});
|
||||
|
||||
Embedis::command( F("FACTORY.RESET"), [](Embedis* e) {
|
||||
settingsFactoryReset();
|
||||
e->response(Embedis::OK);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -369,6 +369,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
|
||||
#if DOMOTICZ_SUPPORT
|
||||
domoticzConfigure();
|
||||
#endif
|
||||
#if NOFUSS_SUPPORT
|
||||
nofussConfigure();
|
||||
#endif
|
||||
#if RF_SUPPORT
|
||||
rfBuildCodes();
|
||||
#endif
|
||||
@@ -590,18 +593,24 @@ void _wsStart(uint32_t client_id) {
|
||||
root["powPowerFactor"] = String(getPowerFactor(), 2);
|
||||
#endif
|
||||
|
||||
#if NOFUSS_SUPPORT
|
||||
root["nofussVisible"] = 1;
|
||||
root["nofussEnabled"] = getSetting("nofussEnabled", NOFUSS_ENABLED).toInt() == 1;
|
||||
root["nofussServer"] = getSetting("nofussServer", NOFUSS_SERVER);
|
||||
#endif
|
||||
|
||||
#ifdef ITEAD_SONOFF_RFBRIDGE
|
||||
root["rfbVisible"] = 1;
|
||||
root["rfbCount"] = relayCount();
|
||||
JsonArray& rfb = root.createNestedArray("rfb");
|
||||
for (byte id=0; id<relayCount(); id++) {
|
||||
for (byte status=0; status<2; status++) {
|
||||
JsonObject& node = rfb.createNestedObject();
|
||||
node["id"] = id;
|
||||
node["status"] = status;
|
||||
node["data"] = rfbRetrieve(id, status == 1);
|
||||
root["rfbVisible"] = 1;
|
||||
root["rfbCount"] = relayCount();
|
||||
JsonArray& rfb = root.createNestedArray("rfb");
|
||||
for (byte id=0; id<relayCount(); id++) {
|
||||
for (byte status=0; status<2; status++) {
|
||||
JsonObject& node = rfb.createNestedObject();
|
||||
node["id"] = id;
|
||||
node["status"] = status;
|
||||
node["data"] = rfbRetrieve(id, status == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
root["wifiGain"] = getSetting("wifiGain", WIFI_GAIN).toFloat();
|
||||
|
||||
@@ -481,6 +481,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pure-g module module-nofuss">
|
||||
<div class="pure-u-1 pure-u-sm-1-4"><label for="nofussEnabled">Automatic remote updates (NoFUSS)</label></div>
|
||||
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="nofussEnabled" /></div>
|
||||
</div>
|
||||
|
||||
<div class="pure-g module module-nofuss">
|
||||
<label class="pure-u-1 pure-u-md-1-4" for="nofussServer">NoFUSS server</label>
|
||||
<input name="nofussServer" class="pure-u-1 pure-u-md-3-4" type="text" tabindex="15" />
|
||||
<div class="pure-u-0 pure-u-md-1-4"> </div>
|
||||
<div class="pure-u-1 pure-u-md-3-4 hint">This name address of the NoFUSS server for automatic remote updates (see https://bitbucket.org/xoseperez/nofuss).</div>
|
||||
</div>
|
||||
|
||||
<div class="pure-g">
|
||||
<label class="pure-u-1 pure-u-md-1-4">Upgrade</label>
|
||||
<input class="pure-u-1-2 pure-u-md-1-2" name="filename" type="text" readonly />
|
||||
@@ -488,7 +500,7 @@
|
||||
<div class=" pure-u-1-8 pure-u-md-1-8"><button class="pure-button button-upgrade pure-u-23-24">Upgrade</button></div>
|
||||
<div class="pure-u-0 pure-u-md-1-4"> </div>
|
||||
<div class="pure-u-1 pure-u-md-3-4"><progress id="upgrade-progress"></progress></div>
|
||||
<input name="upgrade" type="file" tabindex="15" />
|
||||
<input name="upgrade" type="file" tabindex="16" />
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
|
||||
@@ -25,7 +25,7 @@ lib_deps =
|
||||
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.1
|
||||
https://bitbucket.org/xoseperez/nofuss.git#0.2.4
|
||||
https://bitbucket.org/xoseperez/nofuss.git#0.2.5
|
||||
https://bitbucket.org/xoseperez/emonliteesp.git#0.2.0
|
||||
https://bitbucket.org/xoseperez/debounceevent.git#2.0.1
|
||||
https://github.com/xoseperez/my9291#2.0.0
|
||||
|
||||
Reference in New Issue
Block a user