Skip to content

Commit

Permalink
Version 2.2-beta10
Browse files Browse the repository at this point in the history
feat: display hum/temp values on webpage if sensor is present (#21)
feat: home assistant auto discovery implemented (#15)
feat: show itho speed val above slider on web page (#20)
feat: add file system format button to debug page
feat: update hardware design files
fix: a little more robust itho init check
  • Loading branch information
arjenhiemstra committed Apr 6, 2021
1 parent 352a5ae commit 6504bdf
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 38 deletions.
8 changes: 4 additions & 4 deletions compiled_firmware_files/firmware.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"hw_rev": {
"1": {
"latest_fw":"2.2-beta9",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_1/nrgitho-hw1-v2.2-beta9.bin"
"latest_fw":"2.2-beta10",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_1/nrgitho-hw1-v2.2-beta10.bin"
},
"2": {
"latest_fw":"2.2-beta9",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/nrgitho-hw2-v2.2-beta9.bin"
"latest_fw":"2.2-beta10",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/nrgitho-hw2-v2.2-beta10.bin"
}
}
}
Binary file not shown.
Binary file not shown.
12 changes: 2 additions & 10 deletions software/NRG_itho_wifi/02_HTML.ino
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ void handleAPI(AsyncWebServerRequest *request) {
}
else if(strcmp(p->name().c_str(), "debug") == 0) {
if (strcmp(p->value().c_str(), "format") == 0 ) {
if (SPIFFS.format()) {
strcpy(logBuff, "Filesystem format = success");
dontSaveConfig = true;
}
else {
strcpy(logBuff, "Filesystem format = failed");
}
jsonLogMessage(logBuff, WEBINTERFACE);
strcpy(logBuff, "");
formatFileSystem = true;
parseOK = true;
}
if (strcmp(p->value().c_str(), "reboot") == 0 ) {
Expand Down Expand Up @@ -265,7 +257,7 @@ void handleDebug(AsyncWebServerRequest *request) {
#elif defined (__HW_VERSION_TWO__)
response->print(SPIFFS.totalBytes());
#endif
response->print(F(" bytes total</span><br><a href='#' class='pure-button' onclick=\"$('#main').empty();$('#main').append( html_edit );\">Edit filesystem</a>"));
response->print(F(" bytes total</span><br><a href='#' class='pure-button' onclick=\"$('#main').empty();$('#main').append( html_edit );\">Edit filesystem</a>&nbsp;<button id=\"format\" class=\"pure-button\">Format filesystem</button>"));
#if defined (__HW_VERSION_TWO__)
response->print(F("<br><br><span>CC1101 task memory: </span><span>"));
response->print(TaskCC1101HWmark);
Expand Down
19 changes: 18 additions & 1 deletion software/NRG_itho_wifi/04_JS_UI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ function startWebsock(websocketServerLocation){
$('#itho_llm').addClass("pure-button button-secondary");
$('#itho_llm').text("Off");
}
if('format' in x) {
if(x.format) {
$('#format').text('Format filesystem');
}
else {
$('#format').text('Format failed');
}
}
}
else if (f.messagebox) {
let x = f.messagebox;
Expand Down Expand Up @@ -359,6 +368,12 @@ $(document).ready(function() {
websock.send('{\"reboot\":true}');
}
}
else if ($(this).attr('id') == 'format') {
if (confirm("This will erase all settings, are you sure?")) {
websock.send('{\"format\":true}');
$('#format').text('Formatting...');
}
}
else if ($(this).attr('id') == 'wifiscan') {
$('.ScanResults').remove();
$('.hidden').removeClass('hidden');
Expand Down Expand Up @@ -387,7 +402,7 @@ $(document).ready(function() {
}
else if ($(this).attr('id') == 'buttonstatusformat') {
websock.send('{\"ithobutton\":31}');
}
}
else if ($(this).attr('id') == 'updatesubmit') {
e.preventDefault();
var form = $('#updateform')[0];
Expand Down Expand Up @@ -616,6 +631,7 @@ function moveBar(nPer, element) {
//
function updateSlider(value) {
var val = parseInt(value);
if (isNaN(val)) val = 0;
$('#ithotextval').html(val);
websock.send(JSON.stringify({'itho':val}));
}
Expand Down Expand Up @@ -1142,6 +1158,7 @@ var html_mqttsetup = `
<label id="label-lwt_topic" for="mqtt_lwt_topic">Last will topic</label>
<input id="mqtt_lwt_topic" maxlength="120" type="text">
</div>
<br>
<div class="pure-control-group">
<label for="option-mqtt_ha" class="pure-radio">Home Assistant MQTT Discovery</label>
<input id="option-mqtt_ha-1" type="radio" name="option-mqtt_ha_active" onchange='radio("mqtt_ha", 1)' value="1"> on
Expand Down
5 changes: 4 additions & 1 deletion software/NRG_itho_wifi/06_Websock_func.ino
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void jsonSystemstat() {
#if defined (__HW_VERSION_TWO__)
systemstat["itho_llm"] = remotes.getllModeTime();
#endif
systemstat["ithoinit"] = ithoInit;
systemstat["ithoinit"] = ithoInitResult;
systemstat["sht3x"] = systemConfig.syssht30;

char buffer[512];
Expand Down Expand Up @@ -301,6 +301,9 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
else if (msg.startsWith("{\"resetsysconf")) {
resetSystemConfigflag = true;
}
else if (msg.startsWith("{\"format")) {
formatFileSystem = true;
}
else if (msg.startsWith("{\"itho")) {
StaticJsonDocument<128> root;
DeserializationError error = deserializeJson(root, msg);
Expand Down
18 changes: 9 additions & 9 deletions software/NRG_itho_wifi/09_init_code.ino
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ void hardwareInit() {
failSafeBoot();
#endif

IthoInitCheck.once(7, ithoInitCheck);
IthoInit = true;
}

void ithoInitCheck() {
bool ithoInitCheck() {
if (digitalRead(STATUSPIN) == LOW) {
ithoInit = 1;
}
else {
ithoInit = -1;
ithoInitResult = 1;
return false;
}
ithoInitResult = -1;
return true;
}

void logInit() {
Expand Down Expand Up @@ -557,12 +557,12 @@ void sendHADiscovery(JsonObject obj, const char* topic)
{
serializeJson(obj, mqttClient);
if (!mqttClient.endPublish()) logInput("MQTT: Failed to send payload (HA discovery)");
}
else
}
else
{
logInput("MQTT: Failed to start building message (HA discovery)");
}

// reset buffer
mqttClient.setBufferSize(MQTT_BUFFER_SIZE);
}
Expand Down
43 changes: 34 additions & 9 deletions software/NRG_itho_wifi/Loop.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ void execMQTTTasks() {
char buffer[512];

if (systemConfig.mqtt_domoticz_active) {
int humstat = 0;
int humstat = 0;
// Humidity Status
if (ithoHum < 31) {
humstat = 2;
}
humstat = 2;
}
else if (ithoHum > 69) {
humstat = 3;
}
humstat = 3;
}
else if (ithoHum > 34 && ithoHum < 66 && ithoTemp > 21 && ithoTemp < 27) {
humstat = 1;
humstat = 1;
}

char svalue[32];
sprintf(svalue, "%1.1f;%1.1f;%d", ithoTemp, ithoHum, humstat);

Expand All @@ -84,7 +84,7 @@ void execMQTTTasks() {
sprintf(buffer, "{\"temp\":%1.1f,\"hum\":%1.1f}", ithoTemp, ithoHum);
mqttClient.publish(systemConfig.mqtt_sensor_topic, buffer, true);
}

}
}
#endif
Expand All @@ -104,7 +104,11 @@ void execMQTTTasks() {
}

void execSystemControlTasks() {
if (systemConfig.itho_sendjoin > 0 && coldBoot && ithoInit == 1 && !joinSend) {

if (IthoInit) {
IthoInit = ithoInitCheck();
}
if (systemConfig.itho_sendjoin > 0 && coldBoot && ithoInitResult == 1 && !joinSend) {
joinSend = true;
sendJoinI2C();
logInput("Virtual remote join command send");
Expand Down Expand Up @@ -253,6 +257,27 @@ void execLogAndConfigTasks() {
lastLog = millis();
}

if (formatFileSystem) {
formatFileSystem = false;
char logBuff[LOG_BUF_SIZE] = "";
StaticJsonDocument<128> root;
JsonObject systemstat = root.createNestedObject("systemstat");

if (SPIFFS.format()) {
systemstat["format"] = 1;
strcpy(logBuff, "Filesystem format = success");
dontSaveConfig = true;
}
else {
systemstat["format"] = 0;
strcpy(logBuff, "Filesystem format = failed");
}
jsonLogMessage(logBuff, WEBINTERFACE);
strcpy(logBuff, "");
char buffer[128];
size_t len = serializeJson(root, buffer);
notifyClients(buffer, len);
}

}

Expand Down
9 changes: 5 additions & 4 deletions software/NRG_itho_wifi/NRG_itho_wifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* Choose partition scheme: Minimal SPIFFS (1.9 APP with OTA)
* Because of FreetRTOS function xTaskCreateStaticPinnedToCore a standard arduino esp-32 SDK lib needs to be replaced otherwise the code doesn't compile.
* A compiled version is included in the folder static files and should be copied to your SDK location ie.:
* /Arduino15/packages/esp32/hardware/esp32/1.0.5-rc7/tools/sdk/lib
* /Arduino15/packages/esp32/hardware/esp32/1.0.5/tools/sdk/lib
* and in:
* /Arduino15/packages/esp32/hardware/esp32/1.0.5-rc7/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h
* /Arduino15/packages/esp32/hardware/esp32/1.0.5/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h
* change "#define configSUPPORT_STATIC_ALLOCATION CONFIG_SUPPORT_STATIC_ALLOCATION" to "#define configSUPPORT_STATIC_ALLOCATION 1"
*
*
Expand Down Expand Up @@ -92,7 +92,6 @@ AsyncEventSource events("/events");
SpiffsFilePrint filePrint("/logfile", 2, 10000);

Ticker IthoCMD;
Ticker IthoInitCheck;
Ticker DelayedReq;
Ticker DelayedSave;
Ticker scan;
Expand Down Expand Up @@ -188,7 +187,8 @@ unsigned long lastLog = 0;
//flags used
bool coldBoot = false;
bool joinSend = false;
int8_t ithoInit = 0;
int8_t ithoInitResult = 0;
bool IthoInit = false;
bool shouldReboot = false;
bool onOTA = false;
bool dontSaveConfig = false;
Expand All @@ -200,6 +200,7 @@ bool dontReconnectMQTT = false;
bool clearQueue = false;
bool wifiModeAP = false;
bool sysStatReq = false;
bool formatFileSystem = false;
bool runscan = false;
bool updateIthoMQTT = false;
bool SHT3xupdated = false;
Expand Down

0 comments on commit 6504bdf

Please sign in to comment.