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