mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 03:39:49 +03:00
1-wire errors/reset improved, cleaned up
This commit is contained in:
@@ -1236,51 +1236,6 @@ void resetHard() {
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _owire
|
||||
/*
|
||||
void Changed(int i, DeviceAddress addr, float currentTemp) {
|
||||
char addrstr[32] = "NIL";
|
||||
//char addrbuf[17];
|
||||
//char valstr[16] = "NIL";
|
||||
//char *owEmitString = NULL;
|
||||
//char *owItem = NULL;
|
||||
|
||||
SetBytes(addr, 8, addrstr);
|
||||
addrstr[17] = 0;
|
||||
if (!root) return;
|
||||
aJsonObject *owObj = aJson.getObjectItem(owArr, addrstr);
|
||||
|
||||
if (i<0) //just print note about address
|
||||
{
|
||||
if (owObj && owObj->child && owObj->child->type==aJson_String && owObj->child->valuestring)
|
||||
debugSerial<<F(" ")<<owObj->child->valuestring<<F(" ");
|
||||
return;
|
||||
}
|
||||
|
||||
debugSerial<<endl<<F("T:")<<currentTemp<<F("<")<<addrstr<<F(">")<<endl;
|
||||
if ((currentTemp != -127.0) && (currentTemp != 85.0) && (currentTemp != 0.0))
|
||||
executeCommand(owObj,-1,itemCmd(currentTemp).setSuffix(S_VAL));
|
||||
else
|
||||
if (owObj && owObj->child && owObj->child->type==aJson_String && owObj->child->valuestring)
|
||||
errorSerial<<F("Read error for ")<<owObj->child->valuestring<<endl;
|
||||
|
||||
////
|
||||
#ifdef WITH_DOMOTICZ
|
||||
aJsonObject *idx = aJson.getObjectItem(owObj, "idx");
|
||||
if (idx && && idx->type ==aJson_String && idx->valuestring) {//DOMOTICZ json format support
|
||||
debugSerial << endl << idx->valuestring << F(" Domoticz valstr:");
|
||||
char valstr[50];
|
||||
sprintf(valstr, "{\"idx\":%s,\"svalue\":\"%.1f\"}", idx->valuestring, currentTemp);
|
||||
debugSerial << valstr;
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(owEmitString, valstr);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
////
|
||||
}
|
||||
*/
|
||||
#endif //_owire
|
||||
|
||||
int cmdFunctionHelp(int arg_cnt, char **args)
|
||||
{
|
||||
@@ -1329,7 +1284,7 @@ return 500;
|
||||
}
|
||||
|
||||
int cmdFunctionSearch(int arg_cnt, char **args) {
|
||||
infoSerial<<F("searching");
|
||||
//infoSerial<<F("searching");
|
||||
owSearch();
|
||||
return 200;
|
||||
}
|
||||
@@ -1400,20 +1355,6 @@ setupSyslog();
|
||||
aJsonObject *item = owArr->child;
|
||||
owReady = owSetup();
|
||||
if (owReady) infoSerial<<F("One wire Ready\n");
|
||||
/// t_count = 0;
|
||||
/*
|
||||
while (item && owReady) {
|
||||
if ((item->type == aJson_Object)) {
|
||||
DeviceAddress addr;
|
||||
//infoSerial<<F("Add:")),infoSerial<<item->name);
|
||||
SetAddr(item->name, addr);
|
||||
owAdd(addr);
|
||||
}
|
||||
yield();
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -31,18 +31,10 @@ extern aJsonObject *owArr;
|
||||
aJsonObject *dev2Check = NULL;
|
||||
|
||||
OneWire *oneWire = NULL;
|
||||
|
||||
//DeviceAddress *term = NULL;
|
||||
//uint16_t *wstat = NULL;
|
||||
|
||||
DallasTemperature *sensors = NULL;
|
||||
|
||||
//short si = 0;
|
||||
//int t_count = 0;
|
||||
unsigned long owTimer = 0;
|
||||
|
||||
//owChangedType owChanged;
|
||||
|
||||
void owSearch()
|
||||
{
|
||||
owUpdate();
|
||||
@@ -55,7 +47,7 @@ bool zero(const uint8_t *addr, uint8_t len)
|
||||
return true;
|
||||
}
|
||||
|
||||
char * getReableNote(aJsonObject * owObj)
|
||||
char * getReadableNote(aJsonObject * owObj)
|
||||
{
|
||||
if (owObj && owObj->child)
|
||||
{
|
||||
@@ -67,7 +59,7 @@ char * getReableNote(aJsonObject * owObj)
|
||||
}
|
||||
void processTemp(aJsonObject * owObj, float currentTemp) {
|
||||
if (!owObj || !owArr) return;
|
||||
char* note = getReableNote(owObj);
|
||||
char* note = getReadableNote(owObj);
|
||||
debugSerial<<endl<<F("1WT:")<<currentTemp<<F(" <")<<owObj->name<<F("> ");
|
||||
if ((currentTemp != -127.0) && (currentTemp != 85.0) && (currentTemp != 0.0))
|
||||
{
|
||||
@@ -76,7 +68,7 @@ void processTemp(aJsonObject * owObj, float currentTemp) {
|
||||
executeCommand(owObj,-1,itemCmd(currentTemp).setSuffix(S_VAL));
|
||||
}
|
||||
else
|
||||
if (note) errorSerial<<F("1WT: Read error for ")<<note<<endl;
|
||||
if (note) debugSerial<<F(" read error for ")<<note<<endl;
|
||||
|
||||
/*
|
||||
#ifdef WITH_DOMOTICZ
|
||||
@@ -98,32 +90,29 @@ void processTemp(aJsonObject * owObj, float currentTemp) {
|
||||
int owUpdate() {
|
||||
#ifndef OWIRE_DISABLE
|
||||
DeviceAddress dev;
|
||||
//unsigned long finish = millis();// + OW_UPDATE_INTERVAL;
|
||||
if (!oneWire || !owArr) return 0;
|
||||
oneWire->reset_search();
|
||||
debugSerial << F("1WT: Searching dev")<<endl;
|
||||
infoSerial << F("1WT: Searching dev")<<endl;
|
||||
while (oneWire->wireSearch(dev) > 0)
|
||||
{
|
||||
wdt_res();
|
||||
char addrstr[17];
|
||||
SetBytes(dev, 8, addrstr);
|
||||
addrstr[16] = 0;
|
||||
aJsonObject * owObj=aJson.getObjectItem(owArr,addrstr);
|
||||
debugSerial<<F("1WT:")<<addrstr;
|
||||
infoSerial<<F("1WT:")<<addrstr;
|
||||
if (owObj)
|
||||
{
|
||||
char * note = getReableNote(owObj);
|
||||
if (note) debugSerial<<F(" is ")<<note<<endl;
|
||||
char * note = getReadableNote(owObj);
|
||||
if (note) infoSerial<<F(" is ")<<note<<endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
debugSerial<<F(" new")<<endl;
|
||||
infoSerial<<F(" new")<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
if (oneWire) oneWire->reset_search();
|
||||
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||
|
||||
@@ -183,15 +172,10 @@ int owSetup() {
|
||||
|
||||
if (!oneWire)
|
||||
{
|
||||
errorSerial<<F("Error 1-w init #1")<<endl;
|
||||
errorSerial<<F("Error 1-w init")<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
// sensors = new DallasTemperature(oneWire);
|
||||
|
||||
/*
|
||||
term = new DeviceAddress[t_max];
|
||||
debugSerial<<F("Term. Free:")<<freeRam()<<endl;
|
||||
@@ -203,7 +187,6 @@ if (!term || ! wstat)
|
||||
errorSerial<<F("Error 1-w init #2 Free:")<<freeRam()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
owChanged = owCh;
|
||||
*/
|
||||
|
||||
@@ -223,8 +206,8 @@ if (!term || ! wstat)
|
||||
debugSerial.println(F("\tReset done"));
|
||||
return true;
|
||||
}
|
||||
debugSerial.println(F("\tDS2482 error"));
|
||||
return false;
|
||||
debugSerial.println(F("\tDS2482 reset error"));
|
||||
return true;
|
||||
#else
|
||||
// software driver
|
||||
oneWire->reset();
|
||||
@@ -239,12 +222,33 @@ return false;
|
||||
|
||||
int sensors_loop(void) {
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
if (oneWire->getError() == DS2482_ERROR_SHORT)
|
||||
{
|
||||
debugSerial<<F("1-wire shorted")<<endl;
|
||||
oneWire->wireReset();
|
||||
return 10000;
|
||||
}
|
||||
switch (oneWire->getError())
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case DS2482_ERROR_SHORT:
|
||||
errorSerial<<F("1WT: 1-wire shorted")<<endl;
|
||||
oneWire->wireReset();
|
||||
return INTERVAL_1W;
|
||||
|
||||
case DS2482_ERROR_CONFIG:
|
||||
errorSerial<<F("1WT: DS2482_ERROR_CONFIG")<<endl;
|
||||
oneWire->wireReset();
|
||||
return INTERVAL_1W;
|
||||
|
||||
case DS2482_ERROR_TIMEOUT:
|
||||
errorSerial<<F("1WT: 1-wire shorted")<<endl;
|
||||
oneWire->wireReset();
|
||||
return INTERVAL_1W;
|
||||
|
||||
default:
|
||||
errorSerial<<F("1WT: error")<<endl;
|
||||
oneWire->wireReset();
|
||||
return INTERVAL_1W;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -261,7 +265,6 @@ if (!sensors)
|
||||
|
||||
if (!dev2Check && owArr)
|
||||
{
|
||||
|
||||
if (owArr && owArr->type == aJson_Object && owArr->child) dev2Check = owArr->child;
|
||||
///owUpdate(); //every check circle - scan for new devices
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ e-mail anklimov@gmail.com
|
||||
#define SW_MASK 0xF
|
||||
#define SW_INMASK 0xFC
|
||||
|
||||
#define recheck_interval 5
|
||||
//#define recheck_interval 5
|
||||
//#define check_circle 2000/t_count
|
||||
|
||||
#define SW_FIND 1
|
||||
@@ -79,24 +79,12 @@ extern aJsonObject *owArr;
|
||||
|
||||
|
||||
extern OneWire *oneWire;
|
||||
|
||||
extern DallasTemperature *sensors;
|
||||
//extern DeviceAddress *term ;
|
||||
//extern int *regs ;
|
||||
//extern uint16_t *wstat;
|
||||
//extern int t_count;
|
||||
//extern short si;
|
||||
|
||||
//extern owChangedType owChanged;
|
||||
|
||||
|
||||
|
||||
int owUpdate();
|
||||
int owSetup();
|
||||
void owLoop();
|
||||
void setupOwIdle(void (*)()) ;
|
||||
//int owFind(DeviceAddress addr);
|
||||
//void owAdd (DeviceAddress addr);
|
||||
void owSearch();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user