Skip to content

Commit

Permalink
Version 2.3-beta2
Browse files Browse the repository at this point in the history
fix: bogus temperature/humidity value visible even if no sensor present
fix: remote on index 0 could not be removed
fix: remove remote wasn't handled correctly in the CC1101 library
fix: CC1101 support was not working for the NON-CVE wifi module
fix: removed some unused settings
fix: simplify hum/temp sensor support setting
fix: HA autodiscovery not working for hum/temp sensor data
fix: last command string incorrectly referenced as const char * instead of copy
fix: failed i2c request' CRC incorrectly resulted in checked OK
fix: wifi reconnect could result in timeout on task SysControl
  • Loading branch information
arjenhiemstra committed Oct 22, 2021
1 parent aca802e commit 7502b35
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 199 deletions.
Binary file not shown.
171 changes: 57 additions & 114 deletions software/NRG_itho_wifi/02_JS_UI.ino

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions software/NRG_itho_wifi/06_Websock_func.ino
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
}
else if (val == 24109) {
updateSetting(root["index"].as<int8_t>(), root["value"].as<int32_t>(), true);
}
}
}
else {
i2c_result_updateweb = true;
Expand Down Expand Up @@ -229,22 +229,22 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
}
else if (msg.find("{\"itho_remove_remote\"") != std::string::npos) {
bool parseOK = false;
int number = atoi( (msg.substr(22, len)).c_str() );
if (number == 0) {
if (strcmp(msg.substr(22, 23).c_str(), "0") == 0) {
StaticJsonDocument<128> root;
DeserializationError error = deserializeJson(root, msg.c_str());
if (!error) {
int number = root["itho_remove_remote"];
if (number > 0 && number < MAX_NUMBER_OF_REMOTES + 1) {
parseOK = true;
number--; //+1 was added earlier to offset index from 0
}
if (parseOK) {
remotes.removeRemote(number);
int* id = remotes.getRemoteIDbyIndex(number);
rf.setBindAllowed(true);
rf.removeRFDevice(*id, *(id + 1), *(id + 2));
rf.setBindAllowed(false);
saveRemotesflag = true;
}
}
else if (number > 0 && number < MAX_NUMBER_OF_REMOTES) {
parseOK = true;
}
if (parseOK) {
remotes.removeRemote(number);
int* id = remotes.getRemoteIDbyIndex(number);
rf.setBindAllowed(true);
rf.removeRFDevice(*id, *(id + 1), *(id + 2));
rf.setBindAllowed(false);
saveRemotesflag = true;
}
}
else if (msg.find("{\"itho_update_remote\"") != std::string::npos) {
Expand Down
1 change: 0 additions & 1 deletion software/NRG_itho_wifi/09_init_code.ino
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ void init_vRemote() {
id0 = getMac(6 - 3);
id1 = getMac(6 - 2);
id2 = getMac(6 - 1);
swap = systemConfig.itho_vremswap;
char buff[128];
sprintf(buff, "Setup: Virtual remote ID: %d,%d,%d", id0, id1, id2);
logInput(buff);
Expand Down
3 changes: 1 addition & 2 deletions software/NRG_itho_wifi/10_Gen_func.ino
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void getRemotesInfoJSON(JsonObject root) {

}


bool ithoExecCommand(const char* command, cmdOrigin origin)
{
D_LOG("EXEC COMMAND\n");
Expand Down Expand Up @@ -223,7 +222,7 @@ void logLastCommand(const char* command, cmdOrigin origin) {
void logLastCommand(const char* command, const char* source) {

lastCmd.source = source;
lastCmd.command = command;
strcpy(lastCmd.command, command);

if (time(nullptr)) {
time_t now;
Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/IthoCC1101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ bool IthoCC1101::addRFDevice(uint32_t ID) {

bool IthoCC1101::removeRFDevice(uint8_t byte0, uint8_t byte1, uint8_t byte2) {
uint32_t tempID = byte0 << 16 | byte1 << 8 | byte2;
return addRFDevice(tempID);
return removeRFDevice(tempID);
}

bool IthoCC1101::removeRFDevice(uint32_t ID) {
Expand Down
6 changes: 0 additions & 6 deletions software/NRG_itho_wifi/IthoCC1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ struct ithoRFDevices {
const uint8_t ithoPaTableSend[8] = {0x6F, 0x26, 0x2E, 0x8C, 0x87, 0xCD, 0xC7, 0xC0};
const uint8_t ithoPaTableReceive[8] = {0x6F, 0x26, 0x2E, 0x7F, 0x8A, 0x84, 0xCA, 0xC4};

const uint8_t messageOpcodeRemote[] = { 0x22, 0xF1 };
const uint8_t messageOpcodeRemoteAutoCO2[] = { 0x22, 0xF8 };
const uint8_t messageOpcodeTimer[] = { 0x22, 0xF3 };
const uint8_t messageOpcodeRFTRV[] = { 0x31, 0xE0 };
const uint8_t messageOpcodeRFBind[] = { 0x1F, 0xC9 };

//message command bytes
const uint8_t ithoMessageRVHighCommandBytes[] = {49, 224, 4, 0, 0, 200, 0};
const uint8_t ithoMessageHighCommandBytes[] = {34, 241, 3, 0, 4, 4};
Expand Down
7 changes: 3 additions & 4 deletions software/NRG_itho_wifi/IthoRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int IthoRemote::removeRemote(int* id) {

int index = this->remoteIndex(id);

if (index <= 0) return -1;
if (index < 0) return -1;

for (uint8_t i = 0; i < 3; i++) {
remotes[index].ID[i] = 0;
Expand All @@ -86,8 +86,7 @@ int IthoRemote::removeRemote(int* id) {

int IthoRemote::removeRemote(uint8_t index) {

if (index <= 0) return -1;
if (index > MAX_NUMBER_OF_REMOTES) return -1;
if (!(index < MAX_NUMBER_OF_REMOTES)) return -1;

if (remotes[index].ID[0] != 0 && remotes[index].ID[1] != 0 && remotes[index].ID[2] != 0) {
for (uint8_t i = 0; i < 3; i++) {
Expand Down Expand Up @@ -118,7 +117,7 @@ void IthoRemote::addCapabilities(uint8_t remoteIndex, const char* name, int32_t
}

int IthoRemote::remoteIndex(int32_t id) {
if (id <= 0) return -1;
if (id < 0) return -1;
int tempID[3];
tempID[0] = (id >> 16) & 0xFF;
tempID[1] = (id >> 8) & 0xFF;
Expand Down
32 changes: 9 additions & 23 deletions software/NRG_itho_wifi/IthoSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
#include "notifyClients.h"
#include "IthoSystemConsts.h"

size_t itho2401len = 0;

uint8_t ithoDeviceID = 0;
uint8_t itho_fwversion = 0;
volatile uint16_t ithoCurrentVal = 0;
uint8_t id0 = 0;
uint8_t id1 = 0;
uint8_t id2 = 0;
int8_t swap = 0;
struct ihtoDeviceType* ithoDeviceptr = getDevicePtr(ithoDeviceID);
int ithoSettingsLength = getSettingsLength(ithoDeviceID, itho_fwversion);
std::vector<ithoDeviceStatus> ithoStatus;
Expand Down Expand Up @@ -275,15 +272,6 @@ void sendButton(uint8_t number, bool & updateweb) {
command[14] = cmdCounter;
cmdCounter++;

if (swap) {
if (number == 1) {
number = 3;
}
else if (number == 3) {
number = 1;
}
}

command[19] += number;

command[sizeof(command) - 1] = checksum(command, sizeof(command) - 1);
Expand Down Expand Up @@ -433,7 +421,7 @@ void sendQueryDevicetype(bool & updateweb) {
size_t len = i2c_slave_receive(i2cbuf);

//if (len > 2) {
if (i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (len > 1 && i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (updateweb) {
updateweb = false;

Expand Down Expand Up @@ -491,7 +479,7 @@ void sendQueryStatusFormat(bool & updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (len > 1 && i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (updateweb) {
updateweb = false;
jsonSysmessage("ithostatusformat", i2cbuf2string(i2cbuf, len).c_str());
Expand Down Expand Up @@ -581,9 +569,7 @@ void sendQueryStatus(bool & updateweb) {
uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);

itho2401len = len;

if (i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (len > 1 && i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {

if (updateweb) {
updateweb = false;
Expand Down Expand Up @@ -637,7 +623,7 @@ void sendQueryStatus(bool & updateweb) {
}
}
if (strcmp(ithoStat.name.c_str(), "RelativeHumidity") == 0 || strcmp(ithoStat.name.c_str(), "humidity") == 0) {
if (ithoStat.value.floatval < 100.0) {
if (ithoStat.value.floatval > 1.0 && ithoStat.value.floatval < 100.0) {
if (!systemConfig.syssht30) {
ithoHum = ithoStat.value.floatval;
itho_internal_hum_temp = true;
Expand All @@ -649,7 +635,7 @@ void sendQueryStatus(bool & updateweb) {
}
}
if (strcmp(ithoStat.name.c_str(), "Temperature") == 0 || strcmp(ithoStat.name.c_str(), "temperature") == 0) {
if (ithoStat.value.floatval < 100.0) {
if (ithoStat.value.floatval > 1.0 && ithoStat.value.floatval < 100.0) {
if (!systemConfig.syssht30) {
ithoTemp = ithoStat.value.floatval;
itho_internal_hum_temp = true;
Expand Down Expand Up @@ -698,7 +684,7 @@ void sendQuery31DA(bool & updateweb) {
uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);

if (i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (len > 1 && i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {

if (updateweb) {
updateweb = false;
Expand Down Expand Up @@ -998,7 +984,7 @@ void sendQuery31D9(bool & updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (len > 1 && i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {

if (updateweb) {
updateweb = false;
Expand Down Expand Up @@ -1094,7 +1080,7 @@ int32_t * sendQuery2410(bool & updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (len > 1 && i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {

uint8_t tempBuf[] = { i2cbuf[9], i2cbuf[8], i2cbuf[7], i2cbuf[6] };
std::memcpy(&values[0], tempBuf, 4);
Expand Down Expand Up @@ -1171,7 +1157,7 @@ void setSetting2410(bool & updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (len > 1 && i2cbuf[len - 1] == checksum(i2cbuf, len - 1)) {
if (updateweb) {
updateweb = false;
if (len > 2) {
Expand Down
5 changes: 1 addition & 4 deletions software/NRG_itho_wifi/IthoSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

extern size_t itho2401len;

extern uint8_t ithoDeviceID;
extern uint8_t itho_fwversion;
extern volatile uint16_t ithoCurrentVal;
extern uint8_t id0, id1, id2;
extern int8_t swap;
extern struct ihtoDeviceType* ithoDeviceptr;
extern int ithoSettingsLength;

Expand Down Expand Up @@ -85,7 +82,7 @@ extern std::vector<ithoDeviceMeasurements> ithoInternalMeasurements;

struct lastCommand {
const char* source;
const char* command;
char command[20];
time_t timestamp;
};

Expand Down
3 changes: 2 additions & 1 deletion software/NRG_itho_wifi/NRG_itho_wifi.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define FWVERSION "2.3-beta1"
#define FWVERSION "2.3-beta2"

#define LOGGING_INTERVAL 21600000 //Log system status at regular intervals
#define ENABLE_FAILSAVE_BOOT
Expand Down Expand Up @@ -204,6 +204,7 @@ bool formatFileSystem = false;
bool runscan = false;
bool updateIthoMQTT = false;
bool updateMQTTihtoStatus = false;
bool sendHomeAssistantDiscovery = false;
volatile bool ithoCheck = false;
volatile bool saveRemotesflag = false;
bool SHT3x_original = false;
Expand Down
18 changes: 0 additions & 18 deletions software/NRG_itho_wifi/SystemConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ SystemConfig::SystemConfig() {
syssec_api = 0;
syssec_edit = 0;
syssht30 = 0;
sysfirhum = 0;
mqtt_active = 0;
strlcpy(mqtt_serverName, "192.168.1.123", sizeof(mqtt_serverName));
strlcpy(mqtt_username, "", sizeof(mqtt_username));
Expand Down Expand Up @@ -46,8 +45,6 @@ SystemConfig::SystemConfig() {
itho_updatefreq = 5;
itho_sendjoin = 0;
itho_forcemedium = 0;
itho_vremapi = 0;
itho_vremswap = 0;
itho_rf_support = 0;
rfInitOK = false;
nonQ_cmd_clearsQ = 1;
Expand Down Expand Up @@ -95,10 +92,6 @@ bool SystemConfig::set(JsonObjectConst obj) {
updated = true;
syssht30 = obj["syssht30"];
}
if (!(const char*)obj["sysfirhum"].isNull()) {
updated = true;
sysfirhum = obj["sysfirhum"];
}
//MQTT Settings parse
if (!(const char*)obj["mqtt_active"].isNull()) {
mqtt_updated = true;
Expand Down Expand Up @@ -217,14 +210,6 @@ bool SystemConfig::set(JsonObjectConst obj) {
updated = true;
itho_forcemedium = obj["itho_forcemedium"];
}
if (!(const char*)obj["itho_vremapi"].isNull()) {
updated = true;
itho_vremapi = obj["itho_vremapi"];
}
if (!(const char*)obj["itho_vremswap"].isNull()) {
updated = true;
itho_vremswap = obj["itho_vremswap"];
}
if (!(const char*)obj["itho_rf_support"].isNull()) {
updated = true;
itho_rf_support = obj["itho_rf_support"];
Expand Down Expand Up @@ -254,7 +239,6 @@ void SystemConfig::get(JsonObject obj) const {
obj["syssec_api"] = syssec_api;
obj["syssec_edit"] = syssec_edit;
obj["syssht30"] = syssht30;
obj["sysfirhum"] = sysfirhum;
obj["itho_rf_support"] = itho_rf_support;
obj["rfInitOK"] = rfInitOK;
obj["itho_fallback"] = itho_fallback;
Expand All @@ -267,8 +251,6 @@ void SystemConfig::get(JsonObject obj) const {
obj["itho_updatefreq"] = itho_updatefreq;
obj["itho_sendjoin"] = itho_sendjoin;
obj["itho_forcemedium"] = itho_forcemedium;
obj["itho_vremapi"] = itho_vremapi;
obj["itho_vremswap"] = itho_vremswap;
obj["nonQ_cmd_clearsQ"] = nonQ_cmd_clearsQ;
}
if (complete || get_mqtt_settings) {
Expand Down
3 changes: 0 additions & 3 deletions software/NRG_itho_wifi/SystemConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class SystemConfig {
uint8_t syssec_api;
uint8_t syssec_edit;
uint8_t syssht30;
uint8_t sysfirhum;
uint8_t mqtt_active;
char mqtt_serverName[65];
char mqtt_username[32];
Expand Down Expand Up @@ -48,8 +47,6 @@ class SystemConfig {
uint16_t itho_updatefreq;
uint8_t itho_sendjoin;
uint8_t itho_forcemedium;
uint8_t itho_vremapi;
uint8_t itho_vremswap;
uint8_t itho_rf_support;
mutable bool rfInitOK;
uint8_t nonQ_cmd_clearsQ;
Expand Down
4 changes: 3 additions & 1 deletion software/NRG_itho_wifi/TaskCC1101.ino
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ void TaskCC1101( void * pvParameters ) {

const ithoRFDevices &rfDevices = rf.getRFdevices();
for (auto& item : rfDevices.device) {
int remIndex = remotes.remoteIndex(item.deviceId);
if (item.deviceId == 0) continue;
int remIndex = remotes.remoteIndex(item.deviceId);
if (remIndex != -1) {
remotes.addCapabilities(remIndex, "lastcmd", item.lastCommand);
if (item.co2 != 0xEFFF) {
Expand All @@ -324,6 +325,7 @@ void TaskCC1101( void * pvParameters ) {
}
}
}

}
}
if (ithoCCstatReq) {
Expand Down
Loading

0 comments on commit 7502b35

Please sign in to comment.