Skip to content

Commit

Permalink
Version 2.3-alpha8
Browse files Browse the repository at this point in the history
- filter out bogus i2c readout results
- increase i2c timeout to increase readout reliability
- change init check to not rely on attiny init anymore
  • Loading branch information
arjenhiemstra committed Sep 15, 2021
1 parent 06a7fd5 commit 260c85b
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 26 deletions.
Binary file not shown.
1 change: 0 additions & 1 deletion software/NRG_itho_wifi/01_HTML.ino
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ void handleDebug(AsyncWebServerRequest *request) {
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("<br><br>");


request->send(response);

Expand Down
5 changes: 2 additions & 3 deletions software/NRG_itho_wifi/09_init_code.ino
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,10 @@ void i2cInit() {

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

void logInit() {
Expand Down
49 changes: 33 additions & 16 deletions software/NRG_itho_wifi/IthoSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ bool temp_hum_updated = false;
float ithoHum = 0;
float ithoTemp = 0;

const uint8_t itho_14v134[] {0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 102, 103, 255};
const uint8_t itho_14v2[] {0, 1, 2, 3, 4, 5, 6, 7, 102, 103, 255};
const uint8_t itho_14v14[] {0, 1, 2, 3, 4, 5, 6, 7, 102, 103, 255};
const uint8_t itho_14v5[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 26, 48, 49, 50, 51, 96, 52, 53, 97, 98, 99, 100, 101, 102, 103, 255};
const uint8_t itho_14v6[] {0, 1, 2, 3, 4, 5, 6, 7, 26, 48, 49, 50, 51, 96, 52, 53, 97, 98, 99, 100, 101, 102, 103, 255};

Expand All @@ -63,7 +62,7 @@ const uint8_t itho_1Bv25[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
const uint8_t itho_1Bv2627[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 255};


const uint8_t *ihto14Versions[] = { itho_14v134, itho_14v2, itho_14v134, itho_14v134, itho_14v5, itho_14v6 };
const uint8_t *ihto14Versions[] = { nullptr, itho_14v14, itho_14v14, itho_14v14, itho_14v14, itho_14v5, itho_14v6 };
const uint8_t *ihto1BVersions[] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, itho_1Bv6, itho_1Bv7, itho_1Bv8, itho_1Bv9, itho_1Bv10, itho_1Bv11, nullptr, nullptr, nullptr, nullptr, nullptr, itho_1Bv17, itho_1Bv1820, nullptr, itho_1Bv1820, itho_1Bv21, itho_1Bv22, nullptr, itho_1Bv24, itho_1Bv25, itho_1Bv2627, itho_1Bv2627 };

const uint8_t itho_14sv14[] {0, 1, 2, 3, 4, 5, 6, 255};
Expand All @@ -76,8 +75,8 @@ const uint8_t itho_1Bsv2021[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 255
const uint8_t itho_1Bsv22[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 255};
const uint8_t itho_1Bsv2427[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255};

const uint8_t *ihto14Status[] = { itho_14sv14, itho_14sv14, itho_14sv14, itho_14sv14, itho_1Bsv57, itho_1Bsv57 };
const uint8_t *ihto1BStatus[] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, itho_1Bsv57, itho_1Bsv57, itho_1Bsv8, itho_1Bsv911, itho_1Bsv911, itho_1Bsv911, nullptr, nullptr, nullptr, nullptr, nullptr, itho_1Bsv17, itho_1Bsv18, nullptr, itho_1Bsv2021, itho_1Bsv2021, itho_1Bsv22, nullptr, itho_1Bsv2427, itho_1Bsv2427, itho_1Bsv2427, itho_1Bsv2427 };
const uint8_t *ihto14Status[] = { nullptr, itho_14sv14, itho_14sv14, itho_14sv14, itho_14sv14, itho_1Bsv57, itho_1Bsv57, itho_1Bsv57 };
const uint8_t *ihto1BStatus[] = { nullptr, nullptr, nullptr, nullptr, nullptr, itho_1Bsv57, itho_1Bsv57, itho_1Bsv57, itho_1Bsv8, itho_1Bsv911, itho_1Bsv911, itho_1Bsv911, nullptr, nullptr, nullptr, nullptr, nullptr, itho_1Bsv17, itho_1Bsv18, nullptr, itho_1Bsv2021, itho_1Bsv2021, itho_1Bsv22, nullptr, itho_1Bsv2427, itho_1Bsv2427, itho_1Bsv2427, itho_1Bsv2427 };

struct ihtoDeviceType {
uint8_t ID;
Expand Down Expand Up @@ -523,6 +522,24 @@ uint8_t checksum(const uint8_t* buf, size_t buflen) {
}


void sendI2CPWMinit() {

uint8_t command[] = { 0x82, 0xEF, 0xC0, 0x00, 0x01, 0x06, 0x00, 0x00, 0x09, 0x00, 0x09, 0x00, 0xB6 };

command[sizeof(command) - 1] = checksum(command, sizeof(command) - 1);

while (digitalRead(SCLPIN) == LOW) {
yield();
delay(1);
}

#if defined (HW_VERSION_TWO)

i2c_sendBytes(command, sizeof(command));

#endif

}

uint8_t cmdCounter = 0;

Expand Down Expand Up @@ -663,7 +680,7 @@ void sendQueryDevicetype(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (len > 0) {
if (len > 2) {
jsonSysmessage("ithotype", i2cbuf2string(i2cbuf, len).c_str());
ithoDeviceID = i2cbuf[9];
itho_fwversion = i2cbuf[11];
Expand Down Expand Up @@ -697,7 +714,7 @@ void sendQueryStatusFormat(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (len > 0) {
if (len > 2) {
jsonSysmessage("ithostatusformat", i2cbuf2string(i2cbuf, len).c_str());

}
Expand Down Expand Up @@ -729,7 +746,7 @@ void sendQueryStatus(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (len > 0) {
if (len > 2) {
jsonSysmessage("ithostatus", i2cbuf2string(i2cbuf, len).c_str());

}
Expand Down Expand Up @@ -777,7 +794,7 @@ void sendQuery2400(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (len > 0) {
if (len > 2) {
if (i2c_result_updateweb) {
i2c_result_updateweb = false;
jsonSysmessage("itho2400", i2cbuf2string(i2cbuf, len).c_str());
Expand Down Expand Up @@ -873,10 +890,10 @@ void sendQuery2401(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);

itho2401len = len;
if (len > 0) {

if (len > 2) {

if (i2c_result_updateweb) {
i2c_result_updateweb = false;
Expand Down Expand Up @@ -963,7 +980,7 @@ void sendQuery31DA(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (len > 0) {
if (len > 2) {
jsonSysmessage("itho31DA", i2cbuf2string(i2cbuf, len).c_str());

}
Expand Down Expand Up @@ -993,7 +1010,7 @@ void sendQuery31D9(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (len > 0) {
if (len > 2) {
jsonSysmessage("itho31D9", i2cbuf2string(i2cbuf, len).c_str());
}
else {
Expand Down Expand Up @@ -1030,7 +1047,7 @@ int32_t * sendQuery2410(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (len > 0) {
if (len > 2) {

//current value
values[0] = i2cbuf[6] << 24; //6,7,8,9
Expand Down Expand Up @@ -1116,7 +1133,7 @@ void setSetting2410(bool i2c_result_updateweb) {

uint8_t i2cbuf[512] {};
size_t len = i2c_slave_receive(i2cbuf);
if (len > 0) {
if (len > 2) {
if (command[6] == i2cbuf[6] && command[7] == i2cbuf[7] && command[8] == i2cbuf[8] && command[9] == i2cbuf[9] && command[23] == i2cbuf[23]) {
jsonSysmessage("itho2410setres", "confirmed");
}
Expand Down
4 changes: 2 additions & 2 deletions software/NRG_itho_wifi/IthoSystem.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once

#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <Arduino.h>

extern size_t itho2401len;


extern uint8_t ithoDeviceID;
extern uint8_t itho_fwversion;
extern volatile uint16_t ithoCurrentVal;
Expand Down Expand Up @@ -64,6 +63,7 @@ void updateSetting(uint8_t i, int32_t value);
struct ihtoDeviceType* getSettingsPtr(uint8_t deviceID, uint8_t version);

uint8_t checksum(const uint8_t* buf, size_t buflen);
void sendI2CPWMinit();
void sendButton(uint8_t number, bool i2c_result_updateweb);
void sendJoinI2C(bool i2c_result_updateweb);
void sendLeaveI2C(bool i2c_result_updateweb);
Expand Down
2 changes: 1 addition & 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-alpha7"
#define FWVERSION "2.3-alpha8"

#define LOGGING_INTERVAL 21600000 //Log system status at regular intervals
#define ENABLE_FAILSAVE_BOOT
Expand Down
9 changes: 7 additions & 2 deletions software/NRG_itho_wifi/TaskSysControl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ void TaskSysControl( void * pvParameters ) {

void execSystemControlTasks() {

if (IthoInit) {
if (IthoInit && millis() > 250) {
IthoInit = ithoInitCheck();
}
#if defined (HW_VERSION_TWO)
if (!i2cStartCommands && millis() > 15000) {
sendQueryDevicetype(i2c_result_updateweb);

if (itho_fwversion > 0) {
ithoInitResult = 1;
}
else {
ithoInitResult = -1;
}
if (systemConfig.sysfirhum == 1 && ithoDeviceID == 0x1B) {
if (itho_fwversion == 25) {
updateSetting(63, 0);
Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/i2c_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ size_t i2c_slave_receive(uint8_t i2c_receive_buf[]) {

while (millis() < timeoutmillis) {
while (1) {
int len1 = i2c_slave_read_buffer(I2C_SLAVE_NUM, i2cbuf + buflen, sizeof(i2cbuf) - buflen, 10);
int len1 = i2c_slave_read_buffer(I2C_SLAVE_NUM, i2cbuf + buflen, sizeof(i2cbuf) - buflen, 100);
if (len1 <= 0)
break;
buflen += len1;
Expand Down

0 comments on commit 260c85b

Please sign in to comment.