Skip to content

Commit

Permalink
- clean-up code
Browse files Browse the repository at this point in the history
- removed ESP8266 support (net enough memory to run all the new features of this version)
- removed all PROGMEM en FlashStringhelper code which is not usefull on ESP32
- Textual corrections
  • Loading branch information
arjenhiemstra committed Nov 30, 2021
1 parent 6bd63de commit 1c38192
Show file tree
Hide file tree
Showing 33 changed files with 1,978 additions and 2,403 deletions.
107 changes: 47 additions & 60 deletions software/NRG_itho_wifi/01_HTML.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <ESPAsyncWebServer.h>

const char html_mainpage[] PROGMEM = R"=====(
const char* html_mainpage = R"=====(
<!doctype html>
<html lang="en">
<head>
Expand Down Expand Up @@ -176,7 +176,6 @@ void handleAPI(AsyncWebServerRequest *request) {
if(!parseOK) parseOK = ithoSetTimer(timer, HTMLAPI);
}
else if(strcmp(p->name().c_str(), "debug") == 0) {
#if defined (HW_VERSION_TWO)
if (strcmp(p->value().c_str(), "level0") == 0 ) {

debugLevel = 0;
Expand Down Expand Up @@ -213,14 +212,13 @@ void handleAPI(AsyncWebServerRequest *request) {
strcpy(logBuff, "");
parseOK = true;
}
#endif
if (strcmp(p->value().c_str(), "format") == 0 ) {
formatFileSystem = true;
parseOK = true;
}
if (strcmp(p->value().c_str(), "reboot") == 0 ) {
shouldReboot = true;
logMessagejson(F("Reboot requested"), WEBINTERFACE);
logMessagejson("Reboot requested", WEBINTERFACE);
parseOK = true;
}
}
Expand All @@ -243,49 +241,39 @@ void handleDebug(AsyncWebServerRequest *request) {
}
AsyncResponseStream *response = request->beginResponseStream("text/html");

response->print(F("<div class=\"header\"><h1>Debug page</h1></div><br><br>"));
response->print(F("<div>Config version: "));
response->print("<div class=\"header\"><h1>Debug page</h1></div><br><br>");
response->print("<div>Config version: ");
response->print(CONFIG_VERSION);
response->print(F("<br><br><span>Itho I2C connection status: </span><span id=\'ithoinit\'>unknown</span></div>"));
response->print("<br><br><span>Itho I2C connection status: </span><span id=\'ithoinit\'>unknown</span></div>");

response->print(F("<br><span>File system: </span><span>"));
#if defined (HW_VERSION_ONE)
LITTLEFS.info(fs_info);
response->print(fs_info.usedBytes);
#elif defined (HW_VERSION_TWO)
response->print(LITTLEFS.usedBytes());
#endif
response->print(F(" bytes used / "));
#if defined (HW_VERSION_ONE)
response->print(fs_info.totalBytes);
#elif defined (HW_VERSION_TWO)
response->print(LITTLEFS.totalBytes());
#endif
response->print(F(" bytes total</span><br><a href='#' class='pure-button' onclick=\"$('#main').empty();$('#main').append( html_edit );\">Edit filesystem</a>"));
#if defined (HW_VERSION_TWO)
response->print(F("<br><br><span>CC1101 task memory: </span><span>"));
response->print("<br><span>File system: </span><span>");

response->print(ACTIVE_FS.usedBytes());
response->print(" bytes used / ");
response->print(ACTIVE_FS.totalBytes());
response->print(" bytes total</span><br><a href='#' class='pure-button' onclick=\"$('#main').empty();$('#main').append( html_edit );\">Edit filesystem</a>");
response->print("<br><br><span>CC1101 task memory: </span><span>");
response->print(TaskCC1101HWmark);
response->print(F(" bytes free</span>"));
response->print(F("<br><span>MQTT task memory: </span><span>"));
response->print(" bytes free</span>");
response->print("<br><span>MQTT task memory: </span><span>");
response->print(TaskMQTTHWmark);
response->print(F(" bytes free</span>"));
response->print(F("<br><span>Web task memory: </span><span>"));
response->print(" bytes free</span>");
response->print("<br><span>Web task memory: </span><span>");
response->print(TaskWebHWmark);
response->print(F(" bytes free</span>"));
response->print(F("<br><span>Config and Log task memory: </span><span>"));
response->print(" bytes free</span>");
response->print("<br><span>Config and Log task memory: </span><span>");
response->print(TaskConfigAndLogHWmark);
response->print(F(" bytes free</span>"));
response->print(F("<br><span>SysControl task memory: </span><span>"));
response->print(" bytes free</span>");
response->print("<br><span>SysControl task memory: </span><span>");
response->print(TaskSysControlHWmark);
response->print(F(" bytes free</span></div>"));
#endif
response->print(F("<br><br><div id='syslog_outer'><div style='display:inline-block;vertical-align:top;overflow:hidden;padding-bottom:5px;'>System Log:</div>"));
response->print(" bytes free</span></div>");
response->print("<br><br><div id='syslog_outer'><div style='display:inline-block;vertical-align:top;overflow:hidden;padding-bottom:5px;'>System Log:</div>");

response->print(F("<div style='padding:10px;background-color:black;min-height:30vh;max-height:60vh;font: 0.9rem Inconsolata, monospace;border-radius:7px;overflow:auto'>"));
response->print("<div style='padding:10px;background-color:black;min-height:30vh;max-height:60vh;font: 0.9rem Inconsolata, monospace;border-radius:7px;overflow:auto'>");
char link[24] = "";
char linkcur[24] = "";

if ( LITTLEFS.exists("/logfile0.current.log") ) {
if ( ACTIVE_FS.exists("/logfile0.current.log") ) {
strlcpy(linkcur, "/logfile0.current.log", sizeof(linkcur));
strlcpy(link, "/logfile1.log", sizeof(link));
}
Expand All @@ -294,37 +282,36 @@ void handleDebug(AsyncWebServerRequest *request) {
strlcpy(link, "/logfile0.log", sizeof(link));
}

File file = LITTLEFS.open(linkcur, FILE_READ);
File file = ACTIVE_FS.open(linkcur, FILE_READ);
while (file.available()) {
if(char(file.peek()) == '\n') response->print("<br>");
response->print(char(file.read()));
}
file.close();

response->print(F("</div><div style='padding-top:5px;'><a class='pure-button' href='/curlog'>Download current logfile</a>"));
response->print("</div><div style='padding-top:5px;'><a class='pure-button' href='/curlog'>Download current logfile</a>");

if ( LITTLEFS.exists(link) ) {
response->print(F("&nbsp;<a class='pure-button' href='/prevlog'>Download previous logfile</a>"));
if ( ACTIVE_FS.exists(link) ) {
response->print("&nbsp;<a class='pure-button' href='/prevlog'>Download previous logfile</a>");

}

#if defined (HW_VERSION_TWO)
response->print(F("</div></div><br><br><div id='rflog_outer' class='hidden'><div style='display:inline-block;vertical-align:top;overflow:hidden;padding-bottom:5px;'>RF Log:</div>"));
response->print(F("<div id='rflog' style='padding:10px;background-color:black;min-height:30vh;max-height:60vh;font: 0.9rem Inconsolata, monospace;border-radius:7px;overflow:auto'>"));
response->print(F("</div><div style='padding-top:5px;'><a href='#' class='pure-button' onclick=\"$('#rflog').empty()\">Clear</a></div></div></div>"));
#endif

response->print(F("<form class=\"pure-form pure-form-aligned\"><fieldset><legend><br>Low level itho I2C commands:</legend><br><span>I2C virtual remote commands:</span><br><button id=\"button1\" class=\"pure-button pure-button-primary\">Low</button>&nbsp;<button id=\"button2\" class=\"pure-button pure-button-primary\">Medium</button>&nbsp;<button id=\"button3\" class=\"pure-button pure-button-primary\">High</button><br><br>"));
response->print(F("<button id=\"buttonjoin\" class=\"pure-button pure-button-primary\">Join</button>&nbsp;<button id=\"buttonleave\" class=\"pure-button pure-button-primary\">Leave</button><br><br>"));
response->print(F("<button id=\"buttontype\" class=\"pure-button pure-button-primary\">Query Devicetype</button><br><span>Result:&nbsp;</span><span id=\'ithotype\'></span><br><br>"));
response->print(F("<button id=\"buttonstatusformat\" class=\"pure-button pure-button-primary\">Query Status Format</button><br><span>Result:&nbsp;</span><span id=\'ithostatusformat\'></span><br><br>"));
response->print(F("<button id=\"buttonstatus\" class=\"pure-button pure-button-primary\">Query Status</button><br><span>Result:&nbsp;</span><span id=\'ithostatus\'></span><br><br>"));
response->print(F("<button id=\"button2410\" class=\"pure-button pure-button-primary\">Query 2410</button>setting index: <input id=\"itho_setting_id\" type=\"number\" min=\"0\" max=\"254\" size=\"6\" value=\"0\"><br><span>Result:&nbsp;</span><span id=\'itho2410\'></span><br><span>Current:&nbsp;</span><span id=\'itho2410cur\'></span><br><span>Minimum value:&nbsp;</span><span id=\'itho2410min\'></span><br><span>Maximum value:&nbsp;</span><span id=\'itho2410max\'></span><br><br>"));
response->print(F("<span style=\"color:red\">Warning!!<br> \"Set 2410\" changes the settings of your itho unit<br>Use with care and use only if you know what you are doing!</span><br>"));
response->print(F("<button id=\"button2410set\" class=\"pure-button pure-button-primary\">Set 2410</button>setting index: <input id=\"itho_setting_id_set\" type=\"number\" min=\"0\" max=\"254\" size=\"6\" value=\"0\"> setting value: <input id=\"itho_setting_value_set\" type=\"number\" min=\"-2147483647\" max=\"2147483647\" size=\"10\" value=\"0\"><br><span>Sent command:&nbsp;</span><span id=\'itho2410set\'></span><br><span>Result:&nbsp;</span><span id=\'itho2410setres\'></span><br>"));
response->print(F("<span style=\"color:red\">Warning!!</span><br><br>"));
response->print(F("<button id=\"button31DA\" class=\"pure-button pure-button-primary\">Query 31DA</button><br><span>Result:&nbsp;</span><span id=\'itho31DA\'></span><br><br>"));
response->print(F("<button id=\"button31D9\" class=\"pure-button pure-button-primary\">Query 31D9</button><br><span>Result:&nbsp;</span><span id=\'itho31D9\'></span></fieldset></form><br>"));
response->print("</div></div><br><br><div id='rflog_outer' class='hidden'><div style='display:inline-block;vertical-align:top;overflow:hidden;padding-bottom:5px;'>RF Log:</div>");
response->print("<div id='rflog' style='padding:10px;background-color:black;min-height:30vh;max-height:60vh;font: 0.9rem Inconsolata, monospace;border-radius:7px;overflow:auto'>");
response->print("</div><div style='padding-top:5px;'><a href='#' class='pure-button' onclick=\"$('#rflog').empty()\">Clear</a></div></div></div>");

response->print("<form class=\"pure-form pure-form-aligned\"><fieldset><legend><br>Low level itho I2C commands:</legend><br><span>I2C virtual remote commands:</span><br><button id=\"button1\" class=\"pure-button pure-button-primary\">Low</button>&nbsp;<button id=\"button2\" class=\"pure-button pure-button-primary\">Medium</button>&nbsp;<button id=\"button3\" class=\"pure-button pure-button-primary\">High</button><br><br>");
response->print("<button id=\"buttonjoin\" class=\"pure-button pure-button-primary\">Join</button>&nbsp;<button id=\"buttonleave\" class=\"pure-button pure-button-primary\">Leave</button><br><br>");
response->print("<button id=\"buttontype\" class=\"pure-button pure-button-primary\">Query Devicetype</button><br><span>Result:&nbsp;</span><span id=\'ithotype\'></span><br><br>");
response->print("<button id=\"buttonstatusformat\" class=\"pure-button pure-button-primary\">Query Status Format</button><br><span>Result:&nbsp;</span><span id=\'ithostatusformat\'></span><br><br>");
response->print("<button id=\"buttonstatus\" class=\"pure-button pure-button-primary\">Query Status</button><br><span>Result:&nbsp;</span><span id=\'ithostatus\'></span><br><br>");
response->print("<button id=\"button2410\" class=\"pure-button pure-button-primary\">Query 2410</button>setting index: <input id=\"itho_setting_id\" type=\"number\" min=\"0\" max=\"254\" size=\"6\" value=\"0\"><br><span>Result:&nbsp;</span><span id=\'itho2410\'></span><br><span>Current:&nbsp;</span><span id=\'itho2410cur\'></span><br><span>Minimum value:&nbsp;</span><span id=\'itho2410min\'></span><br><span>Maximum value:&nbsp;</span><span id=\'itho2410max\'></span><br><br>");
response->print("<span style=\"color:red\">Warning!!<br> \"Set 2410\" changes the settings of your itho unit<br>Use with care and use only if you know what you are doing!</span><br>");
response->print("<button id=\"button2410set\" class=\"pure-button pure-button-primary\">Set 2410</button>setting index: <input id=\"itho_setting_id_set\" type=\"number\" min=\"0\" max=\"254\" size=\"6\" value=\"0\"> setting value: <input id=\"itho_setting_value_set\" type=\"number\" min=\"-2147483647\" max=\"2147483647\" size=\"10\" value=\"0\"><br><span>Sent command:&nbsp;</span><span id=\'itho2410set\'></span><br><span>Result:&nbsp;</span><span id=\'itho2410setres\'></span><br>");
response->print("<span style=\"color:red\">Warning!!</span><br><br>");
response->print("<button id=\"button31DA\" class=\"pure-button pure-button-primary\">Query 31DA</button><br><span>Result:&nbsp;</span><span id=\'itho31DA\'></span><br><br>");
response->print("<button id=\"button31D9\" class=\"pure-button pure-button-primary\">Query 31D9</button><br><span>Result:&nbsp;</span><span id=\'itho31D9\'></span></fieldset></form><br>");

response->print("<br><br>");

Expand All @@ -341,13 +328,13 @@ void handleCurLogDownload(AsyncWebServerRequest *request) {
return request->requestAuthentication();
}
char link[24] = "";
if ( LITTLEFS.exists("/logfile0.current.log") ) {
if ( ACTIVE_FS.exists("/logfile0.current.log") ) {
strlcpy(link, "/logfile0.current.log", sizeof(link));
}
else {
strlcpy(link, "/logfile1.current.log", sizeof(link));
}
request->send(LITTLEFS, link, "", true);
request->send(ACTIVE_FS, link, "", true);
}

void handlePrevLogDownload(AsyncWebServerRequest *request) {
Expand All @@ -356,11 +343,11 @@ void handlePrevLogDownload(AsyncWebServerRequest *request) {
return request->requestAuthentication();
}
char link[24] = "";
if ( LITTLEFS.exists("/logfile0.current.log") ) {
if ( ACTIVE_FS.exists("/logfile0.current.log") ) {
strlcpy(link, "/logfile1.log", sizeof(link));
}
else {
strlcpy(link, "/logfile0.log", sizeof(link));
}
request->send(LITTLEFS, link, "", true);
request->send(ACTIVE_FS, link, "", true);
}
6 changes: 3 additions & 3 deletions software/NRG_itho_wifi/02_JS_UI.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


const char controls_js[] PROGMEM = R"=====(
const char* controls_js = R"=====(
var count = 0;
var itho_low = 0;
Expand Down Expand Up @@ -1138,8 +1138,8 @@ var html_systemsettings_start = `
<input id="option-syssec_edit-1" type="radio" name="option-syssec_edit" value="1"> on
<input id="option-syssec_edit-0" type="radio" name="option-syssec_edit" value="0"> off
</div>
<legend><br>API settings (reboot needed):</legend>
<p>Have api keys on the WebAPI, MQTT API and Itho Status page normlized (all lowercase, no spaces and special charactars).</p>
<legend><br>API settings:</legend>
<p>Have api keys on the WebAPI, MQTT API and Itho Status page normlized (all lowercase, no spaces and special characters).</p>
<div class="pure-control-group">
<label for="option-api_normalize" class="pure-radio">Normalize keys</label>
<input id="option-api_normalize-1" type="radio" name="option-api_normalize" value="1"> on
Expand Down
70 changes: 31 additions & 39 deletions software/NRG_itho_wifi/06_Websock_func.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ void jsonWsSend(const char* rootName) {

if (strcmp(rootName, "wifisettings") == 0) {
JsonObject nested = root.createNestedObject(rootName);
nested[F("ssid")] = wifiConfig.ssid;
nested[F("passwd")] = wifiConfig.passwd;
nested[F("dhcp")] = wifiConfig.dhcp;
nested[F("renew")] = wifiConfig.renew;
nested["ssid"] = wifiConfig.ssid;
nested["passwd"] = wifiConfig.passwd;
nested["dhcp"] = wifiConfig.dhcp;
nested["renew"] = wifiConfig.renew;
if (strcmp(wifiConfig.dhcp, "off") == 0) {
nested[F("ip")] = wifiConfig.ip;
nested[F("subnet")] = wifiConfig.subnet;
nested[F("gateway")] = wifiConfig.gateway;
nested[F("dns1")] = wifiConfig.dns1;
nested[F("dns2")] = wifiConfig.dns2;
nested["ip"] = wifiConfig.ip;
nested["subnet"] = wifiConfig.subnet;
nested["gateway"] = wifiConfig.gateway;
nested["dns1"] = wifiConfig.dns1;
nested["dns2"] = wifiConfig.dns2;
}
else {
nested[F("ip")] = WiFi.localIP().toString();
nested[F("subnet")] = WiFi.subnetMask().toString();
nested[F("gateway")] = WiFi.gatewayIP().toString();
nested[F("dns1")] = WiFi.dnsIP().toString();
nested[F("dns2")] = WiFi.dnsIP(1).toString();
nested["ip"] = WiFi.localIP().toString();
nested["subnet"] = WiFi.subnetMask().toString();
nested["gateway"] = WiFi.gatewayIP().toString();
nested["dns1"] = WiFi.dnsIP().toString();
nested["dns2"] = WiFi.dnsIP(1).toString();
}
nested[F("port")] = wifiConfig.port;
nested[F("hostname")] = hostName();
nested["port"] = wifiConfig.port;
nested["hostname"] = hostName();
}
else if (strcmp(rootName, "systemsettings") == 0) {
// Create an object at the root
Expand All @@ -34,48 +34,43 @@ void jsonWsSend(const char* rootName) {
else if (strcmp(rootName, "ithodevinfo") == 0) {
// Create an object at the root
JsonObject nested = root.createNestedObject(rootName);
nested[F("itho_devtype")] = getIthoType(ithoDeviceID);
nested[F("itho_fwversion")] = itho_fwversion;
nested[F("itho_setlen")] = ithoSettingsLength;
nested["itho_devtype"] = getIthoType(ithoDeviceID);
nested["itho_fwversion"] = itho_fwversion;
nested["itho_setlen"] = ithoSettingsLength;
}
else if (strcmp(rootName, "ithosatusinfo") == 0) {
// Create an object at the root
JsonObject nested = root.createNestedObject(rootName);
getIthoStatusJSON(nested);
}

#if defined (HW_VERSION_TWO)
else if (strcmp(rootName, "ithoremotes") == 0) {
// Create an object at the root
JsonObject obj = root.to<JsonObject>(); // Fill the object
remotes.get(obj);
}
#endif
notifyClients(root.as<JsonObjectConst>());
}

void jsonSystemstat() {
StaticJsonDocument<512> root;
//JsonObject root = jsonBuffer.createObject();
JsonObject systemstat = root.createNestedObject("systemstat");
systemstat[F("freemem")] = sys.getMemHigh();
systemstat[F("memlow")] = sys.getMemLow();
systemstat[F("mqqtstatus")] = MQTT_conn_state;
systemstat[F("itho")] = ithoCurrentVal;
systemstat[F("itho_low")] = systemConfig.itho_low;
systemstat[F("itho_medium")] = systemConfig.itho_medium;
systemstat[F("itho_high")] = systemConfig.itho_high;
systemstat["freemem"] = sys.getMemHigh();
systemstat["memlow"] = sys.getMemLow();
systemstat["mqqtstatus"] = MQTT_conn_state;
systemstat["itho"] = ithoCurrentVal;
systemstat["itho_low"] = systemConfig.itho_low;
systemstat["itho_medium"] = systemConfig.itho_medium;
systemstat["itho_high"] = systemConfig.itho_high;

if (SHT3x_original || SHT3x_alternative || itho_internal_hum_temp)
{
systemstat[F("sensor_temp")] = ithoTemp;
systemstat[F("sensor_hum")] = ithoHum;
systemstat[F("sensor")] = 1;
systemstat["sensor_temp"] = ithoTemp;
systemstat["sensor_hum"] = ithoHum;
systemstat["sensor"] = 1;
}
#if defined (HW_VERSION_TWO)
systemstat[F("itho_llm")] = remotes.getllModeTime();
#endif
systemstat[F("ithoinit")] = ithoInitResult;
systemstat["itho_llm"] = remotes.getllModeTime();
systemstat["ithoinit"] = ithoInitResult;

notifyClients(root.as<JsonObjectConst>());

Expand Down Expand Up @@ -240,8 +235,6 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT

}
}

#if defined (HW_VERSION_TWO)
else if (msg.find("{\"ithoremotes\"") != std::string::npos) {
jsonWsSend("ithoremotes");
sysStatReq = true;
Expand Down Expand Up @@ -288,7 +281,6 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
saveRemotesflag = true;
}
}
#endif
else if (msg.find("{\"reboot\"") != std::string::npos) {
StaticJsonDocument<128> root;
DeserializationError error = deserializeJson(root, msg.c_str());
Expand Down
Loading

0 comments on commit 1c38192

Please sign in to comment.