mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
new interface class itemCmd as interface between objects
Modbus polling->MQTT syslog fix different level of logging infoSerial errorSerial
This commit is contained in:
1
compiled/lighthub21/uploadOTA.sh
Executable file
1
compiled/lighthub21/uploadOTA.sh
Executable file
@@ -0,0 +1 @@
|
|||||||
|
../tools/mac/arduinoOTA -address 192.168.88.59 -port 65280 -username arduino -password password -sketch firmware.bin -b -upload /sketch
|
||||||
@@ -54,12 +54,91 @@ extern lan_status lanStatus;
|
|||||||
|
|
||||||
int retrieveCode(char **psubItem);
|
int retrieveCode(char **psubItem);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
itemCmd itemCmd::Percents(int i)
|
||||||
|
{
|
||||||
|
type=ST_PERCENTS;
|
||||||
|
param.aslong=i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::Int(int32_t i)
|
||||||
|
{
|
||||||
|
type=ST_INT32;
|
||||||
|
param.asInt32=i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::Int(uint32_t i)
|
||||||
|
{
|
||||||
|
type=ST_UINT32;
|
||||||
|
param.asUint32=i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
itemCmd itemCmd::Cmd(uint8_t i)
|
||||||
|
{
|
||||||
|
type=ST_COMMAND;
|
||||||
|
param.cmd_code=i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
char * itemCmd::toString(char * Buffer, int bufLen)
|
||||||
|
{
|
||||||
|
if (!Buffer) return NULL;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ST_VOID:
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
case ST_PERCENTS:
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
case ST_UINT32:
|
||||||
|
snprintf(Buffer, bufLen, "%u", param.asUint32);
|
||||||
|
break;
|
||||||
|
case ST_INT32:
|
||||||
|
snprintf(Buffer, bufLen, "%d", param.asInt32);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ST_HS:
|
||||||
|
case ST_HSV:
|
||||||
|
case ST_HSV255:
|
||||||
|
snprintf(Buffer, bufLen, "%d,%d,%d", param.h, param.s, param.v);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ST_FLOAT_CELSIUS:
|
||||||
|
case ST_FLOAT_FARENHEIT:
|
||||||
|
case ST_FLOAT:
|
||||||
|
snprintf(Buffer, bufLen, "%d", param.asfloat);
|
||||||
|
break;
|
||||||
|
case ST_RGB:
|
||||||
|
snprintf(Buffer, bufLen, "%d,%d,%d", param.r, param.g, param.b);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ST_RGBW:
|
||||||
|
snprintf(Buffer, bufLen, "%d,%d,%d", param.r, param.g, param.b,param.w);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ST_STRING:
|
||||||
|
strncpy(Buffer, param.asString,bufLen);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ST_COMMAND:
|
||||||
|
strncpy_P(Buffer, commands_P[param.cmd_code], bufLen);
|
||||||
|
}
|
||||||
|
return Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
int txt2cmd(char *payload) {
|
int txt2cmd(char *payload) {
|
||||||
int cmd = CMD_UNKNOWN;
|
int cmd = CMD_UNKNOWN;
|
||||||
|
if (!payload || !payload[0]) return cmd;
|
||||||
|
|
||||||
// Check for command
|
// Check for command
|
||||||
if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = CMD_NUM;
|
if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = CMD_NUM;
|
||||||
else if (*payload == '%') cmd = CMD_UP;
|
else if (*payload == '%') cmd = CMD_UP;
|
||||||
|
/*
|
||||||
else if (strcmp_P(payload, ON_P) == 0) cmd = CMD_ON;
|
else if (strcmp_P(payload, ON_P) == 0) cmd = CMD_ON;
|
||||||
else if (strcmp_P(payload, OFF_P) == 0) cmd = CMD_OFF;
|
else if (strcmp_P(payload, OFF_P) == 0) cmd = CMD_OFF;
|
||||||
else if (strcmp_P(payload, REST_P) == 0) cmd = CMD_RESTORE;
|
else if (strcmp_P(payload, REST_P) == 0) cmd = CMD_RESTORE;
|
||||||
@@ -81,10 +160,26 @@ int txt2cmd(char *payload) {
|
|||||||
else if (strcmp_P(payload, HIGH_P) == 0) cmd = CMD_HIGH;
|
else if (strcmp_P(payload, HIGH_P) == 0) cmd = CMD_HIGH;
|
||||||
else if (strcmp_P(payload, MED_P) == 0) cmd = CMD_MED;
|
else if (strcmp_P(payload, MED_P) == 0) cmd = CMD_MED;
|
||||||
else if (strcmp_P(payload, LOW_P) == 0) cmd = CMD_LOW;
|
else if (strcmp_P(payload, LOW_P) == 0) cmd = CMD_LOW;
|
||||||
|
*/
|
||||||
else if (*payload == '{') cmd = CMD_JSON;
|
else if (*payload == '{') cmd = CMD_JSON;
|
||||||
else if (*payload == '#') cmd = CMD_RGB;
|
else if (*payload == '#') cmd = CMD_RGB;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(uint8_t i=1; i<commandsNum ;i++)
|
||||||
|
if (strcmp_P(payload, commands_P[i]) == 0)
|
||||||
|
{
|
||||||
|
// debugSerial<< i << F(" ") << pgm_read_word_near(&serialModes_P[i].mode)<< endl;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
// debugSerial<< F("Default serial mode N81 used");
|
||||||
|
// return static_cast<uint16_t> (SERIAL_8N1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
else if (strncmp_P(payload, HSV_P, strlen (HSV_P)) == 0) cmd = CMD_HSV;
|
else if (strncmp_P(payload, HSV_P, strlen (HSV_P)) == 0) cmd = CMD_HSV;
|
||||||
else if (strncmp_P(payload, RGB_P, strlen (RGB_P)) == 0) cmd = CMD_RGB;
|
else if (strncmp_P(payload, RGB_P, strlen (RGB_P)) == 0) cmd = CMD_RGB;
|
||||||
|
*/
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,8 +61,18 @@ e-mail anklimov@gmail.com
|
|||||||
#define CMD_NUM 0
|
#define CMD_NUM 0
|
||||||
#define CMD_UNKNOWN -1
|
#define CMD_UNKNOWN -1
|
||||||
#define CMD_JSON -2
|
#define CMD_JSON -2
|
||||||
#define CMD_RGB -3
|
//#define CMD_RGB -3
|
||||||
#define CMD_HSV -4
|
//#define CMD_HSV -4
|
||||||
|
|
||||||
|
typedef char cmdstr[9];
|
||||||
|
|
||||||
|
const cmdstr commands_P[] PROGMEM =
|
||||||
|
{
|
||||||
|
"","ON","OFF","RESTORE","TOGGLE","HALT","XON","XOFF","INCREASE","DECREASE",
|
||||||
|
"HEAT","COOL","AUTO","FAN_ONLY","DRY","STOP","HIGH","MEDIUM","LOW",
|
||||||
|
"TRUE","FALSE","ENABLED","DISABLED","RGB","HSV"
|
||||||
|
};
|
||||||
|
#define commandsNum sizeof(commands_P)/sizeof(cmdstr)
|
||||||
|
|
||||||
#define CMD_ON 1
|
#define CMD_ON 1
|
||||||
#define CMD_OFF 2
|
#define CMD_OFF 2
|
||||||
@@ -78,10 +88,16 @@ e-mail anklimov@gmail.com
|
|||||||
#define CMD_AUTO 0xc
|
#define CMD_AUTO 0xc
|
||||||
#define CMD_FAN 0xd
|
#define CMD_FAN 0xd
|
||||||
#define CMD_DRY 0xe
|
#define CMD_DRY 0xe
|
||||||
//#define CMD_SET 0xf
|
#define CMD_STOP 0xf
|
||||||
#define CMD_HIGH 0x10 //AC fan leve
|
#define CMD_HIGH 0x10 //AC fan leve
|
||||||
#define CMD_MED 0x11
|
#define CMD_MED 0x11
|
||||||
#define CMD_LOW 0x12
|
#define CMD_LOW 0x12
|
||||||
|
#define CMD_ENABLED 0x13
|
||||||
|
#define CMD_DISABLED 0x14
|
||||||
|
#define CMD_TRUE 0x15
|
||||||
|
#define CMD_FALSE 0x16
|
||||||
|
#define CMD_RGB 0x17
|
||||||
|
#define CMD_HSV 0x18
|
||||||
//#define CMD_CURTEMP 0xf
|
//#define CMD_CURTEMP 0xf
|
||||||
#define CMD_MASK 0xff
|
#define CMD_MASK 0xff
|
||||||
#define FLAG_MASK 0xff00
|
#define FLAG_MASK 0xff00
|
||||||
@@ -94,6 +110,10 @@ e-mail anklimov@gmail.com
|
|||||||
#define ACTION_NEEDED 0x1000
|
#define ACTION_NEEDED 0x1000
|
||||||
#define ACTION_IN_PROCESS 0x2000
|
#define ACTION_IN_PROCESS 0x2000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#define CMD_REPORT 32
|
//#define CMD_REPORT 32
|
||||||
|
|
||||||
#define I_TYPE 0 //Type of item
|
#define I_TYPE 0 //Type of item
|
||||||
@@ -130,7 +150,12 @@ ST_FLOAT_FARENHEIT= 5,
|
|||||||
ST_RGB = 6,
|
ST_RGB = 6,
|
||||||
ST_RGBW = 7,
|
ST_RGBW = 7,
|
||||||
ST_PERCENTS255 = 8,
|
ST_PERCENTS255 = 8,
|
||||||
ST_HSV255 = 9
|
ST_HSV255 = 9,
|
||||||
|
ST_INT32 = 10,
|
||||||
|
ST_UINT32 = 11,
|
||||||
|
ST_STRING = 12,
|
||||||
|
ST_FLOAT = 13,
|
||||||
|
ST_COMMAND = 15
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -138,7 +163,17 @@ ST_HSV255 = 9
|
|||||||
typedef union
|
typedef union
|
||||||
{
|
{
|
||||||
long int aslong;
|
long int aslong;
|
||||||
|
int32_t asInt32;
|
||||||
|
uint32_t asUint32;
|
||||||
|
char* asString;
|
||||||
float asfloat;
|
float asfloat;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t cmd_code;
|
||||||
|
uint8_t cmd_flag;
|
||||||
|
uint8_t cmd_effect;
|
||||||
|
uint8_t cmd_effect_param;
|
||||||
|
};
|
||||||
struct
|
struct
|
||||||
{ uint8_t v;
|
{ uint8_t v;
|
||||||
uint8_t s;
|
uint8_t s;
|
||||||
@@ -155,14 +190,18 @@ typedef union
|
|||||||
};
|
};
|
||||||
} itemStore;
|
} itemStore;
|
||||||
|
|
||||||
/*
|
class itemCmd
|
||||||
typedef union
|
|
||||||
{
|
{
|
||||||
long int aslong;
|
public:
|
||||||
struct
|
itemStoreType type;
|
||||||
|
itemStore param;
|
||||||
|
itemCmd Percents(int i);
|
||||||
|
itemCmd Int(int32_t i);
|
||||||
|
itemCmd Int(uint32_t i);
|
||||||
|
itemCmd Cmd(uint8_t i);
|
||||||
|
char * toString(char * Buffer, int bufLen);
|
||||||
|
} ;
|
||||||
|
|
||||||
} RGBWstore;
|
|
||||||
*/
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ EthernetClient ethClient;
|
|||||||
EthernetUDP udpSyslogClient;
|
EthernetUDP udpSyslogClient;
|
||||||
Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_BSD);
|
Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_BSD);
|
||||||
unsigned long nextSyslogPingTime;
|
unsigned long nextSyslogPingTime;
|
||||||
|
static char syslogDeviceHostname[16];
|
||||||
|
|
||||||
Streamlog debugSerial(&debugSerialPort,LOG_DEBUG,&udpSyslog);
|
Streamlog debugSerial(&debugSerialPort,LOG_DEBUG,&udpSyslog);
|
||||||
Streamlog errorSerial(&debugSerialPort,LOG_ERROR,&udpSyslog);
|
Streamlog errorSerial(&debugSerialPort,LOG_ERROR,&udpSyslog);
|
||||||
@@ -329,14 +330,14 @@ else
|
|||||||
|
|
||||||
|
|
||||||
void printMACAddress() {
|
void printMACAddress() {
|
||||||
debugSerial<<F("MAC:");
|
infoSerial<<F("MAC:");
|
||||||
for (byte i = 0; i < 6; i++)
|
for (byte i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
if (mac[i]<16) debugSerial<<"0";
|
if (mac[i]<16) infoSerial<<"0";
|
||||||
#ifdef WITH_PRINTEX_LIB
|
#ifdef WITH_PRINTEX_LIB
|
||||||
(i < 5) ?debugSerial<<hex <<(mac[i])<<F(":"):debugSerial<<hex<<(mac[i])<<endl;
|
(i < 5) ?infoSerial<<hex <<(mac[i])<<F(":"):infoSerial<<hex<<(mac[i])<<endl;
|
||||||
#else
|
#else
|
||||||
(i < 5) ?debugSerial<<_HEX(mac[i])<<F(":"):debugSerial<<_HEX(mac[i])<<endl;
|
(i < 5) ?infoSerial<<_HEX(mac[i])<<F(":"):infoSerial<<_HEX(mac[i])<<endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,7 +382,7 @@ lan_status lanLoop() {
|
|||||||
mqttClient.unsubscribe(buf);
|
mqttClient.unsubscribe(buf);
|
||||||
|
|
||||||
lanStatus = OPERATION;//3;
|
lanStatus = OPERATION;//3;
|
||||||
debugSerial<<F("Accepting commands...\n");
|
infoSerial<<F("Accepting commands...\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,32 +436,32 @@ if (WiFi.status() != WL_CONNECTED)
|
|||||||
|
|
||||||
switch (etherStatus) {
|
switch (etherStatus) {
|
||||||
case NO_LINK:
|
case NO_LINK:
|
||||||
debugSerial<<F("No link")<<endl;
|
errorSerial<<F("No link")<<endl;
|
||||||
if (mqttClient.connected()) mqttClient.disconnect();
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
nextLanCheckTime = millis() + 30000;
|
nextLanCheckTime = millis() + 30000;
|
||||||
lanStatus = AWAITING_ADDRESS;//-10;
|
lanStatus = AWAITING_ADDRESS;//-10;
|
||||||
break;
|
break;
|
||||||
case DHCP_CHECK_RENEW_FAIL:
|
case DHCP_CHECK_RENEW_FAIL:
|
||||||
debugSerial<<F("Error: renewed fail");
|
errorSerial<<F("Error: renewed fail");
|
||||||
if (mqttClient.connected()) mqttClient.disconnect();
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
nextLanCheckTime = millis() + 1000;
|
nextLanCheckTime = millis() + 1000;
|
||||||
lanStatus = AWAITING_ADDRESS;//-10;
|
lanStatus = AWAITING_ADDRESS;//-10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DHCP_CHECK_RENEW_OK:
|
case DHCP_CHECK_RENEW_OK:
|
||||||
debugSerial<<F("Renewed success. IP address:");
|
errorSerial<<F("Renewed success. IP address:");
|
||||||
printIPAddress(Ethernet.localIP());
|
printIPAddress(Ethernet.localIP());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DHCP_CHECK_REBIND_FAIL:
|
case DHCP_CHECK_REBIND_FAIL:
|
||||||
debugSerial<<F("Error: rebind fail");
|
errorSerial<<F("Error: rebind fail");
|
||||||
if (mqttClient.connected()) mqttClient.disconnect();
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
nextLanCheckTime = millis() + 1000;
|
nextLanCheckTime = millis() + 1000;
|
||||||
lanStatus = AWAITING_ADDRESS;//-10;
|
lanStatus = AWAITING_ADDRESS;//-10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DHCP_CHECK_REBIND_OK:
|
case DHCP_CHECK_REBIND_OK:
|
||||||
debugSerial<<F("Rebind success. IP address:");
|
errorSerial<<F("Rebind success. IP address:");
|
||||||
printIPAddress(Ethernet.localIP());
|
printIPAddress(Ethernet.localIP());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -606,11 +607,10 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
char passwordBuf[16] = "";
|
char passwordBuf[16] = "";
|
||||||
char *password = passwordBuf;
|
char *password = passwordBuf;
|
||||||
int syslogPort = 514;
|
int syslogPort = 514;
|
||||||
char syslogDeviceHostname[16];
|
|
||||||
if (mqttArr && (aJson.getArraySize(mqttArr)))
|
if (mqttArr && (aJson.getArraySize(mqttArr)))
|
||||||
{
|
{
|
||||||
deviceName = getStringFromConfig(mqttArr, 0);
|
deviceName = getStringFromConfig(mqttArr, 0);
|
||||||
debugSerial<<F("Device Name:")<<deviceName<<endl;
|
infoSerial<<F("Device Name:")<<deviceName<<endl;
|
||||||
}
|
}
|
||||||
#ifdef SYSLOG_ENABLE
|
#ifdef SYSLOG_ENABLE
|
||||||
|
|
||||||
@@ -625,13 +625,13 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
char *syslogDeviceHostname = aJson.getArrayItem(udpSyslogArr, 2)->valuestring;
|
char *syslogDeviceHostname = aJson.getArrayItem(udpSyslogArr, 2)->valuestring;
|
||||||
char *syslogAppname = aJson.getArrayItem(udpSyslogArr, 3)->valuestring;
|
char *syslogAppname = aJson.getArrayItem(udpSyslogArr, 3)->valuestring;
|
||||||
*/
|
*/
|
||||||
debugSerial<<F("Syslog params:")<<syslogServer<<":"<<syslogPort<<":"<<syslogDeviceHostname<<":"<<deviceName<<endl;
|
infoSerial<<F("Syslog params:")<<syslogServer<<":"<<syslogPort<<":"<<syslogDeviceHostname<<":"<<deviceName<<endl;
|
||||||
udpSyslog.server(syslogServer, syslogPort);
|
udpSyslog.server(syslogServer, syslogPort);
|
||||||
udpSyslog.deviceHostname(syslogDeviceHostname);
|
udpSyslog.deviceHostname(syslogDeviceHostname);
|
||||||
if (deviceName) udpSyslog.appName(deviceName);
|
if (deviceName) udpSyslog.appName(deviceName);
|
||||||
udpSyslog.defaultPriority(LOG_KERN);
|
udpSyslog.defaultPriority(LOG_KERN);
|
||||||
udpSyslog.log(LOG_INFO, F("UDP Syslog initialized!"));
|
udpSyslog.log(LOG_INFO, F("UDP Syslog initialized!"));
|
||||||
debugSerial<<F("UDP Syslog initialized!\n");
|
infoSerial<<F("UDP Syslog initialized!\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -642,7 +642,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
if (n >= 4) user = getStringFromConfig(mqttArr, 3);
|
if (n >= 4) user = getStringFromConfig(mqttArr, 3);
|
||||||
if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) {
|
if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) {
|
||||||
password = getStringFromConfig(mqttArr, 4);
|
password = getStringFromConfig(mqttArr, 4);
|
||||||
debugSerial<<F("Using MQTT password from config");
|
infoSerial<<F("Using MQTT password from config");
|
||||||
}
|
}
|
||||||
|
|
||||||
mqttClient.setServer(servername, port);
|
mqttClient.setServer(servername, port);
|
||||||
@@ -659,7 +659,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
strncat_P(willTopic, state_P, sizeof(willTopic));
|
strncat_P(willTopic, state_P, sizeof(willTopic));
|
||||||
|
|
||||||
|
|
||||||
debugSerial<<F("\nAttempting MQTT connection to ")<<servername<<F(":")<<port<<F(" user:")<<user<<F(" ...");
|
infoSerial<<F("\nAttempting MQTT connection to ")<<servername<<F(":")<<port<<F(" user:")<<user<<F(" ...");
|
||||||
if (!strlen(user))
|
if (!strlen(user))
|
||||||
{
|
{
|
||||||
user = NULL;
|
user = NULL;
|
||||||
@@ -668,7 +668,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
// wdt_dis(); //potential unsafe for ethernetIdle(), but needed to avoid cyclic reboot if mosquitto out of order
|
// wdt_dis(); //potential unsafe for ethernetIdle(), but needed to avoid cyclic reboot if mosquitto out of order
|
||||||
if (mqttClient.connect(deviceName, user, password,willTopic,MQTTQOS1,true,willMessage)) {
|
if (mqttClient.connect(deviceName, user, password,willTopic,MQTTQOS1,true,willMessage)) {
|
||||||
mqttErrorRate = 0;
|
mqttErrorRate = 0;
|
||||||
debugSerial<<F("connected as ")<<deviceName <<endl;
|
infoSerial<<F("connected as ")<<deviceName <<endl;
|
||||||
// wdt_en();
|
// wdt_en();
|
||||||
configOk = true;
|
configOk = true;
|
||||||
// ... Temporary subscribe to status topic
|
// ... Temporary subscribe to status topic
|
||||||
@@ -696,14 +696,14 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
// if (_once) {DMXput(); _once=0;}
|
// if (_once) {DMXput(); _once=0;}
|
||||||
lanStatus = RETAINING_COLLECTING;//4;
|
lanStatus = RETAINING_COLLECTING;//4;
|
||||||
nextLanCheckTime = millis() + 5000;
|
nextLanCheckTime = millis() + 5000;
|
||||||
debugSerial<<F("Awaiting for retained topics");
|
infoSerial<<F("Awaiting for retained topics");
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("failed, rc=")<<mqttClient.state()<<F(" try again in 5 seconds")<<endl;
|
errorSerial<<F("failed, rc=")<<mqttClient.state()<<F(" try again in 5 seconds")<<endl;
|
||||||
nextLanCheckTime = millis() + 5000;
|
nextLanCheckTime = millis() + 5000;
|
||||||
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
||||||
mqttErrorRate++;
|
mqttErrorRate++;
|
||||||
if(mqttErrorRate>50){
|
if(mqttErrorRate>50){
|
||||||
debugSerial<<F("Too many MQTT connection errors. Restart LAN"));
|
errorSerial<<F("Too many MQTT connection errors. Restart LAN"));
|
||||||
mqttErrorRate=0;
|
mqttErrorRate=0;
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
resetHard();
|
resetHard();
|
||||||
@@ -732,7 +732,7 @@ void onInitialStateInitLAN() {
|
|||||||
#if defined(WIFI_MANAGER_DISABLE)
|
#if defined(WIFI_MANAGER_DISABLE)
|
||||||
if(WiFi.status() != WL_CONNECTED) {
|
if(WiFi.status() != WL_CONNECTED) {
|
||||||
WiFi.mode(WIFI_STA); // ESP 32 - WiFi.disconnect(); instead
|
WiFi.mode(WIFI_STA); // ESP 32 - WiFi.disconnect(); instead
|
||||||
debugSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD)<<endl;
|
infoSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD)<<endl;
|
||||||
|
|
||||||
wifi_set_macaddr(STATION_IF,mac); //ESP32 to check
|
wifi_set_macaddr(STATION_IF,mac); //ESP32 to check
|
||||||
|
|
||||||
@@ -781,13 +781,13 @@ wifiManager.setTimeout(30);
|
|||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
debugSerial<<F("WiFi connected. IP address: ")<<WiFi.localIP()<<endl;
|
infoSerial<<F("WiFi connected. IP address: ")<<WiFi.localIP()<<endl;
|
||||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||||
setupOTA();
|
setupOTA();
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
debugSerial<<F("Problem with WiFi!");
|
errorSerial<<F("Problem with WiFi!");
|
||||||
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -799,29 +799,29 @@ setupOTA();
|
|||||||
#else
|
#else
|
||||||
Ethernet.w5500_cspin = W5500_CS_PIN;
|
Ethernet.w5500_cspin = W5500_CS_PIN;
|
||||||
#endif
|
#endif
|
||||||
debugSerial<<F("Use W5500 pin: ");
|
infoSerial<<F("Use W5500 pin: ");
|
||||||
debugSerial<<QUOTE(W5500_CS_PIN)<<endl;
|
infoSerial<<QUOTE(W5500_CS_PIN)<<endl;
|
||||||
#endif
|
#endif
|
||||||
IPAddress ip, dns, gw, mask;
|
IPAddress ip, dns, gw, mask;
|
||||||
int res = 1;
|
int res = 1;
|
||||||
debugSerial<<F("Starting lan")<<endl;
|
infoSerial<<F("Starting lan")<<endl;
|
||||||
if (ipLoadFromFlash(OFFSET_IP, ip)) {
|
if (ipLoadFromFlash(OFFSET_IP, ip)) {
|
||||||
debugSerial<<"Loaded from flash IP:";
|
infoSerial<<"Loaded from flash IP:";
|
||||||
printIPAddress(ip);
|
printIPAddress(ip);
|
||||||
if (ipLoadFromFlash(OFFSET_DNS, dns)) {
|
if (ipLoadFromFlash(OFFSET_DNS, dns)) {
|
||||||
debugSerial<<" DNS:";
|
infoSerial<<" DNS:";
|
||||||
printIPAddress(dns);
|
printIPAddress(dns);
|
||||||
if (ipLoadFromFlash(OFFSET_GW, gw)) {
|
if (ipLoadFromFlash(OFFSET_GW, gw)) {
|
||||||
debugSerial<<" GW:";
|
infoSerial<<" GW:";
|
||||||
printIPAddress(gw);
|
printIPAddress(gw);
|
||||||
if (ipLoadFromFlash(OFFSET_MASK, mask)) {
|
if (ipLoadFromFlash(OFFSET_MASK, mask)) {
|
||||||
debugSerial<<" MASK:";
|
infoSerial<<" MASK:";
|
||||||
printIPAddress(mask);
|
printIPAddress(mask);
|
||||||
Ethernet.begin(mac, ip, dns, gw, mask);
|
Ethernet.begin(mac, ip, dns, gw, mask);
|
||||||
} else Ethernet.begin(mac, ip, dns, gw);
|
} else Ethernet.begin(mac, ip, dns, gw);
|
||||||
} else Ethernet.begin(mac, ip, dns);
|
} else Ethernet.begin(mac, ip, dns);
|
||||||
} else Ethernet.begin(mac, ip);
|
} else Ethernet.begin(mac, ip);
|
||||||
debugSerial<<endl;
|
infoSerial<<endl;
|
||||||
lanStatus = HAVE_IP_ADDRESS;
|
lanStatus = HAVE_IP_ADDRESS;
|
||||||
setupOTA();
|
setupOTA();
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
@@ -829,7 +829,7 @@ setupOTA();
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
debugSerial<<"\nNo IP data found in flash\n";
|
infoSerial<<"\nNo IP data found in flash\n";
|
||||||
wdt_dis();
|
wdt_dis();
|
||||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined (NRF5)
|
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined (NRF5)
|
||||||
res = Ethernet.begin(mac, 12000);
|
res = Ethernet.begin(mac, 12000);
|
||||||
@@ -842,14 +842,14 @@ setupOTA();
|
|||||||
|
|
||||||
|
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
debugSerial<<F("Failed to configure Ethernet using DHCP. You can set ip manually!")<<F("'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n");
|
errorSerial<<F("Failed to configure Ethernet using DHCP. You can set ip manually!")<<F("'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n");
|
||||||
lanStatus = AWAITING_ADDRESS;//-10;
|
lanStatus = AWAITING_ADDRESS;//-10;
|
||||||
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
resetHard();
|
resetHard();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("Got IP address:");
|
infoSerial<<F("Got IP address:");
|
||||||
printIPAddress(Ethernet.localIP());
|
printIPAddress(Ethernet.localIP());
|
||||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||||
|
|
||||||
@@ -866,8 +866,8 @@ setupOTA();
|
|||||||
|
|
||||||
void resetHard() {
|
void resetHard() {
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
debugSerial<<F("Reset Arduino with digital pin ");
|
infoSerial<<F("Reset Arduino with digital pin ");
|
||||||
debugSerial<<QUOTE(RESET_PIN);
|
infoSerial<<QUOTE(RESET_PIN);
|
||||||
delay(500);
|
delay(500);
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN,LOW);
|
digitalWrite(RESET_PIN,LOW);
|
||||||
@@ -939,7 +939,7 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
|||||||
#endif
|
#endif
|
||||||
printCurentLanConfig();
|
printCurentLanConfig();
|
||||||
// printFreeRam();
|
// printFreeRam();
|
||||||
debugSerial<<F("\nUse these commands: 'help' - this text\n"
|
infoSerial<<F("\nUse these commands: 'help' - this text\n"
|
||||||
"'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n"
|
"'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n"
|
||||||
"'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n"
|
"'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n"
|
||||||
"'save' - save config in NVRAM\n"
|
"'save' - save config in NVRAM\n"
|
||||||
@@ -951,7 +951,7 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
|||||||
"'reboot' - reboot controller");
|
"'reboot' - reboot controller");
|
||||||
}
|
}
|
||||||
void printCurentLanConfig() {
|
void printCurentLanConfig() {
|
||||||
debugSerial << F("Current LAN config(ip,dns,gw,subnet):");
|
infoSerial << F("Current LAN config(ip,dns,gw,subnet):");
|
||||||
printIPAddress(Ethernet.localIP());
|
printIPAddress(Ethernet.localIP());
|
||||||
// printIPAddress(Ethernet.dnsServerIP());
|
// printIPAddress(Ethernet.dnsServerIP());
|
||||||
printIPAddress(Ethernet.gatewayIP());
|
printIPAddress(Ethernet.gatewayIP());
|
||||||
@@ -961,12 +961,12 @@ void printCurentLanConfig() {
|
|||||||
void cmdFunctionKill(int arg_cnt, char **args) {
|
void cmdFunctionKill(int arg_cnt, char **args) {
|
||||||
for (byte i = 1; i < 20; i++) {
|
for (byte i = 1; i < 20; i++) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
debugSerial<<i;
|
infoSerial<<i;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionReboot(int arg_cnt, char **args) {
|
void cmdFunctionReboot(int arg_cnt, char **args) {
|
||||||
debugSerial<<F("Soft rebooting...");
|
infoSerial<<F("Soft rebooting...");
|
||||||
softRebootFunc();
|
softRebootFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,7 +978,7 @@ configLocked++;
|
|||||||
dmxArr = aJson.getObjectItem(root, "dmxin");
|
dmxArr = aJson.getObjectItem(root, "dmxin");
|
||||||
if (dmxArr && (itemsCount = aJson.getArraySize(dmxArr))) {
|
if (dmxArr && (itemsCount = aJson.getArraySize(dmxArr))) {
|
||||||
DMXinSetup(itemsCount * 4);
|
DMXinSetup(itemsCount * 4);
|
||||||
debugSerial<<F("DMX in started. Channels:")<<itemsCount * 4<<endl;
|
infoSerial<<F("DMX in started. Channels:")<<itemsCount * 4<<endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
@@ -987,7 +987,7 @@ configLocked++;
|
|||||||
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
||||||
if (dmxoutArr && (numParams=aJson.getArraySize(dmxoutArr)) >=1 ) {
|
if (dmxoutArr && (numParams=aJson.getArraySize(dmxoutArr)) >=1 ) {
|
||||||
DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, numParams-1)->valueint);
|
DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, numParams-1)->valueint);
|
||||||
debugSerial<<F("DMX out started. Channels: ")<<maxChannels<<endl;
|
infoSerial<<F("DMX out started. Channels: ")<<maxChannels<<endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
@@ -999,13 +999,13 @@ configLocked++;
|
|||||||
if (owArr && !owReady) {
|
if (owArr && !owReady) {
|
||||||
aJsonObject *item = owArr->child;
|
aJsonObject *item = owArr->child;
|
||||||
owReady = owSetup(&Changed);
|
owReady = owSetup(&Changed);
|
||||||
if (owReady) debugSerial<<F("One wire Ready\n");
|
if (owReady) infoSerial<<F("One wire Ready\n");
|
||||||
t_count = 0;
|
t_count = 0;
|
||||||
|
|
||||||
while (item && owReady) {
|
while (item && owReady) {
|
||||||
if ((item->type == aJson_Object)) {
|
if ((item->type == aJson_Object)) {
|
||||||
DeviceAddress addr;
|
DeviceAddress addr;
|
||||||
//debugSerial<<F("Add:")),debugSerial<<item->name);
|
//infoSerial<<F("Add:")),infoSerial<<item->name);
|
||||||
SetAddr(item->name, addr);
|
SetAddr(item->name, addr);
|
||||||
owAdd(addr);
|
owAdd(addr);
|
||||||
}
|
}
|
||||||
@@ -1066,26 +1066,26 @@ configLocked--;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printConfigSummary() {
|
void printConfigSummary() {
|
||||||
debugSerial<<F("\nConfigured:")<<F("\nitems ");
|
infoSerial<<F("\nConfigured:")<<F("\nitems ");
|
||||||
printBool(items);
|
printBool(items);
|
||||||
debugSerial<<F("\ninputs ");
|
infoSerial<<F("\ninputs ");
|
||||||
printBool(inputs);
|
printBool(inputs);
|
||||||
#ifndef MODBUS_DISABLE
|
#ifndef MODBUS_DISABLE
|
||||||
debugSerial<<F("\nmodbus ");
|
infoSerial<<F("\nmodbus ");
|
||||||
printBool(modbusObj);
|
printBool(modbusObj);
|
||||||
#endif
|
#endif
|
||||||
debugSerial<<F("\nmqtt ");
|
infoSerial<<F("\nmqtt ");
|
||||||
printBool(mqttArr);
|
printBool(mqttArr);
|
||||||
#ifdef _owire
|
#ifdef _owire
|
||||||
debugSerial<<F("\n1-wire ");
|
infoSerial<<F("\n1-wire ");
|
||||||
printBool(owArr);
|
printBool(owArr);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SYSLOG_ENABLE
|
#ifdef SYSLOG_ENABLE
|
||||||
debugSerial<<F("\nudp syslog ");
|
infoSerial<<F("\nudp syslog ");
|
||||||
printBool(udpSyslogArr);
|
printBool(udpSyslogArr);
|
||||||
#endif
|
#endif
|
||||||
debugSerial << endl;
|
infoSerial << endl;
|
||||||
debugSerial<<F("RAM=")<<freeRam()<<endl;
|
infoSerial<<F("RAM=")<<freeRam()<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionLoad(int arg_cnt, char **args) {
|
void cmdFunctionLoad(int arg_cnt, char **args) {
|
||||||
@@ -1097,7 +1097,7 @@ void cmdFunctionLoad(int arg_cnt, char **args) {
|
|||||||
int loadConfigFromEEPROM()
|
int loadConfigFromEEPROM()
|
||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
debugSerial<<F("Loading Config from EEPROM")<<endl;
|
infoSerial<<F("Loading Config from EEPROM")<<endl;
|
||||||
|
|
||||||
ch = EEPROM.read(EEPROM_offsetJSON);
|
ch = EEPROM.read(EEPROM_offsetJSON);
|
||||||
if (ch == '{') {
|
if (ch == '{') {
|
||||||
@@ -1105,15 +1105,15 @@ int loadConfigFromEEPROM()
|
|||||||
cleanConf();
|
cleanConf();
|
||||||
root = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
if (!root) {
|
if (!root) {
|
||||||
debugSerial<<F("load failed")<<endl;
|
errorSerial<<F("load failed")<<endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
debugSerial<<F("Loaded")<<endl;
|
infoSerial<<F("Loaded")<<endl;
|
||||||
applyConfig();
|
applyConfig();
|
||||||
ethClient.stop(); //Refresh MQTT connect to get retained info
|
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("No stored config")<<endl;
|
infoSerial<<F("No stored config")<<endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1128,7 +1128,7 @@ void cmdFunctionReq(int arg_cnt, char **args) {
|
|||||||
int mqttConfigRequest(int arg_cnt, char **args)
|
int mqttConfigRequest(int arg_cnt, char **args)
|
||||||
{
|
{
|
||||||
char buf[25] = "/";
|
char buf[25] = "/";
|
||||||
debugSerial<<F("\nrequest MQTT Config");
|
infoSerial<<F("\nrequest MQTT Config");
|
||||||
SetBytes((uint8_t *) mac, 6, buf + 1);
|
SetBytes((uint8_t *) mac, 6, buf + 1);
|
||||||
buf[13] = 0;
|
buf[13] = 0;
|
||||||
strncat(buf, "/resp/#", 25);
|
strncat(buf, "/resp/#", 25);
|
||||||
@@ -1143,14 +1143,14 @@ int mqttConfigRequest(int arg_cnt, char **args)
|
|||||||
|
|
||||||
|
|
||||||
int mqttConfigResp(char *as) {
|
int mqttConfigResp(char *as) {
|
||||||
debugSerial<<F("got MQTT Config");
|
infoSerial<<F("got MQTT Config");
|
||||||
root = aJson.parse(as);
|
root = aJson.parse(as);
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
debugSerial<<F("\nload failed\n");
|
errorSerial<<F("\nload failed\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
debugSerial<<F("\nLoaded");
|
infoSerial<<F("\nLoaded");
|
||||||
applyConfig();
|
applyConfig();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1165,7 +1165,7 @@ void cmdFunctionSave(int arg_cnt, char **args)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debugSerial<<F("Saving config to EEPROM..");
|
infoSerial<<F("Saving config to EEPROM..");
|
||||||
aJsonStringStream stringStream(NULL, outBuf, saveBufLen);
|
aJsonStringStream stringStream(NULL, outBuf, saveBufLen);
|
||||||
aJson.print(root, &stringStream);
|
aJson.print(root, &stringStream);
|
||||||
int len = strlen(outBuf);
|
int len = strlen(outBuf);
|
||||||
@@ -1173,20 +1173,20 @@ void cmdFunctionSave(int arg_cnt, char **args)
|
|||||||
EEPROM.write(EEPROM_offsetJSON,(byte*) outBuf,len);
|
EEPROM.write(EEPROM_offsetJSON,(byte*) outBuf,len);
|
||||||
|
|
||||||
free (outBuf);
|
free (outBuf);
|
||||||
debugSerial<<F("Saved to EEPROM");
|
infoSerial<<F("Saved to EEPROM");
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
void cmdFunctionSave(int arg_cnt, char **args)
|
void cmdFunctionSave(int arg_cnt, char **args)
|
||||||
{
|
{
|
||||||
aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offsetJSON);
|
aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offsetJSON);
|
||||||
debugSerial<<F("Saving config to EEPROM..");
|
infoSerial<<F("Saving config to EEPROM..");
|
||||||
|
|
||||||
aJson.print(root, &jsonEEPROMStream);
|
aJson.print(root, &jsonEEPROMStream);
|
||||||
jsonEEPROMStream.putEOF();
|
jsonEEPROMStream.putEOF();
|
||||||
|
|
||||||
|
|
||||||
debugSerial<<F("Saved to EEPROM");
|
infoSerial<<F("Saved to EEPROM");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1223,7 +1223,7 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
|||||||
if (arg_cnt==1)
|
if (arg_cnt==1)
|
||||||
{
|
{
|
||||||
saveFlash(OFFSET_IP,ip0);
|
saveFlash(OFFSET_IP,ip0);
|
||||||
debugSerial<<F("Set dynamic IP\n");
|
infoSerial<<F("Set dynamic IP\n");
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
IPAddress current_ip = Ethernet.localIP();
|
IPAddress current_ip = Ethernet.localIP();
|
||||||
@@ -1240,7 +1240,7 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
|||||||
printIPAddress(current_gw);
|
printIPAddress(current_gw);
|
||||||
printIPAddress(current_mask); */
|
printIPAddress(current_mask); */
|
||||||
//}
|
//}
|
||||||
debugSerial<<F("Saved\n");
|
infoSerial<<F("Saved\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
||||||
@@ -1250,7 +1250,7 @@ void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
|||||||
for (int i = 0; i < EEPROM_SIGNATURE_LENGTH; i++)
|
for (int i = 0; i < EEPROM_SIGNATURE_LENGTH; i++)
|
||||||
EEPROM.write(i+OFFSET_SIGNATURE,EEPROM_signature[i]);
|
EEPROM.write(i+OFFSET_SIGNATURE,EEPROM_signature[i]);
|
||||||
|
|
||||||
debugSerial<<F("EEPROM cleared\n");
|
infoSerial<<F("EEPROM cleared\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1259,18 +1259,18 @@ void cmdFunctionPwd(int arg_cnt, char **args)
|
|||||||
if (arg_cnt)
|
if (arg_cnt)
|
||||||
saveFlash(OFFSET_MQTT_PWD,args[1]);
|
saveFlash(OFFSET_MQTT_PWD,args[1]);
|
||||||
else saveFlash(OFFSET_MQTT_PWD,empty);
|
else saveFlash(OFFSET_MQTT_PWD,empty);
|
||||||
debugSerial<<F("Password updated\n");
|
infoSerial<<F("Password updated\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||||
char dummy;
|
char dummy;
|
||||||
if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5], &dummy) < 6) {
|
if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5], &dummy) < 6) {
|
||||||
debugSerial<<F("could not parse: ")<<args[1];
|
errorSerial<<F("could not parse: ")<<args[1];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printMACAddress();
|
printMACAddress();
|
||||||
for (short i = 0; i < 6; i++) { EEPROM.write(i, mac[i]); }
|
for (short i = 0; i < 6; i++) { EEPROM.write(i, mac[i]); }
|
||||||
debugSerial<<F("Updated\n");
|
infoSerial<<F("Updated\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionGet(int arg_cnt, char **args) {
|
void cmdFunctionGet(int arg_cnt, char **args) {
|
||||||
@@ -1279,7 +1279,7 @@ void cmdFunctionGet(int arg_cnt, char **args) {
|
|||||||
//restoreState();
|
//restoreState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printBool(bool arg) { (arg) ? debugSerial<<F("+") : debugSerial<<F("-"); }
|
void printBool(bool arg) { (arg) ? infoSerial<<F("+") : infoSerial<<F("-"); }
|
||||||
|
|
||||||
void saveFlash(short n, char *str) {
|
void saveFlash(short n, char *str) {
|
||||||
short len=strlen(str);
|
short len=strlen(str);
|
||||||
@@ -1327,11 +1327,11 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
|||||||
if (arg_cnt > 1) {
|
if (arg_cnt > 1) {
|
||||||
strncpy(configServer, args[1], sizeof(configServer) - 1);
|
strncpy(configServer, args[1], sizeof(configServer) - 1);
|
||||||
saveFlash(OFFSET_CONFIGSERVER, configServer);
|
saveFlash(OFFSET_CONFIGSERVER, configServer);
|
||||||
debugSerial<<configServer<<F(" Saved")<<endl;
|
infoSerial<<configServer<<F(" Saved")<<endl;
|
||||||
} else if (!loadFlash(OFFSET_CONFIGSERVER, configServer))
|
} else if (!loadFlash(OFFSET_CONFIGSERVER, configServer))
|
||||||
{
|
{
|
||||||
strncpy_P(configServer,configserver,sizeof(configServer));
|
strncpy_P(configServer,configserver,sizeof(configServer));
|
||||||
debugSerial<<F(" Default config server used: ")<<configServer<<endl;
|
infoSerial<<F(" Default config server used: ")<<configServer<<endl;
|
||||||
}
|
}
|
||||||
#ifndef DEVICE_NAME
|
#ifndef DEVICE_NAME
|
||||||
snprintf(URI, sizeof(URI), "/cnf/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
snprintf(URI, sizeof(URI), "/cnf/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
||||||
@@ -1345,7 +1345,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
|||||||
strncat(URI, "_config.json", sizeof(URI));
|
strncat(URI, "_config.json", sizeof(URI));
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
debugSerial<<F("Config URI: http://")<<configServer<<URI<<endl;
|
infoSerial<<F("Config URI: http://")<<configServer<<URI<<endl;
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_AVR)
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
FILE *configStream;
|
FILE *configStream;
|
||||||
@@ -1359,7 +1359,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
|||||||
if (configStream != NULL) {
|
if (configStream != NULL) {
|
||||||
if (responseStatusCode == 200) {
|
if (responseStatusCode == 200) {
|
||||||
|
|
||||||
debugSerial<<F("got Config\n");
|
infoSerial<<F("got Config\n");
|
||||||
char c;
|
char c;
|
||||||
aJsonFileStream as = aJsonFileStream(configStream);
|
aJsonFileStream as = aJsonFileStream(configStream);
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
@@ -1369,19 +1369,19 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
|||||||
hclient.closeStream(configStream); // this is very important -- be sure to close the STREAM
|
hclient.closeStream(configStream); // this is very important -- be sure to close the STREAM
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
debugSerial<<F("Config parsing failed\n");
|
errorSerial<<F("Config parsing failed\n");
|
||||||
nextLanCheckTime = millis() + 15000;
|
nextLanCheckTime = millis() + 15000;
|
||||||
return READ_RE_CONFIG;//-11;
|
return READ_RE_CONFIG;//-11;
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("Applying.\n");
|
infoSerial<<F("Applying.\n");
|
||||||
applyConfig();
|
applyConfig();
|
||||||
debugSerial<<F("Done.\n");
|
infoSerial<<F("Done.\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("ERROR: Server returned ");
|
errorSerial<<F("ERROR: Server returned ");
|
||||||
debugSerial<<responseStatusCode;
|
errorSerial<<responseStatusCode<<endl;
|
||||||
nextLanCheckTime = millis() + 5000;
|
nextLanCheckTime = millis() + 5000;
|
||||||
return READ_RE_CONFIG;//-11;
|
return READ_RE_CONFIG;//-11;
|
||||||
}
|
}
|
||||||
@@ -1416,8 +1416,8 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
|||||||
response = htclient.responseBody();
|
response = htclient.responseBody();
|
||||||
htclient.stop();
|
htclient.stop();
|
||||||
wdt_res();
|
wdt_res();
|
||||||
debugSerial<<F("HTTP Status code: ");
|
infoSerial<<F("HTTP Status code: ");
|
||||||
debugSerial<<responseStatusCode<<" ";
|
infoSerial<<responseStatusCode<<" ";
|
||||||
//debugSerial<<"GET Response: ");
|
//debugSerial<<"GET Response: ");
|
||||||
|
|
||||||
if (responseStatusCode == 200) {
|
if (responseStatusCode == 200) {
|
||||||
@@ -1425,19 +1425,19 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
|||||||
root = aJson.parse((char *) response.c_str());
|
root = aJson.parse((char *) response.c_str());
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
debugSerial<<F("Config parsing failed\n");
|
errorSerial<<F("Config parsing failed\n");
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<response;
|
debugSerial<<response;
|
||||||
applyConfig();
|
applyConfig();
|
||||||
debugSerial<<F("Done.\n");
|
infoSerial<<F("Done.\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("Config retrieving failed\n");
|
errorSerial<<F("Config retrieving failed\n");
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("Connect failed\n");
|
errorSerial<<F("Connect failed\n");
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1450,26 +1450,26 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
|||||||
httpClient.begin(fullURI);
|
httpClient.begin(fullURI);
|
||||||
int httpResponseCode = httpClient.GET();
|
int httpResponseCode = httpClient.GET();
|
||||||
if (httpResponseCode > 0) {
|
if (httpResponseCode > 0) {
|
||||||
debugSerial.printf("[HTTP] GET... code: %d\n", httpResponseCode);
|
infoSerial.printf("[HTTP] GET... code: %d\n", httpResponseCode);
|
||||||
if (httpResponseCode == HTTP_CODE_OK) {
|
if (httpResponseCode == HTTP_CODE_OK) {
|
||||||
String response = httpClient.getString();
|
String response = httpClient.getString();
|
||||||
debugSerial<<response;
|
debugSerial<<response;
|
||||||
cleanConf();
|
cleanConf();
|
||||||
root = aJson.parse((char *) response.c_str());
|
root = aJson.parse((char *) response.c_str());
|
||||||
if (!root) {
|
if (!root) {
|
||||||
debugSerial<<F("Config parsing failed\n");
|
errorSerial<<F("Config parsing failed\n");
|
||||||
return READ_RE_CONFIG;
|
return READ_RE_CONFIG;
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("Config OK, Applying\n");
|
infoSerial<<F("Config OK, Applying\n");
|
||||||
applyConfig();
|
applyConfig();
|
||||||
debugSerial<<F("Done.\n");
|
infoSerial<<F("Done.\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("Config retrieving failed\n");
|
errorSerial<<F("Config retrieving failed\n");
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debugSerial.printf("[HTTP] GET... failed, error: %s\n", httpClient.errorToString(httpResponseCode).c_str());
|
errorSerial.printf("[HTTP] GET... failed, error: %s\n", httpClient.errorToString(httpResponseCode).c_str());
|
||||||
httpClient.end();
|
httpClient.end();
|
||||||
return READ_RE_CONFIG;
|
return READ_RE_CONFIG;
|
||||||
}
|
}
|
||||||
@@ -1575,124 +1575,123 @@ void setup_main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printFirmwareVersionAndBuildOptions() {
|
void printFirmwareVersionAndBuildOptions() {
|
||||||
debugSerial<<F("\nLazyhome.ru LightHub controller ")<<F(QUOTE(PIO_SRC_REV))<<F(" C++ version:")<<F(QUOTE(__cplusplus))<<endl;
|
infoSerial<<F("\nLazyhome.ru LightHub controller ")<<F(QUOTE(PIO_SRC_REV))<<F(" C++ version:")<<F(QUOTE(__cplusplus))<<endl;
|
||||||
#ifdef CONTROLLINO
|
#ifdef CONTROLLINO
|
||||||
debugSerial<<F("\n(+)CONTROLLINO");
|
infoSerial<<F("\n(+)CONTROLLINO");
|
||||||
#endif
|
#endif
|
||||||
#ifndef WATCH_DOG_TICKER_DISABLE
|
#ifndef WATCH_DOG_TICKER_DISABLE
|
||||||
debugSerial<<F("\n(+)WATCHDOG");
|
infoSerial<<F("\n(+)WATCHDOG");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)WATCHDOG");
|
infoSerial<<F("\n(-)WATCHDOG");
|
||||||
#endif
|
#endif
|
||||||
debugSerial<<F("\nConfig server:")<<F(CONFIG_SERVER)<<F("\nFirmware MAC Address ")<<F(QUOTE(CUSTOM_FIRMWARE_MAC));
|
infoSerial<<F("\nConfig server:")<<F(CONFIG_SERVER)<<F("\nFirmware MAC Address ")<<F(QUOTE(CUSTOM_FIRMWARE_MAC));
|
||||||
#ifdef DISABLE_FREERAM_PRINT
|
#ifdef DISABLE_FREERAM_PRINT
|
||||||
debugSerial<<F("\n(-)FreeRam printing");
|
infoSerial<<F("\n(-)FreeRam printing");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(+)FreeRam printing");
|
infoSerial<<F("\n(+)FreeRam printing");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_1W_PIN
|
#ifdef USE_1W_PIN
|
||||||
debugSerial<<F("\n(-)DS2482-100 USE_1W_PIN=")<<QUOTE(USE_1W_PIN);
|
infoSerial<<F("\n(-)DS2482-100 USE_1W_PIN=")<<QUOTE(USE_1W_PIN);
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(+)DS2482-100");
|
infoSerial<<F("\n(+)DS2482-100");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Wiz5500
|
#ifdef Wiz5500
|
||||||
debugSerial<<F("\n(+)WizNet5500");
|
infoSerial<<F("\n(+)WizNet5500");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(+)Wiznet5x00");
|
infoSerial<<F("\n(+)Wiznet5x00");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DMX_DISABLE
|
#ifndef DMX_DISABLE
|
||||||
debugSerial<<F("\n(+)DMX");
|
infoSerial<<F("\n(+)DMX");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)DMX");
|
infoSerial<<F("\n(-)DMX");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MODBUS_DISABLE
|
#ifndef MODBUS_DISABLE
|
||||||
debugSerial<<F("\n(+)MODBUS");
|
infoSerial<<F("\n(+)MODBUS");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)MODBUS");
|
infoSerial<<F("\n(-)MODBUS");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef OWIRE_DISABLE
|
#ifndef OWIRE_DISABLE
|
||||||
debugSerial<<F("\n(+)OWIRE");
|
infoSerial<<F("\n(+)OWIRE");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)OWIRE");
|
infoSerial<<F("\n(-)OWIRE");
|
||||||
#endif
|
#endif
|
||||||
#ifndef DHT_DISABLE
|
#ifndef DHT_DISABLE
|
||||||
debugSerial<<F("\n(+)DHT");
|
infoSerial<<F("\n(+)DHT");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)DHT");
|
infoSerial<<F("\n(-)DHT");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef COUNTER_DISABLE
|
#ifndef COUNTER_DISABLE
|
||||||
debugSerial<<F("\n(+)COUNTER");
|
infoSerial<<F("\n(+)COUNTER");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)COUNTER");
|
infoSerial<<F("\n(-)COUNTER");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SD_CARD_INSERTED
|
#ifdef SD_CARD_INSERTED
|
||||||
debugSerial<<F("\n(+)SDCARD");
|
infoSerial<<F("\n(+)SDCARD");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
debugSerial<<F("\n(+)HARDRESET on pin=")<<QUOTE(RESET_PIN);
|
infoSerial<<F("\n(+)HARDRESET on pin=")<<QUOTE(RESET_PIN);
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)HARDRESET, using soft");
|
infoSerial<<F("\n(-)HARDRESET, using soft");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
||||||
debugSerial<<F("\n(+)RESTART_LAN_ON_MQTT_ERRORS");
|
infoSerial<<F("\n(+)RESTART_LAN_ON_MQTT_ERRORS");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)RESTART_LAN_ON_MQTT_ERRORS");
|
infoSerial<<F("\n(-)RESTART_LAN_ON_MQTT_ERRORS");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef CSSHDC_DISABLE
|
#ifndef CSSHDC_DISABLE
|
||||||
debugSerial<<F("\n(+)CCS811 & HDC1080");
|
infoSerial<<F("\n(+)CCS811 & HDC1080");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)CCS811 & HDC1080");
|
infoSerial<<F("\n(-)CCS811 & HDC1080");
|
||||||
#endif
|
#endif
|
||||||
#ifndef AC_DISABLE
|
#ifndef AC_DISABLE
|
||||||
debugSerial<<F("\n(+)AC HAIER");
|
infoSerial<<F("\n(+)AC HAIER");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)AC HAIER");
|
infoSerial<<F("\n(-)AC HAIER");
|
||||||
#endif
|
#endif
|
||||||
#ifndef MOTOR_DISABLE
|
#ifndef MOTOR_DISABLE
|
||||||
debugSerial<<F("\n(+)MOTOR CTR");
|
infoSerial<<F("\n(+)MOTOR CTR");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)MOTOR CTR");
|
infoSerial<<F("\n(-)MOTOR CTR");
|
||||||
#endif
|
#endif
|
||||||
#ifndef SPILED_DISABLE
|
#ifndef SPILED_DISABLE
|
||||||
debugSerial<<F("\n(+)SPI LED");
|
infoSerial<<F("\n(+)SPI LED");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)SPI LED");
|
infoSerial<<F("\n(-)SPI LED");
|
||||||
#endif
|
#endif
|
||||||
#ifdef FASTLED
|
#ifdef FASTLED
|
||||||
debugSerial<<F("\n(+)FASTLED");
|
infoSerial<<F("\n(+)FASTLED");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(+)ADAFRUIT LED");
|
infoSerial<<F("\n(+)ADAFRUIT LED");
|
||||||
#endif
|
#endif
|
||||||
debugSerial<<endl;
|
|
||||||
|
|
||||||
#ifdef OTA
|
#ifdef OTA
|
||||||
debugSerial<<F("\n(+)OTA");
|
infoSerial<<F("\n(+)OTA");
|
||||||
#else
|
#else
|
||||||
debugSerial<<F("\n(-)OTA");
|
infoSerial<<F("\n(-)OTA");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debugSerial<<endl;
|
infoSerial<<endl;
|
||||||
|
|
||||||
// WDT_Disable( WDT ) ;
|
// WDT_Disable( WDT ) ;
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
|
|
||||||
Serial.println(F("Reading 128 bits unique identifier") ) ;
|
debugSerial<<F("Reading 128 bits unique identifier")<<endl ;
|
||||||
ReadUniqueID( UniqueID.UID_Long ) ;
|
ReadUniqueID( UniqueID.UID_Long ) ;
|
||||||
|
|
||||||
Serial.print ("ID: ") ;
|
infoSerial<< F ("ID: ");
|
||||||
for (byte b = 0 ; b < 4 ; b++)
|
for (byte b = 0 ; b < 4 ; b++)
|
||||||
Serial.print ((unsigned int) UniqueID.UID_Long [b], HEX) ;
|
infoSerial<< _HEX((unsigned int) UniqueID.UID_Long [b]) <<endl ;
|
||||||
Serial.println () ;
|
//debugSerial<< endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1731,7 +1730,7 @@ for (short i = 0; i < 6; i++) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isMacValid) {
|
if (!isMacValid) {
|
||||||
debugSerial<<F("No MAC configured: set firmware's MAC\n");
|
infoSerial<<F("No MAC configured: set firmware's MAC\n");
|
||||||
|
|
||||||
#if defined (CUSTOM_FIRMWARE_MAC) //Forced MAC from compiler's directive
|
#if defined (CUSTOM_FIRMWARE_MAC) //Forced MAC from compiler's directive
|
||||||
const char *macStr = QUOTE(CUSTOM_FIRMWARE_MAC);//colon(:) separated from build options
|
const char *macStr = QUOTE(CUSTOM_FIRMWARE_MAC);//colon(:) separated from build options
|
||||||
@@ -1992,7 +1991,7 @@ void thermoLoop(void) {
|
|||||||
float curTemp = aJson.getArrayItem(thermoExtensionArray, IET_TEMP)->valuefloat;
|
float curTemp = aJson.getArrayItem(thermoExtensionArray, IET_TEMP)->valuefloat;
|
||||||
|
|
||||||
if (!aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint) {
|
if (!aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint) {
|
||||||
debugSerial<<thermoItem->name<<F(" Expired\n");
|
errorSerial<<thermoItem->name<<F(" Expired\n");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!(--aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint))
|
if (!(--aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint))
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ struct serial_t
|
|||||||
|
|
||||||
const reg_t regSize_P[] PROGMEM =
|
const reg_t regSize_P[] PROGMEM =
|
||||||
{
|
{
|
||||||
{ "i16", (int) PAR_I16 },
|
{ "i16", (uint8_t) PAR_I16 },
|
||||||
{ "i32", (int) PAR_I32 },
|
{ "i32", (uint8_t) PAR_I32 },
|
||||||
{ "u16", (int) PAR_U16 },
|
{ "u16", (uint8_t) PAR_U16 },
|
||||||
{ "u32", (int) PAR_U32 },
|
{ "u32", (uint8_t) PAR_U32 },
|
||||||
{ "i8h", (int) PAR_I8H },
|
{ "i8h", (uint8_t) PAR_I8H },
|
||||||
{ "i8l", (int) PAR_I8L },
|
{ "i8l", (uint8_t) PAR_I8L },
|
||||||
{ "u8h", (int) PAR_U8H },
|
{ "u8h", (uint8_t) PAR_U8H },
|
||||||
{ "u8l", (int) PAR_U8L }
|
{ "u8l", (uint8_t) PAR_U8L }
|
||||||
} ;
|
} ;
|
||||||
#define regSizeNum sizeof(regSize_P)/sizeof(reg_t)
|
#define regSizeNum sizeof(regSize_P)/sizeof(reg_t)
|
||||||
|
|
||||||
@@ -200,6 +200,7 @@ return (result == node.ku8MBSuccess);
|
|||||||
int out_Modbus::findRegister(int registerNum, int posInBuffer)
|
int out_Modbus::findRegister(int registerNum, int posInBuffer)
|
||||||
{
|
{
|
||||||
aJsonObject * paramObj = store->parameters->child;
|
aJsonObject * paramObj = store->parameters->child;
|
||||||
|
bool is8bit = false;
|
||||||
while (paramObj)
|
while (paramObj)
|
||||||
{
|
{
|
||||||
aJsonObject *regObj = aJson.getObjectItem(paramObj, "reg");
|
aJsonObject *regObj = aJson.getObjectItem(paramObj, "reg");
|
||||||
@@ -207,13 +208,50 @@ int out_Modbus::findRegister(int registerNum, int posInBuffer)
|
|||||||
{
|
{
|
||||||
aJsonObject *typeObj = aJson.getObjectItem(paramObj, "type");
|
aJsonObject *typeObj = aJson.getObjectItem(paramObj, "type");
|
||||||
aJsonObject *mapObj = aJson.getObjectItem(paramObj, "map");
|
aJsonObject *mapObj = aJson.getObjectItem(paramObj, "map");
|
||||||
|
aJsonObject * itemParametersObj = aJson.getArrayItem(item->itemArg, 2);
|
||||||
uint16_t data = node.getResponseBuffer(posInBuffer);
|
uint16_t data = node.getResponseBuffer(posInBuffer);
|
||||||
debugSerial << F("MB got ")<<data<< F(" from ")<<paramObj->name<<endl;
|
int8_t regType = PAR_I16;
|
||||||
return 1;
|
uint32_t param =0;
|
||||||
|
itemCmd mappedParam;
|
||||||
|
bool isSigned=false;
|
||||||
|
if (typeObj && typeObj->type == aJson_String) regType=str2regSize(typeObj->valuestring);
|
||||||
|
switch(regType) {
|
||||||
|
|
||||||
|
case PAR_I16:
|
||||||
|
isSigned=true;
|
||||||
|
case PAR_U16:
|
||||||
|
param=data;
|
||||||
|
break;
|
||||||
|
case PAR_I32:
|
||||||
|
isSigned=true;
|
||||||
|
case PAR_U32:
|
||||||
|
param = data | (node.getResponseBuffer(posInBuffer+1)<<16);
|
||||||
|
break;
|
||||||
|
case PAR_U8L:
|
||||||
|
is8bit=true;
|
||||||
|
param = data & 0xFF;
|
||||||
|
break;
|
||||||
|
case PAR_U8H:
|
||||||
|
is8bit=true;
|
||||||
|
param = data << 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapObj && (mapObj->type==aJson_Array || mapObj->type==aJson_Object))
|
||||||
|
mappedParam = mapInt(param,mapObj);
|
||||||
|
else mappedParam.Int(param);
|
||||||
|
|
||||||
|
if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
||||||
|
{
|
||||||
|
aJsonObject *execObj = aJson.getObjectItem(itemParametersObj,paramObj->name);
|
||||||
|
if (execObj) executeCommand(execObj, -1, mappedParam);
|
||||||
|
}
|
||||||
|
debugSerial << F("MB got ")<<param<< F(" from ")<<regType<<F(":")<<paramObj->name<<endl;
|
||||||
|
|
||||||
|
if (!is8bit) return 1;
|
||||||
}
|
}
|
||||||
paramObj=paramObj->next;
|
paramObj=paramObj->next;
|
||||||
}
|
}
|
||||||
return 0;
|
return is8bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_Modbus::Poll(short cause)
|
int out_Modbus::Poll(short cause)
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ const char freeheap_P[] PROGMEM = "freeheap";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Commands
|
//Commands
|
||||||
|
|
||||||
const char ON_P[] PROGMEM = "ON";
|
const char ON_P[] PROGMEM = "ON";
|
||||||
const char OFF_P[] PROGMEM = "OFF";
|
const char OFF_P[] PROGMEM = "OFF";
|
||||||
const char REST_P[] PROGMEM = "REST";
|
const char REST_P[] PROGMEM = "REST";
|
||||||
@@ -79,6 +81,7 @@ const char TOGGLE_P[] PROGMEM = "TOGGLE";
|
|||||||
const char HALT_P[] PROGMEM = "HALT";
|
const char HALT_P[] PROGMEM = "HALT";
|
||||||
const char XON_P[] PROGMEM = "XON";
|
const char XON_P[] PROGMEM = "XON";
|
||||||
const char XOFF_P[] PROGMEM = "XOFF";
|
const char XOFF_P[] PROGMEM = "XOFF";
|
||||||
|
/*
|
||||||
const char INCREASE_P[] PROGMEM = "INCREASE";
|
const char INCREASE_P[] PROGMEM = "INCREASE";
|
||||||
const char DECREASE_P[] PROGMEM = "DECREASE";
|
const char DECREASE_P[] PROGMEM = "DECREASE";
|
||||||
const char TRUE_P[] PROGMEM = "TRUE";
|
const char TRUE_P[] PROGMEM = "TRUE";
|
||||||
@@ -86,15 +89,20 @@ const char FALSE_P[] PROGMEM = "FALSE";
|
|||||||
|
|
||||||
const char ENABLED_P[] PROGMEM = "ENABLED";
|
const char ENABLED_P[] PROGMEM = "ENABLED";
|
||||||
const char DISABLED_P[] PROGMEM = "DISABLED";
|
const char DISABLED_P[] PROGMEM = "DISABLED";
|
||||||
|
*/
|
||||||
const char HEAT_P[] PROGMEM = "HEAT";
|
const char HEAT_P[] PROGMEM = "HEAT";
|
||||||
const char COOL_P[] PROGMEM = "COOL";
|
const char COOL_P[] PROGMEM = "COOL";
|
||||||
const static char AUTO_P[] PROGMEM = "AUTO";
|
const static char AUTO_P[] PROGMEM = "AUTO";
|
||||||
|
|
||||||
|
|
||||||
const char FAN_ONLY_P[] PROGMEM = "FAN_ONLY";
|
const char FAN_ONLY_P[] PROGMEM = "FAN_ONLY";
|
||||||
const char DRY_P[] PROGMEM = "DRY";
|
const char DRY_P[] PROGMEM = "DRY";
|
||||||
const char HIGH_P[] PROGMEM = "HIGH";
|
const char HIGH_P[] PROGMEM = "HIGH";
|
||||||
const char MED_P[] PROGMEM = "MEDIUM";
|
const char MED_P[] PROGMEM = "MEDIUM";
|
||||||
const char LOW_P[] PROGMEM = "LOW";
|
const char LOW_P[] PROGMEM = "LOW";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// SubTopics
|
// SubTopics
|
||||||
const char SET_P[] PROGMEM = "set";
|
const char SET_P[] PROGMEM = "set";
|
||||||
const char CMD_P[] PROGMEM = "cmd";
|
const char CMD_P[] PROGMEM = "cmd";
|
||||||
@@ -102,13 +110,7 @@ const char MODE_P[] PROGMEM = "mode";
|
|||||||
const char FAN_P[] PROGMEM = "fan";
|
const char FAN_P[] PROGMEM = "fan";
|
||||||
const char HUE_P[] PROGMEM = "hue";
|
const char HUE_P[] PROGMEM = "hue";
|
||||||
const char SAT_P[] PROGMEM = "sat";
|
const char SAT_P[] PROGMEM = "sat";
|
||||||
/*
|
|
||||||
const char TEMP_P[] PROGMEM = "temp";
|
|
||||||
const char SETPOINT_P[] PROGMEM = "setpoint";
|
|
||||||
const char POWER_P[] PROGMEM = "power";
|
|
||||||
const char VOL_P[] PROGMEM = "vol";
|
|
||||||
const char HEAT_P[] PROGMEM = "heat";
|
|
||||||
*/
|
|
||||||
const char HSV_P[] PROGMEM = "HSV";
|
const char HSV_P[] PROGMEM = "HSV";
|
||||||
const char RGB_P[] PROGMEM = "RGB";
|
const char RGB_P[] PROGMEM = "RGB";
|
||||||
|
|
||||||
|
|||||||
@@ -521,7 +521,17 @@ bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t m
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool executeCommand(aJsonObject* cmd, int8_t toggle, char* defCmd)
|
|
||||||
|
|
||||||
|
bool executeCommand(aJsonObject* cmd, int8_t toggle)
|
||||||
|
{
|
||||||
|
itemCmd _itemCmd;
|
||||||
|
_itemCmd.type = ST_VOID;
|
||||||
|
return executeCommand(cmd,toggle,_itemCmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd)
|
||||||
|
//bool executeCommand(aJsonObject* cmd, int8_t toggle, char* defCmd)
|
||||||
{
|
{
|
||||||
switch (cmd->type)
|
switch (cmd->type)
|
||||||
{
|
{
|
||||||
@@ -533,7 +543,7 @@ switch (cmd->type)
|
|||||||
aJsonObject * command = cmd->child;
|
aJsonObject * command = cmd->child;
|
||||||
while (command)
|
while (command)
|
||||||
{
|
{
|
||||||
executeCommand(command,toggle,defCmd);
|
executeCommand(command,toggle,_itemCmd);
|
||||||
command = command->next;
|
command = command->next;
|
||||||
}
|
}
|
||||||
configLocked--;
|
configLocked--;
|
||||||
@@ -561,12 +571,13 @@ switch (toggle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char * itemCommand;
|
char * itemCommand;
|
||||||
|
char Buffer[16];
|
||||||
if(icmd && icmd->type == aJson_String) itemCommand = icmd->valuestring;
|
if(icmd && icmd->type == aJson_String) itemCommand = icmd->valuestring;
|
||||||
else itemCommand = defCmd;
|
else itemCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
||||||
|
|
||||||
char * emitCommand;
|
char * emitCommand;
|
||||||
if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
|
if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
|
||||||
else emitCommand = defCmd;
|
else emitCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
||||||
|
|
||||||
//debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
|
//debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
|
||||||
if (item) debugSerial << item->valuestring<< F(" -> ")<<itemCommand<<endl;
|
if (item) debugSerial << item->valuestring<< F(" -> ")<<itemCommand<<endl;
|
||||||
@@ -613,7 +624,11 @@ return false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
itemCmd mapInt(int32_t arg, aJsonObject* map)
|
||||||
|
{
|
||||||
|
itemCmd _itemCmd;
|
||||||
|
return _itemCmd.Int(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "item.h"
|
||||||
#ifdef WITH_PRINTEX_LIB
|
#ifdef WITH_PRINTEX_LIB
|
||||||
#include "PrintEx.h"
|
#include "PrintEx.h"
|
||||||
using namespace ios;
|
using namespace ios;
|
||||||
@@ -60,4 +61,7 @@ void printUlongValueToStr(char *valstr, unsigned long value);
|
|||||||
void scan_i2c_bus();
|
void scan_i2c_bus();
|
||||||
void softRebootFunc();
|
void softRebootFunc();
|
||||||
bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo = 0xFFFFFFFF);
|
bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo = 0xFFFFFFFF);
|
||||||
bool executeCommand(aJsonObject* cmd, int8_t toggle = -1, char* defCmd = NULL);
|
//bool executeCommand(aJsonObject* cmd, int8_t toggle = -1, char* defCmd = NULL);
|
||||||
|
bool executeCommand(aJsonObject* cmd, int8_t toggle = -1);
|
||||||
|
bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd);
|
||||||
|
itemCmd mapInt(int32_t arg, aJsonObject* map);
|
||||||
|
|||||||
Reference in New Issue
Block a user