mirror of
https://github.com/anklimov/lighthub
synced 2025-12-11 22:29:51 +03:00
Modbus v2 initialization fixed
This commit is contained in:
@@ -1002,7 +1002,7 @@ configLocked++;
|
||||
if (cmd<1) it.setCmd(CMD_OFF);
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, false); //Initially, all thermostates are LOW (OFF for electho heaters, open for water NO)
|
||||
debugSerial<<F("Thermo:")<<pin<<F("=LOW")<<F(",");
|
||||
debugSerial<<F("Thermo:")<<pin<<F("=LOW")<<F(";");
|
||||
break;
|
||||
case CH_RELAY:
|
||||
{
|
||||
@@ -1012,7 +1012,7 @@ configLocked++;
|
||||
digitalWrite(pin, k = ((cmd == CMD_ON) ? LOW : HIGH));
|
||||
else
|
||||
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
||||
debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(",");
|
||||
debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(";");
|
||||
}
|
||||
break;
|
||||
} //switch
|
||||
@@ -1022,6 +1022,7 @@ configLocked++;
|
||||
} //if
|
||||
pollingItem = items->child;
|
||||
}
|
||||
debugSerial<<endl;
|
||||
inputs = aJson.getObjectItem(root, "in");
|
||||
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||
|
||||
@@ -1039,8 +1040,12 @@ void printConfigSummary() {
|
||||
printBool(items);
|
||||
infoSerial<<F("\ninputs ");
|
||||
printBool(inputs);
|
||||
#ifdef _modbus
|
||||
infoSerial<<F("\nmodbus ");
|
||||
#ifndef MODBUS_DISABLE
|
||||
infoSerial<<F("\nmodbus v1 (+)");
|
||||
// printBool(modbusObj);
|
||||
#endif
|
||||
#ifndef MBUS_DISABLE
|
||||
infoSerial<<F("\nmodbus v2");
|
||||
printBool(modbusObj);
|
||||
#endif
|
||||
infoSerial<<F("\nmqtt ");
|
||||
|
||||
@@ -66,6 +66,8 @@
|
||||
|
||||
#include "streamlog.h"
|
||||
extern Streamlog debugSerial;
|
||||
extern Streamlog infoSerial;
|
||||
extern Streamlog errorSerial;
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#define wdt_res() watchdogReset()
|
||||
|
||||
@@ -96,15 +96,21 @@ int str2regSize(char * str)
|
||||
bool out_Modbus::getConfig()
|
||||
{
|
||||
// Retrieve and store template values from global modbus settings
|
||||
if (!store || !item || !item->itemArg || (item->itemArg->type != aJson_Array) || aJson.getArraySize(item->itemArg)<2) return false;
|
||||
|
||||
if (!store || !item || !item->itemArg || (item->itemArg->type != aJson_Array) || aJson.getArraySize(item->itemArg)<2)
|
||||
{
|
||||
errorSerial<<F("MBUS: config failed:")<<(bool)store<<F(",")<<(bool)item<<F(",")<<(bool)item->itemArg<<F(",")<<(item->itemArg->type != aJson_Array)<<F(",")<< (aJson.getArraySize(item->itemArg)<2)<<endl;
|
||||
return false;
|
||||
}
|
||||
aJsonObject * templateIdObj = aJson.getArrayItem(item->itemArg, 1);
|
||||
if (templateIdObj->type != aJson_String || !templateIdObj->valuestring) return false;
|
||||
|
||||
if (templateIdObj->type != aJson_String || !templateIdObj->valuestring)
|
||||
{
|
||||
errorSerial<<F("Invalid template.")<<endl;
|
||||
return false;
|
||||
}
|
||||
aJsonObject * templateObj = aJson.getObjectItem(modbusObj, templateIdObj->valuestring);
|
||||
if (! templateObj)
|
||||
{
|
||||
debugSerial<<F("Modbus template not found: ")<<templateIdObj->valuestring<<endl;
|
||||
errorSerial<<F("Modbus template not found: ")<<templateIdObj->valuestring<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -124,7 +130,7 @@ bool out_Modbus::getConfig()
|
||||
else {store->pollingRegisters=NULL;store->pollingInterval = 1000;}
|
||||
|
||||
store->parameters=aJson.getObjectItem(templateObj, "par");
|
||||
|
||||
return true;
|
||||
//store->addr=item->getArg(0);
|
||||
}
|
||||
|
||||
@@ -132,18 +138,21 @@ bool out_Modbus::getConfig()
|
||||
int out_Modbus::Setup()
|
||||
{
|
||||
if (!store) store= (mbPersistent *)item->setPersistent(new mbPersistent);
|
||||
if (!store) return 0;
|
||||
if (!store)
|
||||
{ errorSerial<<F("MBUS: Out of memory")<<endl;
|
||||
return 0;}
|
||||
|
||||
store->timestamp=millis();
|
||||
if (getConfig())
|
||||
{
|
||||
//item->clearFlag(ACTION_NEEDED);
|
||||
//item->clearFlag(ACTION_IN_PROCESS);
|
||||
debugSerial<<F("Modbus config loaded ")<< item->itemArr->name<<endl;
|
||||
infoSerial<<F("Modbus config loaded ")<< item->itemArr->name<<endl;
|
||||
store->driverStatus = CST_INITIALIZED;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{ debugSerial<<F("Modbus config error")<<endl;
|
||||
{ errorSerial<<F("Modbus config error")<<endl;
|
||||
store->driverStatus = CST_FAILED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user