From 08f251bc635a46f16352738bec25b48082dacc75 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Mon, 27 Apr 2020 02:25:43 +0300 Subject: [PATCH] 1wire error handling --- lighthub/item.cpp | 6 +++--- lighthub/owTerm.cpp | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 7c9afb6..2257bf3 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -1825,7 +1825,7 @@ int Item::SendStatus(int sendFlags) { } //publish to MQTT - OpenHab Legacy style to myhome/s_out/item flat values setTopic(addrstr,sizeof(addrstr),T_OUT); - strncat(addrstr, itemArr->name, sizeof(addrstr)); + strncat(addrstr, itemArr->name, sizeof(addrstr)-1); if (mqttClient.connected() && !ethernetIdleCount) { @@ -1855,7 +1855,7 @@ int Item::SendStatus(int sendFlags) { if (sendFlags & SEND_PARAMETERS) { setTopic(addrstr,sizeof(addrstr),T_OUT); - strncat(addrstr, itemArr->name, sizeof(addrstr)); + strncat(addrstr, itemArr->name, sizeof(addrstr)-1); strncat(addrstr, "/", sizeof(addrstr)); strncat_P(addrstr, SET_P, sizeof(addrstr)); @@ -1893,7 +1893,7 @@ int Item::SendStatus(int sendFlags) { } setTopic(addrstr,sizeof(addrstr),T_OUT); - strncat(addrstr, itemArr->name, sizeof(addrstr)); + strncat(addrstr, itemArr->name, sizeof(addrstr)-1); strncat(addrstr, "/", sizeof(addrstr)); strncat_P(addrstr, CMD_P, sizeof(addrstr)); diff --git a/lighthub/owTerm.cpp b/lighthub/owTerm.cpp index 8bc24ae..6589bcc 100644 --- a/lighthub/owTerm.cpp +++ b/lighthub/owTerm.cpp @@ -42,9 +42,13 @@ owChangedType owChanged; int owUpdate() { #ifndef OWIRE_DISABLE unsigned long finish = millis() + OW_UPDATE_INTERVAL; - short sr; - - +/* + if (oneWire->getError() == DS2482_ERROR_SHORT) + { + debugSerial<reset_search(); for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent @@ -78,6 +82,7 @@ int owUpdate() { debugSerial<wireReset()) debugSerial.println(F("\tReset done")); + if (oneWire->getError() == DS2482_ERROR_SHORT) + { + debugSerial<begin(); owChanged = owCh; //owUpdate(); @@ -141,7 +152,13 @@ int owSetup(owChangedType owCh) { int sensors_loop(void) { - if (!sensors) return -1; + if (!sensors) return 100000; + if (oneWire->getError() == DS2482_ERROR_SHORT) + { + debugSerial<= t_count) { owUpdate(); //every check circle - scan for new devices si = 0;