mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
static ip CLI command/EEPROM saving; reconnection logic refined; new ETHERNET2 lib required
This commit is contained in:
@@ -265,7 +265,23 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
if (itemType!=CH_RGBW || getCmd() != CMD_ON) {
|
if (itemType==CH_RGBW && getCmd() == CMD_ON && getEnableCMD(500)) {
|
||||||
|
Serial.println(F("Force White"));
|
||||||
|
itemType = CH_WHITE;
|
||||||
|
Par[1] = 0; //Zero saturation
|
||||||
|
Par[2] = 100; //Full power
|
||||||
|
// Store
|
||||||
|
st.h = Par[0];
|
||||||
|
st.s = Par[1];
|
||||||
|
st.v = Par[2];
|
||||||
|
setVal(st.aslong);
|
||||||
|
//Send to OH
|
||||||
|
if (send) SendStatus(0, 3, Par);
|
||||||
|
break;
|
||||||
|
} // if forcewhite
|
||||||
|
|
||||||
|
// if (itemType!=CH_RGBW || getCmd() != CMD_ON) {
|
||||||
|
{
|
||||||
short params = 0;
|
short params = 0;
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
//retrive stored values
|
//retrive stored values
|
||||||
@@ -303,8 +319,8 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (send) SendStatus(cmd); // Just send ON
|
if (send) SendStatus(cmd); // Just send ON
|
||||||
}//itemtype
|
}//itemtype switch
|
||||||
else {// Default settings
|
else {// Default settings, values not stored yet
|
||||||
Serial.print(st.aslong);
|
Serial.print(st.aslong);
|
||||||
Serial.println(F(": No stored values - default"));
|
Serial.println(F(": No stored values - default"));
|
||||||
|
|
||||||
@@ -323,18 +339,24 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
params = 3;
|
params = 3;
|
||||||
SendStatus(0, params, Par,true);
|
SendStatus(0, params, Par,true);
|
||||||
break;
|
break;
|
||||||
|
case CH_RELAY:
|
||||||
|
Par[0] = 100;
|
||||||
|
params = 1;
|
||||||
|
if (send) SendStatus(CMD_ON);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Par[0] = 100;
|
Par[0] = 100;
|
||||||
params = 1;
|
params = 1;
|
||||||
SendStatus(0, params, Par);
|
SendStatus(0, params, Par);
|
||||||
}
|
}
|
||||||
}
|
} // default handler
|
||||||
for (short i = 0; i < params; i++) {
|
for (short i = 0; i < params; i++) {
|
||||||
Serial.print(F("Restored: "));
|
Serial.print(F("Restored: "));
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(F("="));
|
Serial.print(F("="));
|
||||||
Serial.println(Par[i]);
|
Serial.println(Par[i]);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
} else { //Double ON - apply special preset - clean white full power
|
} else { //Double ON - apply special preset - clean white full power
|
||||||
if (getEnableCMD(500)) switch (itemType) {
|
if (getEnableCMD(500)) switch (itemType) {
|
||||||
case CH_RGBW:
|
case CH_RGBW:
|
||||||
@@ -354,10 +376,10 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
break;
|
break;
|
||||||
} //itemtype
|
} //itemtype
|
||||||
} //else
|
} //else
|
||||||
|
*/
|
||||||
//Serial.print("Sa:");Serial.println(Par[1]);
|
//Serial.print("Sa:");Serial.println(Par[1]);
|
||||||
if ((itemType == CH_RGBW) && (Par[1] == 0)) itemType = CH_WHITE;
|
if ((itemType == CH_RGBW) && (Par[1] == 0)) itemType = CH_WHITE;
|
||||||
|
}
|
||||||
|
|
||||||
break; //CMD_ON
|
break; //CMD_ON
|
||||||
|
|
||||||
@@ -1084,4 +1106,3 @@ void Item::sendDelayedStatus(){
|
|||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
*
|
*
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -71,7 +66,7 @@ PWM Out
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
@@ -86,6 +81,8 @@ EthernetClient ethClient;
|
|||||||
|
|
||||||
const char outprefix[] PROGMEM = OUTTOPIC;
|
const char outprefix[] PROGMEM = OUTTOPIC;
|
||||||
const char inprefix[] PROGMEM = INTOPIC;
|
const char inprefix[] PROGMEM = INTOPIC;
|
||||||
|
const char configserver[] PROGMEM = CONFIG_SERVER;
|
||||||
|
|
||||||
|
|
||||||
aJsonObject *root = NULL;
|
aJsonObject *root = NULL;
|
||||||
aJsonObject *items = NULL;
|
aJsonObject *items = NULL;
|
||||||
@@ -104,6 +101,7 @@ unsigned long nextThermostatCheck = 0;
|
|||||||
aJsonObject *pollingItem = NULL;
|
aJsonObject *pollingItem = NULL;
|
||||||
|
|
||||||
bool owReady = false;
|
bool owReady = false;
|
||||||
|
bool configOk = false;
|
||||||
int lanStatus = 0;
|
int lanStatus = 0;
|
||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
@@ -118,15 +116,17 @@ PubSubClient mqttClient(ethClient);
|
|||||||
|
|
||||||
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
||||||
|
|
||||||
|
|
||||||
// MQTT Callback routine
|
// MQTT Callback routine
|
||||||
#define MQTT_SUBJECT_LENGTH 20
|
|
||||||
#define MQTT_TOPIC_LENGTH 20
|
|
||||||
|
|
||||||
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||||
payload[length] = 0;
|
|
||||||
Serial.print(F("\n["));
|
Serial.print(F("\n["));
|
||||||
Serial.print(topic);
|
Serial.print(topic);
|
||||||
Serial.print(F("] "));
|
Serial.print(F("] "));
|
||||||
|
if (!payload) return;
|
||||||
|
payload[length] = 0;
|
||||||
|
|
||||||
int fr = freeRam();
|
int fr = freeRam();
|
||||||
if (fr < 250) {
|
if (fr < 250) {
|
||||||
@@ -266,15 +266,30 @@ int lanLoop() {
|
|||||||
switch (lanStatus) {
|
switch (lanStatus) {
|
||||||
//Initial state
|
//Initial state
|
||||||
case 0: //Ethernet.begin(mac,ip);
|
case 0: //Ethernet.begin(mac,ip);
|
||||||
|
{
|
||||||
#ifdef __ESP__
|
#ifdef __ESP__
|
||||||
//WiFi.mode(WIFI_STA);
|
//WiFi.mode(WIFI_STA);
|
||||||
//wifiMulti.addAP("Smartbox", "");
|
//wifiMulti.addAP("Smartbox", "");
|
||||||
if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
||||||
#else
|
#else
|
||||||
|
IPAddress ip;
|
||||||
|
IPAddress dns;
|
||||||
|
IPAddress gw;
|
||||||
|
IPAddress mask;
|
||||||
|
int res = 1;
|
||||||
Serial.println(F("Starting lan"));
|
Serial.println(F("Starting lan"));
|
||||||
|
if (loadFlash(OFFSET_IP,ip))
|
||||||
|
if (loadFlash(OFFSET_DNS,dns))
|
||||||
|
if (loadFlash(OFFSET_GW,gw))
|
||||||
|
if (loadFlash(OFFSET_MASK,mask)) Ethernet.begin(mac,ip,dns,gw,mask);
|
||||||
|
else Ethernet.begin(mac,ip,dns,gw);
|
||||||
|
else Ethernet.begin(mac,ip,dns);
|
||||||
|
else Ethernet.begin(mac,ip);
|
||||||
|
else res = Ethernet.begin(mac, 12000);
|
||||||
|
|
||||||
|
|
||||||
wdt_dis();
|
wdt_dis();
|
||||||
if (Ethernet.begin(mac, 12000) == 0) {
|
if (res == 0) {
|
||||||
Serial.println(F("Failed to configure Ethernet using DHCP"));
|
Serial.println(F("Failed to configure Ethernet using DHCP"));
|
||||||
lanStatus = -10;
|
lanStatus = -10;
|
||||||
lanCheck = millis() + 60000;
|
lanCheck = millis() + 60000;
|
||||||
@@ -284,12 +299,15 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
}
|
}
|
||||||
wdt_en();
|
wdt_en();
|
||||||
wdt_res();
|
wdt_res();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
//Have IP address
|
//Have IP address
|
||||||
case 1:
|
case 1:
|
||||||
|
if (!configOk)
|
||||||
lanStatus = getConfig(0, NULL); //got config from server or load from NVRAM
|
lanStatus = getConfig(0, NULL); //got config from server or load from NVRAM
|
||||||
|
else lanStatus = 2;
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
if (artnet) artnet->begin();
|
if (artnet) artnet->begin();
|
||||||
#endif
|
#endif
|
||||||
@@ -313,6 +331,7 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
if (n >= 5) password = aJson.getArrayItem(mqttArr, 4)->valuestring;
|
if (n >= 5) password = aJson.getArrayItem(mqttArr, 4)->valuestring;
|
||||||
|
|
||||||
mqttClient.setServer(servername, port);
|
mqttClient.setServer(servername, port);
|
||||||
|
mqttClient.setCallback(mqttCallback);
|
||||||
|
|
||||||
Serial.print(F("Attempting MQTT connection to "));
|
Serial.print(F("Attempting MQTT connection to "));
|
||||||
Serial.print(servername);
|
Serial.print(servername);
|
||||||
@@ -322,11 +341,12 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
Serial.print(user);
|
Serial.print(user);
|
||||||
Serial.print(F(" ..."));
|
Serial.print(F(" ..."));
|
||||||
|
|
||||||
|
wdt_dis(); //potential unsafe for ethernetIdle(), but needed to avoid cyclic reboot if mosquitto out of order
|
||||||
if (mqttClient.connect(client_id, user, password)) {
|
if (mqttClient.connect(client_id, user, password)) {
|
||||||
Serial.print(F("connected as "));
|
Serial.print(F("connected as "));
|
||||||
Serial.println(client_id);
|
Serial.println(client_id);
|
||||||
|
wdt_en();
|
||||||
|
configOk=true;
|
||||||
// ... Temporary subscribe to status topic
|
// ... Temporary subscribe to status topic
|
||||||
char buf[MQTT_TOPIC_LENGTH];
|
char buf[MQTT_TOPIC_LENGTH];
|
||||||
|
|
||||||
@@ -349,7 +369,7 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
Serial.print(mqttClient.state());
|
Serial.print(mqttClient.state());
|
||||||
Serial.println(F(" try again in 5 seconds"));
|
Serial.println(F(" try again in 5 seconds"));
|
||||||
lanCheck = millis() + 5000;
|
lanCheck = millis() + 5000;
|
||||||
lanStatus = -12;
|
lanStatus = 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -379,7 +399,7 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
lanStatus = 0;
|
lanStatus = 0;
|
||||||
break;
|
break;
|
||||||
//Reconnect
|
//Reconnect
|
||||||
case -12:
|
case 12:
|
||||||
if (millis() > lanCheck)
|
if (millis() > lanCheck)
|
||||||
|
|
||||||
lanStatus = 2;
|
lanStatus = 2;
|
||||||
@@ -403,9 +423,15 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
wdt_dis();
|
wdt_dis();
|
||||||
if (lanStatus > 0)
|
if (lanStatus > 0)
|
||||||
switch (Ethernet.maintain()) {
|
switch (Ethernet.maintain()) {
|
||||||
|
case NO_LINK:
|
||||||
|
Serial.println(F("No link"));
|
||||||
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
|
lanStatus = -10;
|
||||||
|
break;
|
||||||
case DHCP_CHECK_RENEW_FAIL:
|
case DHCP_CHECK_RENEW_FAIL:
|
||||||
//renewed fail
|
//renewed fail
|
||||||
Serial.println(F("Error: renewed fail"));
|
Serial.println(F("Error: renewed fail"));
|
||||||
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
lanStatus = -10;
|
lanStatus = -10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -416,6 +442,7 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
|
|
||||||
case DHCP_CHECK_REBIND_FAIL:
|
case DHCP_CHECK_REBIND_FAIL:
|
||||||
Serial.println(F("Error: rebind fail"));
|
Serial.println(F("Error: rebind fail"));
|
||||||
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
lanStatus = -10;
|
lanStatus = -10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -530,21 +557,23 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
|||||||
{
|
{
|
||||||
printFirmwareVersionAndBuildOptions();
|
printFirmwareVersionAndBuildOptions();
|
||||||
Serial.println(F("Use the commands: 'help' - this text\n"
|
Serial.println(F("Use the commands: 'help' - this text\n"
|
||||||
"'set 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]]]]'\n"
|
||||||
"'save' - save config in NVRAM\n"
|
"'save' - save config in NVRAM\n"
|
||||||
"'get' - get config from pre-configured URL\n"
|
"'get' [config addr]' - get config from pre-configured URL\n"
|
||||||
"'load' - load config from NVRAM\n"
|
"'load' - load config from NVRAM\n"
|
||||||
"'kill' - test watchdog"));
|
"'kill' - test watchdog"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionKill(int arg_cnt, char **args) {
|
void cmdFunctionKill(int arg_cnt, char **args) {
|
||||||
for (short i = 17; i > 0; i--) {
|
for (short i = 1; i < 20; i++) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println(i);
|
Serial.println(i);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyConfig() {
|
void applyConfig() {
|
||||||
|
if (!root) return;
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
int maxChannels;
|
int maxChannels;
|
||||||
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
||||||
@@ -591,17 +620,19 @@ void applyConfig() {
|
|||||||
items = aJson.getObjectItem(root, "items");
|
items = aJson.getObjectItem(root, "items");
|
||||||
|
|
||||||
// Digital output related Items initialization
|
// Digital output related Items initialization
|
||||||
{
|
pollingItem=NULL;
|
||||||
|
if (items) {
|
||||||
aJsonObject * item = items->child;
|
aJsonObject * item = items->child;
|
||||||
while (items && item)
|
while (items && item)
|
||||||
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
||||||
int cmd = CMD_OFF;
|
Item it(item);
|
||||||
int pin = aJson.getArrayItem(item, I_ARG)->valueint;
|
if (it.isValid()) {
|
||||||
if (aJson.getArraySize(item) > I_CMD) cmd = aJson.getArrayItem(item, I_CMD)->valueint;
|
int pin=it.getArg();
|
||||||
|
int cmd = it.getCmd();
|
||||||
switch (aJson.getArrayItem(item, I_TYPE)->valueint) {
|
switch (it.itemType) {
|
||||||
case CH_RELAY:
|
|
||||||
case CH_THERMO:
|
case CH_THERMO:
|
||||||
|
if (cmd<1) it.setCmd(CMD_OFF);
|
||||||
|
case CH_RELAY:
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
@@ -613,11 +644,11 @@ while (items && item)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} //switch
|
} //switch
|
||||||
|
} //isValid
|
||||||
item = item->next;
|
item = item->next;
|
||||||
} //if
|
} //if
|
||||||
|
|
||||||
}
|
|
||||||
pollingItem = items->child;
|
pollingItem = items->child;
|
||||||
|
}
|
||||||
inputs = aJson.getObjectItem(root, "in");
|
inputs = aJson.getObjectItem(root, "in");
|
||||||
mqttArr = aJson.getObjectItem(root, "mqtt");
|
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||||
printConfigSummary();
|
printConfigSummary();
|
||||||
@@ -660,6 +691,7 @@ int loadConfigFromEEPROM(int arg_cnt, char **args)
|
|||||||
}
|
}
|
||||||
Serial.println(F("Loaded"));
|
Serial.println(F("Loaded"));
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("No stored config"));
|
Serial.println(F("No stored config"));
|
||||||
@@ -719,6 +751,23 @@ void cmdFunctionSave(int arg_cnt, char **args)
|
|||||||
Serial.println(F("Saved to EEPROM"));
|
Serial.println(F("Saved to EEPROM"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmdFunctionIp(int arg_cnt, char **args)
|
||||||
|
//(char* tokens)
|
||||||
|
{ IPAddress ip0 (0,0,0,0);
|
||||||
|
IPAddress ip;
|
||||||
|
DNSClient dns;
|
||||||
|
switch (arg_cnt) {
|
||||||
|
case 5: if (dns.inet_aton(args[4],ip)) saveFlash(OFFSET_MASK,ip); else saveFlash(OFFSET_MASK,ip0);
|
||||||
|
case 4: if (dns.inet_aton(args[3],ip)) saveFlash(OFFSET_GW,ip); else saveFlash(OFFSET_GW,ip0);
|
||||||
|
case 3: if (dns.inet_aton(args[2],ip)) saveFlash(OFFSET_DNS,ip); else saveFlash(OFFSET_DNS,ip0);
|
||||||
|
case 2: if (dns.inet_aton(args[1],ip)) saveFlash(OFFSET_IP,ip); else saveFlash(OFFSET_IP,ip0);
|
||||||
|
break;
|
||||||
|
case 1: //dynamic IP
|
||||||
|
saveFlash(OFFSET_IP,ip0);
|
||||||
|
}
|
||||||
|
Serial.println(F("Saved"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||||
|
|
||||||
@@ -741,22 +790,40 @@ void cmdFunctionSetMac(int arg_cnt, char **args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionGet(int arg_cnt, char **args) {
|
void cmdFunctionGet(int arg_cnt, char **args) {
|
||||||
getConfig(arg_cnt, args);
|
lanStatus=getConfig(arg_cnt, args);
|
||||||
restoreState();
|
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||||
|
//restoreState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printBool(bool arg) { (arg) ? Serial.println(F("on")) : Serial.println(F("off")); }
|
void printBool(bool arg) { (arg) ? Serial.println(F("on")) : Serial.println(F("off")); }
|
||||||
|
|
||||||
|
|
||||||
void saveFlash(short n, char *str) {}
|
void saveFlash(short n, char *str) {
|
||||||
|
short i;
|
||||||
|
short len=strlen(str);
|
||||||
|
if (len>31) len=31;
|
||||||
|
for(int i=0;i<len;i++) EEPROM.write(n+i,str[i]);
|
||||||
|
EEPROM.write(n+len,0);
|
||||||
|
}
|
||||||
|
|
||||||
void loadFlash(short n, char *str) {}
|
int loadFlash(short n, char *str, short l) {
|
||||||
|
short i;
|
||||||
|
uint8_t ch = EEPROM.read(n);
|
||||||
|
if (!ch || (ch == 0xff)) return 0;
|
||||||
|
for (i=0;i<l-1 && (str[i] = EEPROM.read(n++));i++);
|
||||||
|
str[i]=0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef MY_CONFIG_SERVER
|
void saveFlash(short n, IPAddress& ip) {
|
||||||
#define CONFIG_SERVER "lazyhome.ru"
|
for(int i=0;i<4;i++) EEPROM.write(n++,ip[i]);
|
||||||
#else
|
}
|
||||||
#define CONFIG_SERVER QUOTE(MY_CONFIG_SERVER)
|
|
||||||
#endif
|
int loadFlash(short n, IPAddress& ip) {
|
||||||
|
for(int i=0;i<4;i++) ip[i]=EEPROM.read(n++);
|
||||||
|
if (ip[0] && (ip[0] != 0xff)) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int getConfig(int arg_cnt, char **args)
|
int getConfig(int arg_cnt, char **args)
|
||||||
//(char *tokens)
|
//(char *tokens)
|
||||||
@@ -766,11 +833,12 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
int responseStatusCode = 0;
|
int responseStatusCode = 0;
|
||||||
char ch;
|
char ch;
|
||||||
char URI[40];
|
char URI[40];
|
||||||
char configServer[32] = CONFIG_SERVER;
|
char configServer[32]="";
|
||||||
if (arg_cnt > 0) {
|
if (arg_cnt > 1) {
|
||||||
strncpy(configServer, args[1], sizeof(configServer) - 1);
|
strncpy(configServer, args[1], sizeof(configServer) - 1);
|
||||||
saveFlash(0, configServer);
|
saveFlash(OFFSET_CONFIGSERVER, configServer);
|
||||||
} else loadFlash(0, configServer);
|
} else if (!loadFlash(OFFSET_CONFIGSERVER, configServer))
|
||||||
|
strncpy_P(configServer,configserver,sizeof(configServer));
|
||||||
|
|
||||||
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
||||||
mac[5]);
|
mac[5]);
|
||||||
@@ -794,8 +862,11 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
|
|
||||||
Serial.println(F("got Config"));
|
Serial.println(F("got Config"));
|
||||||
aJsonFileStream as = aJsonFileStream(result);
|
aJsonFileStream as = aJsonFileStream(result);
|
||||||
|
noInterrupts();
|
||||||
aJson.deleteItem(root);
|
aJson.deleteItem(root);
|
||||||
root = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
|
interrupts();
|
||||||
|
// Serial.println(F("Parsed."));
|
||||||
hclient.closeStream(result); // this is very important -- be sure to close the STREAM
|
hclient.closeStream(result); // this is very important -- be sure to close the STREAM
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
@@ -806,7 +877,7 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
// char *outstr = aJson.print(root);
|
// char *outstr = aJson.print(root);
|
||||||
// Serial.println(outstr);
|
// Serial.println(outstr);
|
||||||
// free(outstr);
|
// free(outstr);
|
||||||
|
Serial.println(F("Applying."));
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
|
||||||
|
|
||||||
@@ -829,11 +900,12 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
#else
|
#else
|
||||||
//Non AVR code
|
//Non AVR code
|
||||||
String response;
|
String response;
|
||||||
|
EthernetClient configEthClient;
|
||||||
HttpClient htclient = HttpClient(ethClient, configServer, 80);
|
HttpClient htclient = HttpClient(configEthClient, configServer, 80);
|
||||||
|
//htclient.stop(); //_socket =MAX
|
||||||
htclient.setHttpResponseTimeout(4000);
|
htclient.setHttpResponseTimeout(4000);
|
||||||
wdt_res();
|
wdt_res();
|
||||||
//Serial.println("making GET request");
|
//Serial.println("making GET request");get
|
||||||
htclient.beginRequest();
|
htclient.beginRequest();
|
||||||
htclient.get(URI);
|
htclient.get(URI);
|
||||||
htclient.endRequest();
|
htclient.endRequest();
|
||||||
@@ -1013,9 +1085,10 @@ void setupCmdArduino() {
|
|||||||
cmdAdd("save", cmdFunctionSave);
|
cmdAdd("save", cmdFunctionSave);
|
||||||
cmdAdd("load", cmdFunctionLoad);
|
cmdAdd("load", cmdFunctionLoad);
|
||||||
cmdAdd("get", cmdFunctionGet);
|
cmdAdd("get", cmdFunctionGet);
|
||||||
cmdAdd("set", cmdFunctionSetMac);
|
cmdAdd("mac", cmdFunctionSetMac);
|
||||||
cmdAdd("kill", cmdFunctionKill);
|
cmdAdd("kill", cmdFunctionKill);
|
||||||
cmdAdd("req", cmdFunctionReq);
|
cmdAdd("req", cmdFunctionReq);
|
||||||
|
cmdAdd("ip", cmdFunctionIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop_main() {
|
void loop_main() {
|
||||||
@@ -1046,7 +1119,7 @@ void loop_main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (inputs) inputLoop();
|
inputLoop();
|
||||||
|
|
||||||
#if defined (_espdmx)
|
#if defined (_espdmx)
|
||||||
dmxout.update();
|
dmxout.update();
|
||||||
@@ -1072,6 +1145,11 @@ void owIdle(void) {
|
|||||||
dmxout.update();
|
dmxout.update();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
void ethernetIdle(void){
|
||||||
|
wdt_res();
|
||||||
|
inputLoop();
|
||||||
|
// Serial.print(".");
|
||||||
|
};
|
||||||
|
|
||||||
void modbusIdle(void) {
|
void modbusIdle(void) {
|
||||||
wdt_res();
|
wdt_res();
|
||||||
@@ -1080,8 +1158,10 @@ void modbusIdle(void) {
|
|||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
if (artnet) artnet->read();
|
if (artnet) artnet->read();
|
||||||
#endif
|
#endif
|
||||||
|
inputLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _dmxin
|
#ifdef _dmxin
|
||||||
DMXCheck();
|
DMXCheck();
|
||||||
#endif
|
#endif
|
||||||
@@ -1092,6 +1172,7 @@ void modbusIdle(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void inputLoop(void) {
|
void inputLoop(void) {
|
||||||
|
if (!inputs) return;
|
||||||
if (millis() > nextInputCheck) {
|
if (millis() > nextInputCheck) {
|
||||||
aJsonObject *input = inputs->child;
|
aJsonObject *input = inputs->child;
|
||||||
while (input) {
|
while (input) {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "inputs.h"
|
#include "inputs.h"
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
|
#include "Dns.h"
|
||||||
//#include "hsv2rgb.h"
|
//#include "hsv2rgb.h"
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
@@ -95,7 +96,7 @@
|
|||||||
extern Artnet *artnet;
|
extern Artnet *artnet;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void watchdogSetup(void);
|
//void watchdogSetup(void);
|
||||||
|
|
||||||
void mqttCallback(char *topic, byte *payload, unsigned int length);
|
void mqttCallback(char *topic, byte *payload, unsigned int length);
|
||||||
|
|
||||||
@@ -141,9 +142,13 @@ void printBool(bool arg);
|
|||||||
|
|
||||||
void saveFlash(short n, char *str);
|
void saveFlash(short n, char *str);
|
||||||
|
|
||||||
void loadFlash(short n, char *str);
|
int loadFlash(short n, char *str, short l=32);
|
||||||
|
|
||||||
int getConfig(int arg_cnt, char **args);
|
void saveFlash(short n, IPAddress& ip);
|
||||||
|
|
||||||
|
int loadFlash(short n, IPAddress& ip);
|
||||||
|
|
||||||
|
int getConfig(int arg_cnt=0, char **args=NULL);
|
||||||
|
|
||||||
void preTransmission();
|
void preTransmission();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Configuration of drivers enabled
|
// Configuration of drivers enabled
|
||||||
#ifndef PIO_SRC_REV
|
#ifndef PIO_SRC_REV
|
||||||
#define PIO_SRC_REV v0.996
|
#define PIO_SRC_REV v0.997
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TXEnablePin 13
|
#define TXEnablePin 13
|
||||||
@@ -13,9 +13,16 @@
|
|||||||
#define THERMO_OVERHEAT_CELSIUS 38
|
#define THERMO_OVERHEAT_CELSIUS 38
|
||||||
#define FM_OVERHEAT_CELSIUS 40.
|
#define FM_OVERHEAT_CELSIUS 40.
|
||||||
|
|
||||||
#define EEPROM_offset 32+6
|
|
||||||
|
|
||||||
#define INTERVAL_CHECK_INPUT 50
|
#define OFFSET_MAC 0
|
||||||
|
#define OFFSET_IP OFFSET_MAC+6
|
||||||
|
#define OFFSET_DNS OFFSET_IP+4
|
||||||
|
#define OFFSET_GW OFFSET_DNS+4
|
||||||
|
#define OFFSET_MASK OFFSET_GW+4
|
||||||
|
#define OFFSET_CONFIGSERVER OFFSET_MASK+4
|
||||||
|
#define EEPROM_offset OFFSET_CONFIGSERVER+32
|
||||||
|
|
||||||
|
#define INTERVAL_CHECK_INPUT 50
|
||||||
#define INTERVAL_CHECK_MODBUS 2000
|
#define INTERVAL_CHECK_MODBUS 2000
|
||||||
#define INTERVAL_POLLING 100
|
#define INTERVAL_POLLING 100
|
||||||
#define THERMOSTAT_CHECK_PERIOD 5000
|
#define THERMOSTAT_CHECK_PERIOD 5000
|
||||||
@@ -32,15 +39,23 @@
|
|||||||
#define DEFAULT_FIRMWARE_MAC {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0}
|
#define DEFAULT_FIRMWARE_MAC {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MY_CONFIG_SERVER
|
||||||
|
#define CONFIG_SERVER "lazyhome.ru"
|
||||||
|
#else
|
||||||
|
#define CONFIG_SERVER QUOTE(MY_CONFIG_SERVER)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef OUTTOPIC
|
#ifndef OUTTOPIC
|
||||||
#define OUTTOPIC "/myhome/s_out/"
|
#define OUTTOPIC "/myhome/s_out1/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef INTOPIC
|
#ifndef INTOPIC
|
||||||
#define INTOPIC "/myhome/in/"
|
#define INTOPIC "/myhome/in1/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MQTT_SUBJECT_LENGTH 20
|
||||||
|
#define MQTT_TOPIC_LENGTH 20
|
||||||
|
|
||||||
#ifndef DMX_DISABLE
|
#ifndef DMX_DISABLE
|
||||||
#define _dmxin
|
#define _dmxin
|
||||||
#define _dmxout
|
#define _dmxout
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ lib_deps =
|
|||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
https://github.com/anklimov/DS2482_OneWire
|
||||||
https://github.com/anklimov/DmxDue
|
https://github.com/anklimov/DmxDue
|
||||||
https://github.com/arduino-libraries/ArduinoHttpClient
|
https://github.com/anklimov/ArduinoHttpClient
|
||||||
https://github.com/anklimov/aJson
|
https://github.com/anklimov/aJson
|
||||||
https://github.com/anklimov/CmdArduino
|
https://github.com/anklimov/CmdArduino
|
||||||
https://github.com/anklimov/ModbusMaster
|
https://github.com/anklimov/ModbusMaster
|
||||||
@@ -75,7 +75,7 @@ lib_deps =
|
|||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
https://github.com/anklimov/DS2482_OneWire
|
||||||
https://github.com/anklimov/DmxDue
|
https://github.com/anklimov/DmxDue
|
||||||
https://github.com/arduino-libraries/ArduinoHttpClient
|
https://github.com/anklimov/ArduinoHttpClient
|
||||||
https://github.com/anklimov/aJson
|
https://github.com/anklimov/aJson
|
||||||
https://github.com/anklimov/CmdArduino
|
https://github.com/anklimov/CmdArduino
|
||||||
https://github.com/anklimov/ModbusMaster
|
https://github.com/anklimov/ModbusMaster
|
||||||
|
|||||||
Reference in New Issue
Block a user