Skip to content

Commit

Permalink
Version 2.3-beta3
Browse files Browse the repository at this point in the history
fix: timer would always go to high speed, restored API functionality to set speed & timer values at the same time
fix: add-on settings sometimes not loaded correctly due to websocket connection not active yet
fix: add units to HA auto discovery sensors

known issue: some itho settings should not be 32bit wide values. This results in some negative numbers not being parsed correctly in the itho firmware.
#40
  • Loading branch information
arjenhiemstra committed Oct 28, 2021
1 parent 93cee59 commit 6d3231a
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 49 deletions.
2 changes: 1 addition & 1 deletion compiled_firmware_files/firmware.json
Expand Up @@ -10,7 +10,7 @@
},
"NON-CVE 1": {
"latest_fw":"2.3-beta2",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/non-cve_rev_1/nrgitho-noncve-v2.3-beta2.bin"
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/non-cve_rev_1/nrgitho-noncve-v2.3-beta3.bin"
}
}
}
Binary file not shown.
Binary file not shown.
16 changes: 14 additions & 2 deletions software/NRG_itho_wifi/01_HTML.ino
Expand Up @@ -158,10 +158,22 @@ void handleAPI(AsyncWebServerRequest *request) {
parseOK = ithoI2CCommand(p->value().c_str(), HTMLAPI);
}
else if(strcmp(p->name().c_str(), "speed") == 0) {
parseOK = ithoSetSpeed(p->value().c_str(), HTMLAPI);
const char * speed = p->value().c_str();
for(int i=0;i<params;i++){
if(strcmp(p->name().c_str(), "timer") == 0) {
parseOK = ithoSetSpeedTimer(speed, p->value().c_str(), HTMLAPI);
}
}
if(!parseOK) parseOK = ithoSetSpeed(speed, HTMLAPI);
}
else if(strcmp(p->name().c_str(), "timer") == 0) {
parseOK = ithoSetTimer(p->value().c_str(), HTMLAPI);
const char * timer = p->value().c_str();
for(int i=0;i<params;i++){
if(strcmp(p->name().c_str(), "speed") == 0) {
parseOK = ithoSetSpeedTimer(p->value().c_str(), timer, HTMLAPI);
}
}
if(!parseOK) parseOK = ithoSetTimer(timer, HTMLAPI);
}
else if(strcmp(p->name().c_str(), "debug") == 0) {
#if defined (HW_VERSION_TWO)
Expand Down
19 changes: 13 additions & 6 deletions software/NRG_itho_wifi/02_JS_UI.ino
Expand Up @@ -294,7 +294,8 @@ $(document).ready(function() {
itho_timer3: $('#itho_timer3').val(),
itho_updatefreq: $('#itho_updatefreq').val(),
itho_sendjoin: $('input[name=\'option-itho_sendjoin\']:checked').val(),
itho_forcemedium: $('input[name=\'option-itho_forcemedium\']:checked').val()
itho_forcemedium: $('input[name=\'option-itho_forcemedium\']:checked').val(),
itho_vremoteapi: $('input[name=\'option-itho_vremoteapi\']:checked').val()
}
}));
update_page('system');
Expand Down Expand Up @@ -638,9 +639,9 @@ function getSettings(pagevalue) {
websock.send('{\"' + pagevalue + '\":1}');
}
else {
console.log("websock not open");
console.log("websock not open");
setTimeout(getSettings, 1000, pagevalue);
}
}
//
Expand Down Expand Up @@ -1130,7 +1131,7 @@ 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>Speed settings (0-254):</legend>
<legend><br>Speed settings (CVE only) (0-254):</legend>
<div class="pure-control-group">
<label for="itho_fallback">Start/fallback speed</label>
<input id="itho_fallback" type="number" min="0" max="254" size="6">
Expand All @@ -1147,10 +1148,10 @@ var html_systemsettings_start = `
<label for="itho_high">High</label>
<input id="itho_high" type="number" min="0" max="254" size="6">
</div>
<legend><br>Timer settings (0-65535 minutes):</legend>
<legend><br>Timer settings (0-254 minutes):</legend>
<div class="pure-control-group">
<label for="itho_timer1">Timer1</label>
<input id="itho_timer1" type="number" min="0" max="65535" size="6">
<input id="itho_timer1" type="number" min="0" max="254" size="6">
</div>
<div class="pure-control-group">
<label for="itho_timer2">Timer2</label>
Expand All @@ -1170,6 +1171,7 @@ var html_systemsettings_start = `
<p>The add-on can present itself as a virtual remote that can be joined to the itho unit.</p>
<p>This virtual remote can be used to force the itho unit in medium mode before sending a command from the add-on. This way the add-on can overrule the current speed settings of the itho (ie. due to active input from a built in humidity sensor or another remote)</p>
<p>A join command will only be accepted by the itho unit after a power cycle.</p>
<p>Received commands from RF remotes can be translated to matching virtual remote commands for non-CVE devices. The 0-254 speed control does not work for these devices, the timer settings do work as expected.
<div class="pure-control-group">
<label for="option-vremotejoin" class="pure-radio">Send join command</label>
<input id="option-vremotejoin-2" type="radio" name="option-itho_sendjoin" value="2"> every power on
Expand All @@ -1181,6 +1183,11 @@ var html_systemsettings_start = `
<input id="option-vremotemedium-1" type="radio" name="option-itho_forcemedium" value="1"> on
<input id="option-vremotemedium-0" type="radio" name="option-itho_forcemedium" value="0"> off
</div>
<div class="pure-control-group">
<label for="option-vremoteapi" class="pure-radio">Map RF remotes to virtual remote</label>
<input id="option-vremoteapi-1" type="radio" name="option-itho_vremoteapi" value="1"> on
<input id="option-vremoteapi-0" type="radio" name="option-itho_vremoteapi" value="0"> off
</div>
<legend><br>Built-in humidity/temp sensor support (reboot needed):</legend>
<p>Enabling this feature will, on boot, detect the presence of a supported humidity/temp sensor (either original itho or a supported alternative SHT30 sensor) and readout its values.</p><p>Values will be available through the API formatted as JSON.</p>
<p>If your itho has a built-in sensor by default and just the hum/temp values are enough, leave this setting set to 'off'.</p>
Expand Down
4 changes: 1 addition & 3 deletions software/NRG_itho_wifi/06_Websock_func.ino
Expand Up @@ -252,9 +252,7 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
DeserializationError error = deserializeJson(root, msg.c_str());
if (!error) {
uint8_t index = root["itho_update_remote"].as<unsigned int>();
char remoteName[32];
strlcpy(remoteName, root["value"] | "", sizeof(remoteName));
remotes.updateRemoteName(index, remoteName);
remotes.updateRemoteName(index, root["value"] | "");
saveRemotesflag = true;
}
}
Expand Down
80 changes: 54 additions & 26 deletions software/NRG_itho_wifi/10_Gen_func.ino
Expand Up @@ -59,33 +59,38 @@ void getRemotesInfoJSON(JsonObject root) {

}

bool ithoExecCommand(const char* command, cmdOrigin origin)
{
bool ithoExecCommand(const char* command, cmdOrigin origin) {
D_LOG("EXEC COMMAND\n");
if (strcmp(command, "low") == 0) {
ithoSetSpeed(systemConfig.itho_low, origin);
}
else if (strcmp(command, "medium") == 0) {
ithoSetSpeed(systemConfig.itho_medium, origin);
}
else if (strcmp(command, "high") == 0) {
ithoSetSpeed(systemConfig.itho_high, origin);
}
else if (strcmp(command, "timer1") == 0) {
ithoSetTimer(systemConfig.itho_timer1, origin);
}
else if (strcmp(command, "timer2") == 0) {
ithoSetTimer(systemConfig.itho_timer2, origin);
}
else if (strcmp(command, "timer3") == 0) {
ithoSetTimer(systemConfig.itho_timer3, origin);
}
else if (strcmp(command, "clearqueue") == 0) {
clearQueue = true;
if (systemConfig.itho_vremoteapi) {
return ithoI2CCommand(command, origin);
}
else {
return false;
if (strcmp(command, "low") == 0) {
ithoSetSpeed(systemConfig.itho_low, origin);
}
else if (strcmp(command, "medium") == 0) {
ithoSetSpeed(systemConfig.itho_medium, origin);
}
else if (strcmp(command, "high") == 0) {
ithoSetSpeed(systemConfig.itho_high, origin);
}
else if (strcmp(command, "timer1") == 0) {
ithoSetTimer(systemConfig.itho_timer1, origin);
}
else if (strcmp(command, "timer2") == 0) {
ithoSetTimer(systemConfig.itho_timer2, origin);
}
else if (strcmp(command, "timer3") == 0) {
ithoSetTimer(systemConfig.itho_timer3, origin);
}
else if (strcmp(command, "clearqueue") == 0) {
clearQueue = true;
}
else {
return false;
}
}

return true;

}
Expand Down Expand Up @@ -115,15 +120,15 @@ bool ithoI2CCommand(const char* command, cmdOrigin origin) {
sendI2CButton = true;
}
else if (strcmp(command, "timer1") == 0) {
timerValue = 10;
timerValue = systemConfig.itho_timer1;
sendI2CTimer = true;
}
else if (strcmp(command, "timer2") == 0) {
timerValue = 20;
timerValue = systemConfig.itho_timer2;
sendI2CTimer = true;
}
else if (strcmp(command, "timer3") == 0) {
timerValue = 30;
timerValue = systemConfig.itho_timer3;
sendI2CTimer = true;
}
else if (strcmp(command, "join") == 0) {
Expand Down Expand Up @@ -204,6 +209,29 @@ bool ithoSetTimer(uint16_t timer, cmdOrigin origin) {

}

bool ithoSetSpeedTimer(const char* speed, const char* timer, cmdOrigin origin) {
uint16_t speedval = strtoul(speed, NULL, 10);
uint16_t timerval = strtoul(speed, NULL, 10);
return ithoSetSpeedTimer(speedval, timerval, origin);
}

bool ithoSetSpeedTimer(uint16_t speed, uint16_t timer, cmdOrigin origin) {
D_LOG("SET SPEED AND TIMER\n");
if (speed < 255) {
nextIthoVal = speed;
nextIthoTimer = timer;
updateItho();
}
else {
return false;
}

char buf[32] {};
sprintf(buf, "speed:%d,timer:%d", speed, timer);
logLastCommand(buf, origin);
return true;
}

void logLastCommand(const char* command, cmdOrigin origin) {

if (origin != REMOTE) {
Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/IthoRemote.cpp
Expand Up @@ -101,7 +101,7 @@ int IthoRemote::removeRemote(uint8_t index) {
return 1;
}

void IthoRemote::updateRemoteName(uint8_t index, char* remoteName) {
void IthoRemote::updateRemoteName(uint8_t index, const char* remoteName) {
strlcpy(remotes[index].name, remoteName, sizeof(remotes[index].name));
}

Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/IthoRemote.h
Expand Up @@ -45,7 +45,7 @@ class IthoRemote {
int removeRemote(int* id);
int removeRemote(uint8_t index);
void addCapabilities(uint8_t remoteIndex, const char* name, int32_t value);
void updateRemoteName(uint8_t index, char* remoteName);
void updateRemoteName(uint8_t index, const char* remoteName);
int remoteIndex(int32_t id);
int remoteIndex(int* id);
int * getRemoteIDbyIndex(int index);
Expand Down
4 changes: 3 additions & 1 deletion software/NRG_itho_wifi/NRG_itho_wifi.ino
@@ -1,4 +1,4 @@
#define FWVERSION "2.3-beta2"
#define FWVERSION "2.3-beta3"

#define LOGGING_INTERVAL 21600000 //Log system status at regular intervals
#define ENABLE_FAILSAVE_BOOT
Expand Down Expand Up @@ -26,6 +26,8 @@
* (todo) i2c always slave unless master
* (todo) Restructure MQTT topics
* (todo) Restore compatibility with HW rev 1
* (todo) recheck status format if failed on boot
* (todo) implement settings format check to correctly handle shorter than 32 bit values
*
*/

Expand Down
6 changes: 6 additions & 0 deletions software/NRG_itho_wifi/SystemConfig.cpp
Expand Up @@ -45,6 +45,7 @@ SystemConfig::SystemConfig() {
itho_updatefreq = 5;
itho_sendjoin = 0;
itho_forcemedium = 0;
itho_vremoteapi = 0;
itho_rf_support = 0;
rfInitOK = false;
nonQ_cmd_clearsQ = 1;
Expand Down Expand Up @@ -210,6 +211,10 @@ bool SystemConfig::set(JsonObjectConst obj) {
updated = true;
itho_forcemedium = obj["itho_forcemedium"];
}
if (!(const char*)obj["itho_vremoteapi"].isNull()) {
updated = true;
itho_vremoteapi = obj["itho_vremoteapi"];
}
if (!(const char*)obj["itho_rf_support"].isNull()) {
updated = true;
itho_rf_support = obj["itho_rf_support"];
Expand Down Expand Up @@ -251,6 +256,7 @@ void SystemConfig::get(JsonObject obj) const {
obj["itho_updatefreq"] = itho_updatefreq;
obj["itho_sendjoin"] = itho_sendjoin;
obj["itho_forcemedium"] = itho_forcemedium;
obj["itho_vremoteapi"] = itho_vremoteapi;
obj["nonQ_cmd_clearsQ"] = nonQ_cmd_clearsQ;
}
if (complete || get_mqtt_settings) {
Expand Down
1 change: 1 addition & 0 deletions software/NRG_itho_wifi/SystemConfig.h
Expand Up @@ -47,6 +47,7 @@ class SystemConfig {
uint16_t itho_updatefreq;
uint8_t itho_sendjoin;
uint8_t itho_forcemedium;
uint8_t itho_vremoteapi;
uint8_t itho_rf_support;
mutable bool rfInitOK;
uint8_t nonQ_cmd_clearsQ;
Expand Down
12 changes: 6 additions & 6 deletions software/NRG_itho_wifi/TaskCC1101.ino
Expand Up @@ -268,22 +268,22 @@ void TaskCC1101( void * pvParameters ) {
if (chk) {
remotes.lastRemoteName = remotes.getRemoteNamebyIndex(remotes.remoteIndex(id));
if (cmd == IthoLow) {
ithoSetSpeed(systemConfig.itho_low, REMOTE);
ithoExecCommand("low", REMOTE);
}
if (cmd == IthoMedium) {
ithoSetSpeed(systemConfig.itho_medium, REMOTE);
ithoExecCommand("medium", REMOTE);
}
if (cmd == IthoHigh) {
ithoSetSpeed(systemConfig.itho_high, REMOTE);
ithoExecCommand("high", REMOTE);
}
if (cmd == IthoTimer1) {
ithoSetTimer(systemConfig.itho_timer1, REMOTE);
ithoExecCommand("timer1", REMOTE);
}
if (cmd == IthoTimer2) {
ithoSetTimer(systemConfig.itho_timer2, REMOTE);
ithoExecCommand("timer2", REMOTE);
}
if (cmd == IthoTimer3) {
ithoSetTimer(systemConfig.itho_timer3, REMOTE);
ithoExecCommand("timer3", REMOTE);
}
if (cmd == IthoJoin && !remotes.remoteLearnLeaveStatus()) {
}
Expand Down
14 changes: 12 additions & 2 deletions software/NRG_itho_wifi/TaskMQTT.ino
Expand Up @@ -251,11 +251,21 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
}
if (!(const char*)root["speed"].isNull()) {
jsonCmd = true;
ithoSetSpeed(root["speed"].as<uint16_t>(), MQTTAPI);
if (!(const char*)root["timer"].isNull()) {
ithoSetSpeedTimer(root["speed"].as<uint16_t>(), root["timer"].as<uint16_t>(), MQTTAPI);
}
else {
ithoSetSpeed(root["speed"].as<uint16_t>(), MQTTAPI);
}
}
if (!(const char*)root["timer"].isNull()) {
jsonCmd = true;
ithoSetTimer(root["timer"].as<uint16_t>(), MQTTAPI);
if (!(const char*)root["speed"].isNull()) {
ithoSetSpeedTimer(root["speed"].as<uint16_t>(), root["timer"].as<uint16_t>(), MQTTAPI);
}
else {
ithoSetSpeed(root["timer"].as<uint16_t>(), MQTTAPI);
}
}
if (!(const char*)root["clearqueue"].isNull()) {
jsonCmd = true;
Expand Down

0 comments on commit 6d3231a

Please sign in to comment.