mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
Modbus v2 initialization fixed
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
#-DAVR_DMXOUT_PIN=18
|
#-DAVR_DMXOUT_PIN=18
|
||||||
-DDMX_DISABLE
|
-DDMX_DISABLE
|
||||||
-DMODBUS_DISABLE
|
-DMODBUS_DISABLE
|
||||||
-DMBUS_DISABLE
|
#-DMBUS_DISABLE
|
||||||
#-DOWIRE_DISABLE
|
#-DOWIRE_DISABLE
|
||||||
-DDHT_DISABLE
|
-DDHT_DISABLE
|
||||||
-DCOUNTER_DISABLE
|
-DCOUNTER_DISABLE
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1002,7 +1002,7 @@ configLocked++;
|
|||||||
if (cmd<1) it.setCmd(CMD_OFF);
|
if (cmd<1) it.setCmd(CMD_OFF);
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
digitalWrite(pin, false); //Initially, all thermostates are LOW (OFF for electho heaters, open for water NO)
|
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;
|
break;
|
||||||
case CH_RELAY:
|
case CH_RELAY:
|
||||||
{
|
{
|
||||||
@@ -1012,7 +1012,7 @@ configLocked++;
|
|||||||
digitalWrite(pin, k = ((cmd == CMD_ON) ? LOW : HIGH));
|
digitalWrite(pin, k = ((cmd == CMD_ON) ? LOW : HIGH));
|
||||||
else
|
else
|
||||||
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
||||||
debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(",");
|
debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(";");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} //switch
|
} //switch
|
||||||
@@ -1022,6 +1022,7 @@ configLocked++;
|
|||||||
} //if
|
} //if
|
||||||
pollingItem = items->child;
|
pollingItem = items->child;
|
||||||
}
|
}
|
||||||
|
debugSerial<<endl;
|
||||||
inputs = aJson.getObjectItem(root, "in");
|
inputs = aJson.getObjectItem(root, "in");
|
||||||
mqttArr = aJson.getObjectItem(root, "mqtt");
|
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||||
|
|
||||||
@@ -1039,8 +1040,12 @@ void printConfigSummary() {
|
|||||||
printBool(items);
|
printBool(items);
|
||||||
infoSerial<<F("\ninputs ");
|
infoSerial<<F("\ninputs ");
|
||||||
printBool(inputs);
|
printBool(inputs);
|
||||||
#ifdef _modbus
|
#ifndef MODBUS_DISABLE
|
||||||
infoSerial<<F("\nmodbus ");
|
infoSerial<<F("\nmodbus v1 (+)");
|
||||||
|
// printBool(modbusObj);
|
||||||
|
#endif
|
||||||
|
#ifndef MBUS_DISABLE
|
||||||
|
infoSerial<<F("\nmodbus v2");
|
||||||
printBool(modbusObj);
|
printBool(modbusObj);
|
||||||
#endif
|
#endif
|
||||||
infoSerial<<F("\nmqtt ");
|
infoSerial<<F("\nmqtt ");
|
||||||
|
|||||||
@@ -66,6 +66,8 @@
|
|||||||
|
|
||||||
#include "streamlog.h"
|
#include "streamlog.h"
|
||||||
extern Streamlog debugSerial;
|
extern Streamlog debugSerial;
|
||||||
|
extern Streamlog infoSerial;
|
||||||
|
extern Streamlog errorSerial;
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
#define wdt_res() watchdogReset()
|
#define wdt_res() watchdogReset()
|
||||||
|
|||||||
@@ -96,15 +96,21 @@ int str2regSize(char * str)
|
|||||||
bool out_Modbus::getConfig()
|
bool out_Modbus::getConfig()
|
||||||
{
|
{
|
||||||
// Retrieve and store template values from global modbus settings
|
// 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);
|
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);
|
aJsonObject * templateObj = aJson.getObjectItem(modbusObj, templateIdObj->valuestring);
|
||||||
if (! templateObj)
|
if (! templateObj)
|
||||||
{
|
{
|
||||||
debugSerial<<F("Modbus template not found: ")<<templateIdObj->valuestring<<endl;
|
errorSerial<<F("Modbus template not found: ")<<templateIdObj->valuestring<<endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +130,7 @@ bool out_Modbus::getConfig()
|
|||||||
else {store->pollingRegisters=NULL;store->pollingInterval = 1000;}
|
else {store->pollingRegisters=NULL;store->pollingInterval = 1000;}
|
||||||
|
|
||||||
store->parameters=aJson.getObjectItem(templateObj, "par");
|
store->parameters=aJson.getObjectItem(templateObj, "par");
|
||||||
|
return true;
|
||||||
//store->addr=item->getArg(0);
|
//store->addr=item->getArg(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,18 +138,21 @@ bool out_Modbus::getConfig()
|
|||||||
int out_Modbus::Setup()
|
int out_Modbus::Setup()
|
||||||
{
|
{
|
||||||
if (!store) store= (mbPersistent *)item->setPersistent(new mbPersistent);
|
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();
|
store->timestamp=millis();
|
||||||
if (getConfig())
|
if (getConfig())
|
||||||
{
|
{
|
||||||
//item->clearFlag(ACTION_NEEDED);
|
//item->clearFlag(ACTION_NEEDED);
|
||||||
//item->clearFlag(ACTION_IN_PROCESS);
|
//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;
|
store->driverStatus = CST_INITIALIZED;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ debugSerial<<F("Modbus config error")<<endl;
|
{ errorSerial<<F("Modbus config error")<<endl;
|
||||||
store->driverStatus = CST_FAILED;
|
store->driverStatus = CST_FAILED;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ lib_deps =
|
|||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
board = megaatmega2560
|
board = megaatmega2560
|
||||||
;upload_port = net:192.168.88.31:23
|
;upload_port = net:192.168.88.31:23
|
||||||
upload_port = net:192.168.88.2:23000
|
;upload_port = net:192.168.88.2:23000
|
||||||
framework = arduino
|
framework = arduino
|
||||||
build_flags = !python get_build_flags.py mega2560slim-5100
|
build_flags = !python get_build_flags.py mega2560slim-5100
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
|
|||||||
Reference in New Issue
Block a user