mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
http API with CORS (interim)
This commit is contained in:
@@ -10,4 +10,5 @@
|
|||||||
-DARDUINO_OTA_MDNS_DISABLE
|
-DARDUINO_OTA_MDNS_DISABLE
|
||||||
-DMDNS_ENABLE
|
-DMDNS_ENABLE
|
||||||
-DMCP23017
|
-DMCP23017
|
||||||
|
-DCORS=\"http://lazyhome.ru\"
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
-DSYSLOG_ENABLE
|
-DSYSLOG_ENABLE
|
||||||
# - udp errors
|
# - udp errors
|
||||||
-DOTA
|
-DOTA
|
||||||
-DARDUINO_OTA_MDNS_DISABLE
|
#-DARDUINO_OTA_MDNS_DISABLE
|
||||||
-DMDNS_ENABLE
|
#-DMDNS_ENABLE - ArduinoMDNS didnt working
|
||||||
|
|
||||||
-DMCP23017
|
-DMCP23017
|
||||||
-DMODBUS_TX_PIN=13
|
-DMODBUS_TX_PIN=13
|
||||||
@@ -41,3 +41,5 @@
|
|||||||
|
|
||||||
#-DAUTOCONNECT_RECONNECT_WAITTIME=60
|
#-DAUTOCONNECT_RECONNECT_WAITTIME=60
|
||||||
|
|
||||||
|
-DFS_STORAGE
|
||||||
|
-DFS_PREPARE
|
||||||
@@ -15,3 +15,6 @@
|
|||||||
-DPID_DISABLE
|
-DPID_DISABLE
|
||||||
-DWiz5100
|
-DWiz5100
|
||||||
-DMOTOR_DISABLE
|
-DMOTOR_DISABLE
|
||||||
|
-DOTA
|
||||||
|
-DARDUINO_OTA_MDNS_DISABLE
|
||||||
|
#-DMDNS_ENABLE
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
~/.platformio/packages/tool-mkspiffs/mkspiffs_espressif32_arduino -c data data.bin
|
~/.platformio/packages/tool-mkspiffs/mkspiffs_espressif32_arduino -s 20480 -c data data.bin
|
||||||
../tools/mac/arduinoOTA -v -address 192.168.88.60 -port 65280 -username arduino -password password -sketch data.bin -upload /data -b
|
../tools/mac/arduinoOTA -v -address 192.168.88.50 -port 65280 -username arduino -password password -sketch data.bin -upload /data -b
|
||||||
@@ -1 +1 @@
|
|||||||
../tools/mac/arduinoOTA -v -address 192.168.88.60 -port 65280 -username arduino -password password -sketch firmware.bin -upload /sketch -b
|
../tools/mac/arduinoOTA -v -address 192.168.88.50 -port 65280 -username arduino -password password -sketch firmware.bin -upload /sketch -b
|
||||||
@@ -49,7 +49,7 @@ bool systemConfig::isValidSysConf()
|
|||||||
{
|
{
|
||||||
if (!stream) return false;
|
if (!stream) return false;
|
||||||
stream->seek(offsetof(systemConfigData,signature));
|
stream->seek(offsetof(systemConfigData,signature));
|
||||||
for (int i=0;i<EEPROM_SIGNATURE_LENGTH;i++)
|
for (int i=0;i<sizeof(systemConfigData::signature);i++)
|
||||||
if (stream->read()!=EEPROM_signature[i])
|
if (stream->read()!=EEPROM_signature[i])
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -74,6 +74,7 @@ bool systemConfig::isValidSysConf()
|
|||||||
|
|
||||||
bool systemConfig::getMQTTpwd(char * buffer, uint16_t bufLen)
|
bool systemConfig::getMQTTpwd(char * buffer, uint16_t bufLen)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +83,18 @@ bool systemConfig::isValidSysConf()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool systemConfig::getOTApwd(char * buffer, uint16_t bufLen)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool systemConfig::setOTApwd(char * pwd)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool systemConfig::setMAC(macAddress mac)
|
bool systemConfig::setMAC(macAddress mac)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -94,61 +107,71 @@ bool systemConfig::isValidSysConf()
|
|||||||
|
|
||||||
bool systemConfig::getServer(char* url)
|
bool systemConfig::getServer(char* url)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool systemConfig::getIP(IPAddress& ip)
|
bool systemConfig::getIP(IPAddress& ip)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool systemConfig::getMask(IPAddress& mask)
|
bool systemConfig::getMask(IPAddress& mask)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool systemConfig::getDNS(IPAddress& dns)
|
bool systemConfig::getDNS(IPAddress& dns)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool systemConfig::getGW(IPAddress& gw)
|
bool systemConfig::getGW(IPAddress& gw)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool systemConfig::setIP(IPAddress& ip)
|
bool systemConfig::setIP(IPAddress& ip)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool systemConfig::setMask(IPAddress& mask)
|
bool systemConfig::setMask(IPAddress& mask)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool systemConfig::setDNS(IPAddress& dns)
|
bool systemConfig::setDNS(IPAddress& dns)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool systemConfig::setGW(IPAddress& gw)
|
bool systemConfig::setGW(IPAddress& gw)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void systemConfig::clear()
|
void systemConfig::clear()
|
||||||
{
|
{
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!stream) return ;
|
if (!stream) return ;
|
||||||
stream->seek(0);
|
stream->seek(0);
|
||||||
for (unsigned int i = 0; i < stream->getSize(); i++) {
|
for (unsigned int i = 0; i < stream->getSize(); i++) {
|
||||||
mac[i] = stream->write(255);
|
stream->write(0);
|
||||||
}
|
}
|
||||||
|
stream->seek(offsetof(systemConfigData,signature));
|
||||||
|
for (unsigned int i=0;i<sizeof(systemConfigData::signature);i++)
|
||||||
|
if (stream->write(EEPROM_signature[i]));
|
||||||
|
stream->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool systemConfig::getSaveSuccedConfig()
|
bool systemConfig::getSaveSuccedConfig()
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ class systemConfig {
|
|||||||
|
|
||||||
bool getMQTTpwd(char * buffer, uint16_t bufLen);
|
bool getMQTTpwd(char * buffer, uint16_t bufLen);
|
||||||
bool setMQTTpwd(char * pwd = NULL);
|
bool setMQTTpwd(char * pwd = NULL);
|
||||||
|
|
||||||
|
bool getOTApwd(char * buffer, uint16_t bufLen);
|
||||||
|
bool setOTApwd(char * pwd = NULL);
|
||||||
|
|
||||||
bool setMAC(macAddress mac);
|
bool setMAC(macAddress mac);
|
||||||
bool setServer(char* url);
|
bool setServer(char* url);
|
||||||
bool getServer(char* url);
|
bool getServer(char* url);
|
||||||
|
|||||||
11
lighthub/discovery.json
Normal file
11
lighthub/discovery.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "Спальня LED_",
|
||||||
|
"command_topic": "myhome/in/bedr/cmd",
|
||||||
|
"state_topic": "myhome/s_out/bedr/cmd",
|
||||||
|
"hs_command_topic": "myhome/in/bedr/set",
|
||||||
|
"hs_state_topic": "myhome/s_out/bedr/set",
|
||||||
|
"hs_value_template": "{%set a=value.split(',')%} {% if a[1] -%} {{a[0]+','+a[1]}} {%- endif %}",
|
||||||
|
"brightness_scale": 100,
|
||||||
|
"brightness_command_topic": "myhome/in/bedr/set",
|
||||||
|
"brightness_state_topic": "myhome/s_out/bedr/set",
|
||||||
|
"brightness_value_template": "{{ value.split(',')[2] }}" }
|
||||||
369
lighthub/error!.txt
Normal file
369
lighthub/error!.txt
Normal file
@@ -0,0 +1,369 @@
|
|||||||
|
help
|
||||||
|
|
||||||
|
Lazyhome.ru LightHub controller 473256d_2021-05-16 C++ version:201103L
|
||||||
|
|
||||||
|
(+)WATCHDOG
|
||||||
|
Config server:lazyhome.ru
|
||||||
|
Firmware MAC Address CUSTOM_FIRMWARE_MAC
|
||||||
|
(+)FreeRam printing
|
||||||
|
(+)DS2482-100
|
||||||
|
(+)Wiznet5x00
|
||||||
|
(+)DMX
|
||||||
|
(+)ADAFRUIT LED
|
||||||
|
(+)MODBUS
|
||||||
|
(+)OWIRE
|
||||||
|
(+)DHT
|
||||||
|
(+)COUNTER
|
||||||
|
(-)HARDRESET, using soft
|
||||||
|
(-)RESTART_LAN_ON_MQTT_ERRORS
|
||||||
|
(+)CCS811 & HDC1080
|
||||||
|
(+)AC HAIER
|
||||||
|
(+)MOTOR CTR
|
||||||
|
(+)SPI LED
|
||||||
|
(+)OTA
|
||||||
|
(+)ARTNET
|
||||||
|
(+)MCP23017
|
||||||
|
(+)PID
|
||||||
|
(+)SYSLOG
|
||||||
|
Reading 128 bits unique identifier
|
||||||
|
ID: 51203120383830503130313232313035
|
||||||
|
Current LAN config(ip,dns,gw,subnet):192.168.11.172, 192.168.11.1, 255.255.255.0,
|
||||||
|
Use these commands: 'help' - this text
|
||||||
|
'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM
|
||||||
|
'ip [ip[,dns[,gw[,subnet]]]]' - set static IP
|
||||||
|
'save' - save config in NVRAM
|
||||||
|
'get' [config addr]' - get config from pre-configured URL and store addr
|
||||||
|
'load' - load config from NVRAM
|
||||||
|
'pwd' - define MQTT password
|
||||||
|
'kill' - test watchdog
|
||||||
|
'clear' - clear EEPROM
|
||||||
|
'reboot' - reboot controller
|
||||||
|
>>
|
||||||
|
|
||||||
|
|
||||||
|
thermostat inactive Set:33.00 Cur:0.00 cmd:2 Expired
|
||||||
|
|
||||||
|
RAM=41128 thermostat inactive Set:33.00 Cur:0.00 cmd:2 Expired
|
||||||
|
|
||||||
|
RAM=41128 load
|
||||||
|
Loading Config from EEPROM
|
||||||
|
No stored config
|
||||||
|
|
||||||
|
>>
|
||||||
|
thermostat inactive Set:33.00 Cur:0.00 cmd:2 Expired
|
||||||
|
|
||||||
|
RAM=41128 get
|
||||||
|
Default config server used: lazyhome.ru
|
||||||
|
Config URI: http://lazyhome.ru/cnf/de-71-d1-a2-92-96.config.json
|
||||||
|
HTTP Status code: 200
|
||||||
|
GET Response: {
|
||||||
|
"mqtt":["edem3","192.168.88.2"],
|
||||||
|
"syslog":["192.168.88.2"],
|
||||||
|
"dmx":[3,80],
|
||||||
|
"topics":{"root":"edem"},
|
||||||
|
"items":
|
||||||
|
{
|
||||||
|
"lightall":[7,[
|
||||||
|
"lampbedr3",
|
||||||
|
"lampcab31",
|
||||||
|
"lampcab32",
|
||||||
|
"lampsauna3",
|
||||||
|
"lampbath33",
|
||||||
|
"lampktc3",
|
||||||
|
"lampwc3",
|
||||||
|
"lamp4",
|
||||||
|
"lampext4",
|
||||||
|
"lamphall3",
|
||||||
|
"lampstw3",
|
||||||
|
"fasadeast",
|
||||||
|
"bra31",
|
||||||
|
"lampgst3",
|
||||||
|
"lampkln3",
|
||||||
|
"lampbalk3",
|
||||||
|
"fasadsouth",
|
||||||
|
"bra32"]],
|
||||||
|
"gr_hall3":[7,["lamphall3","lampstw3","lampwc3"]],
|
||||||
|
"gr_gost3":[7,["lampgst3","lampktc3"]],
|
||||||
|
"gr_kab3":[7,["lampcab31","lampcab32"]],
|
||||||
|
"relays":[7,["pout0","thermostat","pout2","pout3","pout4","pout5","pout6"]],
|
||||||
|
"uouts":[7,["unprot0","unprot1","unprot2","unprot3","unprot4","unprot5","unprot6","unprot7"]],
|
||||||
|
|
||||||
|
"mb1":[44,[1,0,3,100]],
|
||||||
|
"mb2":[44,[1,1,3,100]],
|
||||||
|
"mb3":[44,[1,2,3,100]],
|
||||||
|
"mb4":[44,[1,3,3,100]],
|
||||||
|
"mba":[44,[96,0,0]],
|
||||||
|
|
||||||
|
"lampbedr3":[0,3],
|
||||||
|
"lampcab31":[0,9],
|
||||||
|
"lampcab32":[0,4],
|
||||||
|
|
||||||
|
"lampsauna3":[0,11],
|
||||||
|
"lampbath3":[0,5],
|
||||||
|
"lampwc3":[0,2],
|
||||||
|
|
||||||
|
"lampktc3":[0,7],
|
||||||
|
"lamp4":[0,8],
|
||||||
|
"lamphall3":[0,1],
|
||||||
|
|
||||||
|
"lampext4":[0,10],
|
||||||
|
"lampstw3":[0,6],
|
||||||
|
"fasadeast":[0,12],
|
||||||
|
|
||||||
|
"lampgst3":[0,13],
|
||||||
|
"bra31":[0,14],
|
||||||
|
"bra32":[0,15],
|
||||||
|
|
||||||
|
"lampbalk3":[0,16],
|
||||||
|
"fasadsouth":[0,17],
|
||||||
|
"lampkln3":[0,18],
|
||||||
|
"lampbar3":[0,21],
|
||||||
|
|
||||||
|
"ledbedr3":[1,22],
|
||||||
|
"ledcab31":[1,26],
|
||||||
|
"ledcab32":[1,30],
|
||||||
|
"ledkab":[7,["ledcab31","ledcab32"]],
|
||||||
|
"ledsauna31":[1,34],
|
||||||
|
"ledsauna32":[1,38],
|
||||||
|
"ledsauna":[7,["ledsauna31","ledsauna32"]],
|
||||||
|
"led4":[1,42],
|
||||||
|
|
||||||
|
"ledktc31":[1,48],
|
||||||
|
"ledktc31w":[0,52],
|
||||||
|
"ledktc32":[1,53],
|
||||||
|
"ledktc32w":[0,57],
|
||||||
|
"ledgst31":[1,58],
|
||||||
|
"ledgst31w":[0,62],
|
||||||
|
"ledgst32":[1,63],
|
||||||
|
"ledgst32w":[0,67],
|
||||||
|
"ledktc3w":[7,["ledktc31w","ledktc32w","ledgst31w","ledgst32w"]],
|
||||||
|
"ledktc3":[7,["ledktc31","ledktc32","ledgst31","ledgst32"]],
|
||||||
|
|
||||||
|
"fanbath3":[0,68],
|
||||||
|
"fanwc3":[0,69],
|
||||||
|
|
||||||
|
"pout0":[6,22],
|
||||||
|
"thermostat":[5,23,33],
|
||||||
|
"pout2":[6,24],
|
||||||
|
"water3":[6,25],
|
||||||
|
"pout4":[3,9],
|
||||||
|
"pout5":[3,8],
|
||||||
|
"pout6":[3,11],
|
||||||
|
"pout7":[6,12],
|
||||||
|
|
||||||
|
|
||||||
|
"pwm0" :[3,4],
|
||||||
|
"pwm1" :[3,5],
|
||||||
|
"pwm2" :[3,6],
|
||||||
|
"pwm3" :[3,7],
|
||||||
|
"pwm10":[3,10],
|
||||||
|
|
||||||
|
|
||||||
|
"unprot0":[6,33],
|
||||||
|
"unprot1":[6,32],
|
||||||
|
"unprot2":[6,31],
|
||||||
|
"unprot3":[6,30],
|
||||||
|
"unprot4":[6,29],
|
||||||
|
"unprot5":[6,28],
|
||||||
|
"unprot6":[6,27],
|
||||||
|
"unprot7":[6,26]
|
||||||
|
},
|
||||||
|
|
||||||
|
"in":
|
||||||
|
[ {"#":42,"emit":"power3","item":"fanwc3"},
|
||||||
|
{"#":44,"emit":"in1"},
|
||||||
|
{"#":46,"emit":"in2"},
|
||||||
|
{"#":49,"emit":"in3"},
|
||||||
|
{"#":43,"emit":"in4"},
|
||||||
|
{"#":45,"emit":"in5"},
|
||||||
|
{"#":47,"emit":"in6"},
|
||||||
|
{"#":48,"emit":"in7"},
|
||||||
|
{"#":34,"emit":"in8"},
|
||||||
|
{"#":36,"emit":"in9"},
|
||||||
|
|
||||||
|
{"#":38,"T":0,
|
||||||
|
"click":{"item":"gr_hall3","icmd":"80"},
|
||||||
|
"dclick":{"item":"lampbedr3","icmd":"ON"},
|
||||||
|
"tclick":{"item":"lightall","icmd":"REST"},
|
||||||
|
"rpcmd":{"item":"gr_hall3","icmd":"%+2"}
|
||||||
|
},
|
||||||
|
{"#":40,"T":0,
|
||||||
|
"click":{"item":"gr_hall3","icmd":"OFF"},
|
||||||
|
"dclick":{"item":"lampbedr3","icmd":"OFF"},
|
||||||
|
"tclick":{"item":"lightall","icmd":"HALT"},
|
||||||
|
"rpcmd":{"item":"gr_hall3","icmd":"%-2"}
|
||||||
|
},
|
||||||
|
{"#":35,"T":0,
|
||||||
|
"click":{"item":"gr_gost3","icmd":"ON"},
|
||||||
|
"dclick":{"item":"gr_kab3","icmd":"ON"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"ON"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%+2"}
|
||||||
|
},
|
||||||
|
{"#":37,"T":0,
|
||||||
|
"click":{"item":"gr_gost3","icmd":"OFF"},
|
||||||
|
"dclick":{"item":"gr_kab3","icmd":"OFF"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"OFF"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%-2"}
|
||||||
|
},
|
||||||
|
|
||||||
|
{"#":39,"emit":"in14"},
|
||||||
|
{"#":41,"emit":"in15"},
|
||||||
|
|
||||||
|
{"#":54,"T":0,"act":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"map":[128,640],
|
||||||
|
"click":{"item":"gr_gost3","icmd":"ON"},
|
||||||
|
"dclick":{"item":"gr_kab3","icmd":"ON"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"ON"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%+2"}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"map":[641,1024],
|
||||||
|
"click":{"item":"gr_gost3","icmd":"OFF"},
|
||||||
|
"dclick":{"item":"gr_kab3","icmd":"OFF"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"OFF"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%-2"}
|
||||||
|
}
|
||||||
|
]},
|
||||||
|
{"#":55,"T":66,"emit":"a01","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
{"#":56,"T":66,"emit":"a02","map":[0,1024,0,1024,10]},
|
||||||
|
{"#":57,"T":66,"emit":"a03","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
{"#":58,"T":66,"emit":"a04","map":[0,1024,0,1024,10]},
|
||||||
|
{"#":59,"T":66,"emit":"a05","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
{"#":60,"T":0,"act":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"map":[128,640],
|
||||||
|
"click":{"item":"gr_hall3","icmd":"50"},
|
||||||
|
"dclick":{"item":"lampbedr3","icmd":"ON"},
|
||||||
|
"tclick":{"item":"lightall","icmd":"REST"},
|
||||||
|
"rpcmd":{"item":"gr_hall3","icmd":"%+2"}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"map":[641,1024],
|
||||||
|
"click":{"item":"gr_hall3","icmd":"OFF"},
|
||||||
|
"dclick":{"item":"lampbedr3","icmd":"OFF"},
|
||||||
|
"tclick":{"item":"lightall","icmd":"HALT"},
|
||||||
|
"rpcmd":{"item":"gr_hall3","icmd":"%-2"}
|
||||||
|
}
|
||||||
|
]},
|
||||||
|
{"#":61,"T":0,"act":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"map":[128,640],
|
||||||
|
"click":{"item":"gr_gost3","icmd":"ON"},
|
||||||
|
"dclick":{"item":"gr_kab3","icmd":"ON"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"ON"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%+2"}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"map":[641,1024],
|
||||||
|
"click":{"item":"gr_gost3","icmd":"OFF"},
|
||||||
|
"dclick":{"item":"gr_kab3","icmd":"OFF"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"OFF"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%-2"}
|
||||||
|
}
|
||||||
|
]},
|
||||||
|
|
||||||
|
{"#":62,"T":66,"emit":"a08","map":[0,1024,0,1024,10]},
|
||||||
|
{"#":63,"T":66,"emit":"a09","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
{"#":64,"T":66,"emit":"a10","map":[0,1024,0,1024,10]},
|
||||||
|
{"#":65,"T":66,"emit":"a11","map":[0,1024,0,1024,10]},
|
||||||
|
{"#":66,"T":0,"emit":"leak31","item":"water3","scmd":"OFF","rcmd":"ON"},
|
||||||
|
{"#":67,"T":2,"emit":"leak32","item":"water3","scmd":"OFF","rcmd":"ON"},
|
||||||
|
{"#":68,"T":0,"emit":"leak33","item":"water3","scmd":"OFF","rcmd":"ON"},
|
||||||
|
{"#":69,"T":0,"emit":"a15"}
|
||||||
|
],
|
||||||
|
|
||||||
|
"in2":
|
||||||
|
{ "42":{"emit":"power3","item":"fanwc3"},
|
||||||
|
"44":{"emit":"in1"},
|
||||||
|
"46":{"emit":"in2"},
|
||||||
|
"49":{"emit":"in3"},
|
||||||
|
"43":{"emit":"in4"},
|
||||||
|
"45":{"emit":"in5"},
|
||||||
|
"47":{"emit":"in6"},
|
||||||
|
"48":{"emit":"in7"},
|
||||||
|
"34":{"emit":"in8"},
|
||||||
|
"36":{"emit":"in9"},
|
||||||
|
|
||||||
|
"38":{"T":0,
|
||||||
|
"click":{"item":"gr_hall3","icmd":"ON"},
|
||||||
|
"dclick":{"item":"lampbedr3","icmd":"ON"},
|
||||||
|
"tclick":{"item":"lightall","icmd":"REST"},
|
||||||
|
"rpcmd":{"item":"gr_hall3","icmd":"%+2"}
|
||||||
|
},
|
||||||
|
"40":{"T":0,
|
||||||
|
"click":{"item":"gr_hall3","icmd":"OFF"},
|
||||||
|
"dclick":{"item":"lampbedr3","icmd":"OFF"},
|
||||||
|
"tclick":{"item":"lightall","icmd":"HALT"},
|
||||||
|
"rpcmd":{"item":"gr_hall3","icmd":"%-2"}
|
||||||
|
},
|
||||||
|
"35":{"T":0,
|
||||||
|
"click":{"item":"gr_gost3","icmd":"ON"},
|
||||||
|
"dclick":{"item":"lampwc3","icmd":"ON"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"ON"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%+2"}
|
||||||
|
},
|
||||||
|
"37":{"T":0,
|
||||||
|
"click":{"item":"gr_gost3","icmd":"OFF"},
|
||||||
|
"dclick":{"item":"lampwc3","icmd":"OFF"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"OFF"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%-2"}
|
||||||
|
},
|
||||||
|
|
||||||
|
"39":{"emit":"in14"},
|
||||||
|
"41":{"emit":"in15"},
|
||||||
|
|
||||||
|
"54":{"addr":54,"T":0,"act":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"map":[128,640],
|
||||||
|
"click":{"item":"gr_gost3","icmd":"ON"},
|
||||||
|
"dclick":{"item":"lampwc3","icmd":"ON"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"ON"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%+2"}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"map":[641,1024],
|
||||||
|
"click":{"item":"gr_gost3","icmd":"OFF"},
|
||||||
|
"dclick":{"item":"lampwc3","icmd":"OFF"},
|
||||||
|
"tclick":{"item":"lampbath3","icmd":"OFF"},
|
||||||
|
"rpcmd":{"item":"gr_gost3","icmd":"%-2"}
|
||||||
|
}
|
||||||
|
]},
|
||||||
|
"55":{"T":66,"emit":"a01","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
"56":{"T":66,"emit":"a02","map":[0,1024,0,1024,10]},
|
||||||
|
"57":{"T":66,"emit":"a03","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
"58":{"T":66,"emit":"a04","map":[0,1024,0,1024,10]},
|
||||||
|
"59":{"T":66,"emit":"a05","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
"60":{"T":66,"emit":"a06","map":[0,1024,0,1024,10]},
|
||||||
|
"61":{"T":66,"emit":"a07","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
"62":{"T":66,"emit":"a08","map":[0,1024,0,1024,10]},
|
||||||
|
"63":{"T":66,"emit":"a09","map":[0,1024,0,1024,10]},
|
||||||
|
|
||||||
|
"64":{"T":66,"emit":"a10","map":[0,1024,0,1024,10]},
|
||||||
|
"65":{"T":66,"emit":"a11","map":[0,1024,0,1024,10]},
|
||||||
|
"66":{"T":0,"emit":"leak31","item":"water3","scmd":"OFF","rcmd":"ON"},
|
||||||
|
"67":{"T":2,"emit":"leak32","item":"water3","scmd":"OFF","rcmd":"ON"},
|
||||||
|
"68":{"T":0,"emit":"leak33","item":"water3","scmd":"OFF","rcmd":"ON"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Free:29320
|
||||||
|
Unlocking config ...
|
||||||
|
|
||||||
|
Default config server used: lazyhome.ru
|
||||||
|
Config URI: http://lazyhome.ru/cnf/de-71-d1-a2-92-96.config.json
|
||||||
|
HTTP Status code>>>
|
||||||
|
Lazyhome.ru LightHub controller 473256d_2021-05-16 C++ version:201103L
|
||||||
|
|
||||||
|
(+)WATCHDOG
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(FS_STORAGE)
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -13,6 +13,10 @@
|
|||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ESP32) && !defined(FS_STORAGE)
|
||||||
|
#include <EEPROM.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
#include <ESP_EEPROM.h>
|
#include <ESP_EEPROM.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -39,6 +43,7 @@ extern NRFFlashStorage EEPROM;
|
|||||||
|
|
||||||
class seekableStream : public Stream
|
class seekableStream : public Stream
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
unsigned int streamSize;
|
unsigned int streamSize;
|
||||||
public:
|
public:
|
||||||
seekableStream(unsigned int size):Stream(),streamSize(size) {};
|
seekableStream(unsigned int size):Stream(),streamSize(size) {};
|
||||||
@@ -46,18 +51,22 @@ unsigned int getSize() {return streamSize;}
|
|||||||
virtual unsigned int seek(unsigned int _pos = 0) = 0;
|
virtual unsigned int seek(unsigned int _pos = 0) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(FS_STORAGE)
|
||||||
class flashStream : public seekableStream
|
class flashStream : public seekableStream
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
File fs;
|
File fs;
|
||||||
public:
|
public:
|
||||||
flashStream(String _filename):seekableStream(65535) {fs = SPIFFS.open(_filename, "r+");}
|
flashStream(String _filename):seekableStream(65535)
|
||||||
virtual int available() { return 1; };
|
{
|
||||||
|
fs = SPIFFS.open(_filename, "a+");
|
||||||
|
if (!fs) SPIFFS.open(_filename, "w+");
|
||||||
|
}
|
||||||
|
virtual int available() { return fs.available(); };
|
||||||
virtual int read() {return fs.read();};
|
virtual int read() {return fs.read();};
|
||||||
virtual int peek() { return fs.peek();};
|
virtual int peek() { return fs.peek();};
|
||||||
virtual unsigned int seek(unsigned int _pos = 0){return fs.seek(_pos,SeekSet);};
|
virtual unsigned int seek(unsigned int _pos = 0){return fs.seek(_pos,SeekSet);};
|
||||||
virtual void flush() {};
|
virtual void flush() {return fs.flush();};
|
||||||
virtual size_t write(uint8_t ch) {return fs.write(ch);};
|
virtual size_t write(uint8_t ch) {return fs.write(ch);};
|
||||||
void putEOF(){write (255);};
|
void putEOF(){write (255);};
|
||||||
virtual ~flashStream () {if (fs) fs.close();} ;
|
virtual ~flashStream () {if (fs) fs.close();} ;
|
||||||
@@ -71,29 +80,36 @@ class flashStream : public seekableStream
|
|||||||
protected:
|
protected:
|
||||||
unsigned int pos;
|
unsigned int pos;
|
||||||
unsigned int startPos;
|
unsigned int startPos;
|
||||||
unsigned int size;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
flashStream(unsigned int _startPos=0, unsigned int _size=4096 ):seekableStream(_size)
|
flashStream(unsigned int _startPos=0, unsigned int _size=4096 ):seekableStream(_size)
|
||||||
{
|
{
|
||||||
pos = _startPos; startPos = _startPos; size = _size;
|
pos = _startPos; startPos = _startPos;
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
size_t len = EEPROM.length();
|
size_t len = EEPROM.length();
|
||||||
if (len) EEPROM.commit();
|
if (len) EEPROM.commit();
|
||||||
EEPROM.begin(len+size); //Re-init
|
EEPROM.begin(len+streamSize); //Re-init
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual unsigned int seek(unsigned int _pos = 0)
|
virtual unsigned int seek(unsigned int _pos = 0)
|
||||||
{ pos=min(startPos+_pos, startPos+size);
|
{ pos=min(startPos+_pos, startPos+streamSize);
|
||||||
debugSerial<<F("Seek:")<<pos<<endl;
|
debugSerial<<F("Seek:")<<pos<<endl;
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
virtual int available() { return 1;};
|
virtual int available() { return (pos<streamSize);};
|
||||||
virtual int read() {int ch = peek(); pos++; return ch;};
|
virtual int read()
|
||||||
|
{
|
||||||
|
int ch = peek();
|
||||||
|
pos++;
|
||||||
|
return ch;
|
||||||
|
};
|
||||||
virtual int peek()
|
virtual int peek()
|
||||||
{
|
{
|
||||||
|
if (pos<streamSize)
|
||||||
return EEPROM.read(pos);
|
return EEPROM.read(pos);
|
||||||
|
else return -1;
|
||||||
};
|
};
|
||||||
virtual void flush() {
|
virtual void flush() {
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
|
|||||||
@@ -925,7 +925,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
|
|||||||
if (driver) //New style modular code
|
if (driver) //New style modular code
|
||||||
{
|
{
|
||||||
int res = -1;
|
int res = -1;
|
||||||
switch (cmd.getCmd())
|
switch (st.getCmd()) ///cmd///???????st ??? wtf
|
||||||
{
|
{
|
||||||
case CMD_XON:
|
case CMD_XON:
|
||||||
if (!chActive) //if channel was'nt active before CMD_XON
|
if (!chActive) //if channel was'nt active before CMD_XON
|
||||||
@@ -987,7 +987,11 @@ if (driver) //New style modular code
|
|||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
//debugSerial<<"ON!"<<endl;
|
//debugSerial<<"ON!"<<endl;
|
||||||
if (chActive) break;
|
if (chActive) break;
|
||||||
|
res = driver->Ctrl(st, subItem);
|
||||||
|
st.saveItem(this);
|
||||||
|
setCmd(st.getCmd());
|
||||||
|
SendStatus(SEND_COMMAND);
|
||||||
|
break;
|
||||||
default: //another command
|
default: //another command
|
||||||
if (cmd.isCommand()) st.Cmd(cmd.getCmd());
|
if (cmd.isCommand()) st.Cmd(cmd.getCmd());
|
||||||
//debugSerial<<"DEF!"<<endl;
|
//debugSerial<<"DEF!"<<endl;
|
||||||
|
|||||||
@@ -922,8 +922,8 @@ bool itemCmd::loadItem(Item * item, bool includeCommand)
|
|||||||
param.asInt32=item->getVal();
|
param.asInt32=item->getVal();
|
||||||
cmd.itemArgType= subtype;
|
cmd.itemArgType= subtype;
|
||||||
if (includeCommand) cmd.cmdCode=item->getCmd();
|
if (includeCommand) cmd.cmdCode=item->getCmd();
|
||||||
debugSerial<<F("Loaded :");
|
// debugSerial<<F("Loaded :");
|
||||||
debugOut();
|
// debugOut();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
switch (item->itemVal->type)
|
switch (item->itemVal->type)
|
||||||
@@ -931,14 +931,14 @@ bool itemCmd::loadItem(Item * item, bool includeCommand)
|
|||||||
case aJson_Int:
|
case aJson_Int:
|
||||||
|
|
||||||
Int((int32_t)item->itemVal->valueint);
|
Int((int32_t)item->itemVal->valueint);
|
||||||
debugSerial<<F("Loaded Int:");
|
// debugSerial<<F("Loaded Int:");
|
||||||
debugOut();
|
// debugOut();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case aJson_Float:
|
case aJson_Float:
|
||||||
Float(item->itemVal->valueint);
|
Float(item->itemVal->valueint);
|
||||||
debugSerial<<F("Loaded Float:");
|
// debugSerial<<F("Loaded Float:");
|
||||||
debugOut();
|
// debugOut();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,59 +15,6 @@ limitations under the License.
|
|||||||
Homepage: http://lazyhome.ru
|
Homepage: http://lazyhome.ru
|
||||||
GIT: https://github.com/anklimov/lighthub
|
GIT: https://github.com/anklimov/lighthub
|
||||||
e-mail anklimov@gmail.com
|
e-mail anklimov@gmail.com
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Done:
|
|
||||||
* MQMT/openhab
|
|
||||||
* 1-wire
|
|
||||||
* DMX - out
|
|
||||||
* DMX IN
|
|
||||||
* 1809 strip out (discarded)
|
|
||||||
* Modbus master Out
|
|
||||||
* DHCP
|
|
||||||
* JSON config
|
|
||||||
* cli
|
|
||||||
* PWM Out 7,8,9
|
|
||||||
* 1-w relay out
|
|
||||||
* Termostat out
|
|
||||||
|
|
||||||
Todo (backlog)
|
|
||||||
===
|
|
||||||
rotary encoder local ctrl ?
|
|
||||||
analog in local ctrl
|
|
||||||
Smooth regulation/fading
|
|
||||||
PID Termostat out ?
|
|
||||||
dmx relay out
|
|
||||||
Relay array channel
|
|
||||||
Relay DMX array channel
|
|
||||||
Config URL & MQTT password commandline configuration
|
|
||||||
1-wire Update refactoring (save memory)
|
|
||||||
Topic configuration
|
|
||||||
Timer
|
|
||||||
Modbus response check
|
|
||||||
control/debug (Commandline) over MQTT
|
|
||||||
more Modbus dimmers
|
|
||||||
|
|
||||||
todo DUE related:
|
|
||||||
PWM freq fix
|
|
||||||
Config webserver
|
|
||||||
SSL
|
|
||||||
|
|
||||||
todo ESP:
|
|
||||||
Config webserver
|
|
||||||
SSL
|
|
||||||
|
|
||||||
ESP32
|
|
||||||
PWM Out
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
|
||||||
#include "FS.h"
|
|
||||||
#endif
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
@@ -76,7 +23,7 @@ PWM Out
|
|||||||
#include "flashstream.h"
|
#include "flashstream.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(FS_STORAGE)
|
||||||
flashStream sysConfStream("config.bin");
|
flashStream sysConfStream("config.bin");
|
||||||
flashStream JSONStream("config.json");
|
flashStream JSONStream("config.json");
|
||||||
#else
|
#else
|
||||||
@@ -291,92 +238,158 @@ bool isNotRetainingStatus() {
|
|||||||
return (lanStatus != RETAINING_COLLECTING);
|
return (lanStatus != RETAINING_COLLECTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
int httpHandler(Client& client, String request, long contentLength)
|
int httpHandler(Client& client, String request, long contentLength, bool authorized)
|
||||||
{
|
{
|
||||||
|
String response = "";
|
||||||
|
|
||||||
debugSerial<<request<<endl;
|
debugSerial<<request<<endl;
|
||||||
return -1;
|
|
||||||
|
|
||||||
|
if (request == (F("GET /")))
|
||||||
|
{
|
||||||
|
client.println(F("HTTP/1.1 301 Moved permanently"));
|
||||||
|
client.print(F("Location: http://lazyhome.ru/pwa?mac="));
|
||||||
|
for (int i=0; i<6; i++) {client.print(sysConf.mac[i]>>4,HEX);client.print(sysConf.mac[i]&0xf,HEX);}
|
||||||
|
client.print(F("&ip="));
|
||||||
|
client.println(Ethernet.localIP());
|
||||||
|
delay(100);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!authorized) return 401;
|
||||||
|
|
||||||
|
if (request.startsWith(F("POST /item/")))
|
||||||
|
{
|
||||||
|
request.remove(0,11);
|
||||||
|
String body=client.readStringUntil('\n');
|
||||||
|
Item item((char*)request.c_str());
|
||||||
|
if (!item.isValid() || !item.Ctrl((char*) body.c_str())) return 400;
|
||||||
|
|
||||||
|
itemCmd ic;
|
||||||
|
ic.loadItem(&item,true);
|
||||||
|
char buf[32];
|
||||||
|
response=ic.toString(buf, sizeof(buf));
|
||||||
|
}
|
||||||
|
else if (request.startsWith(F("GET /item/")))
|
||||||
|
{
|
||||||
|
request.remove(0,10);
|
||||||
|
Item item((char*)request.c_str());
|
||||||
|
if (!item.isValid()) return 400;
|
||||||
|
|
||||||
|
itemCmd ic;
|
||||||
|
ic.loadItem(&item,true);
|
||||||
|
char buf[32];
|
||||||
|
response=ic.toString(buf, sizeof(buf));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (request.startsWith(F("POST /command/")))
|
||||||
|
{
|
||||||
|
request.remove(0,14);
|
||||||
|
String body=client.readStringUntil('\n');
|
||||||
|
|
||||||
|
request+=" ";
|
||||||
|
request+=body;
|
||||||
|
|
||||||
|
debugSerial<<F("Cmd: ")<<request<<endl;
|
||||||
|
if (request=="reboot") client.stop();
|
||||||
|
const char* res=request.c_str();
|
||||||
|
cmd_parse((char*) res);
|
||||||
|
}
|
||||||
|
else return -1; //Unknown
|
||||||
|
|
||||||
|
client.println(F("HTTP/1.1 200 OK"));
|
||||||
|
client.println(F("Connection: close"));
|
||||||
|
|
||||||
|
#ifdef CORS
|
||||||
|
client.print(F("Access-Control-Allow-Origin: "));
|
||||||
|
client.println(CORS);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (response!="") {
|
||||||
|
client.println("Content-Type: text/plain");
|
||||||
|
client.println();
|
||||||
|
client.println(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
int inTopic (char * topic, topicType tt)
|
||||||
debugSerial<<F("\n[")<<topic<<F("] ");
|
{
|
||||||
if (!payload) return;
|
char buf[MQTT_TOPIC_LENGTH + 1];
|
||||||
|
int pfxlen;
|
||||||
|
int intopic;
|
||||||
|
setTopic(buf,sizeof(buf)-1,tt);
|
||||||
|
pfxlen = strlen(buf);
|
||||||
|
intopic = strncmp(topic, buf, pfxlen);
|
||||||
|
// debugSerial<<buf<<" "<<pfxlen<<" "<<intopic<<endl;
|
||||||
|
if (!intopic) return pfxlen;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mqttCallback(char *topic, byte *payload, unsigned int length)
|
||||||
|
{
|
||||||
|
if (!payload) return;
|
||||||
payload[length] = 0;
|
payload[length] = 0;
|
||||||
|
// itemCommand(topic, (char*) payload);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//int itemCommand(char *topic, char *payload){
|
||||||
|
|
||||||
int fr = freeRam();
|
int fr = freeRam();
|
||||||
|
|
||||||
|
debugSerial<<F("\n")<<fr<<F(":[")<<topic<<F("] ");
|
||||||
|
|
||||||
if (fr < 250) {
|
if (fr < 250) {
|
||||||
errorSerial<<F("OutOfMemory!")<<endl;
|
errorSerial<<F("OutOfMemory!")<<endl;
|
||||||
return;
|
return;// -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
statusLED.flash(ledBLUE);
|
statusLED.flash(ledBLUE);
|
||||||
for (unsigned int i = 0; i < length; i++)
|
debugSerial<<(char*)payload<<endl;
|
||||||
debugSerial<<((char) payload[i]);
|
|
||||||
debugSerial<<endl;
|
|
||||||
|
|
||||||
short intopic = 0;
|
|
||||||
short pfxlen = 0;
|
short pfxlen = 0;
|
||||||
char * itemName = NULL;
|
char * itemName = NULL;
|
||||||
char * subItem = NULL;
|
char * subItem = NULL;
|
||||||
|
|
||||||
{
|
// in Retaining status - trying to restore previous state from retained output topic. Retained input topics are not relevant.
|
||||||
char buf[MQTT_TOPIC_LENGTH + 1];
|
if (lanStatus == RETAINING_COLLECTING) pfxlen=inTopic(topic,T_OUT);
|
||||||
|
|
||||||
|
|
||||||
if (lanStatus == RETAINING_COLLECTING)
|
|
||||||
{
|
|
||||||
setTopic(buf,sizeof(buf),T_OUT);
|
|
||||||
pfxlen = strlen(buf);
|
|
||||||
intopic = strncmp(topic, buf, pfxlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setTopic(buf,sizeof(buf),T_BCST);
|
pfxlen=inTopic(topic,T_BCST);
|
||||||
pfxlen = strlen(buf);
|
if (!pfxlen) pfxlen = inTopic(topic,T_DEV);
|
||||||
intopic = strncmp(topic, buf, pfxlen );
|
|
||||||
|
|
||||||
if (intopic)
|
|
||||||
{
|
|
||||||
setTopic(buf,sizeof(buf),T_DEV);
|
|
||||||
pfxlen = strlen(buf);
|
|
||||||
intopic = strncmp(topic, buf, pfxlen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
if (!pfxlen) {
|
||||||
// in Retaining status - trying to restore previous state from retained output topic. Retained input topics are not relevant.
|
debugSerial<<F("Skipping..")<<endl;
|
||||||
if (intopic) {
|
return;// -3;
|
||||||
debugSerial<<F("Skipping..");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
itemName=topic+pfxlen;
|
itemName=topic+pfxlen;
|
||||||
|
|
||||||
|
debugSerial<<itemName<<endl;
|
||||||
|
|
||||||
if(!strcmp(itemName,CMDTOPIC) && payload && (strlen((char*) payload)>1)) {
|
if(!strcmp(itemName,CMDTOPIC) && payload && (strlen((char*) payload)>1)) {
|
||||||
// mqttClient.publish(topic, "");
|
// mqttClient.publish(topic, "");
|
||||||
cmd_parse((char *)payload);
|
cmd_parse((char *)payload);
|
||||||
return;
|
return;// -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subItem = strchr(itemName, '/'))
|
if (subItem = strchr(itemName, '/'))
|
||||||
{
|
{
|
||||||
*subItem = 0;
|
*subItem = 0;
|
||||||
subItem++;
|
subItem++;
|
||||||
if (*subItem=='$') return; //Skipping homie stuff
|
if (*subItem=='$') return;// -5; //Skipping homie stuff
|
||||||
|
|
||||||
// debugSerial<<F("Subitem:")<<subItem<<endl;
|
|
||||||
}
|
}
|
||||||
// debugSerial<<F("Item:")<<itemName<<endl;
|
|
||||||
|
|
||||||
if (itemName[0]=='$') return; //Skipping homie stuff
|
if (itemName[0]=='$') return;// -6; //Skipping homie stuff
|
||||||
|
|
||||||
Item item(itemName);
|
Item item(itemName);
|
||||||
if (item.isValid()) {
|
if (item.isValid()) {
|
||||||
/*
|
//return
|
||||||
if (item.itemType == CH_GROUP && (lanStatus == RETAINING_COLLECTING))
|
|
||||||
return; //Do not restore group channels - they consist not relevant data */
|
|
||||||
item.Ctrl((char *)payload,subItem);
|
item.Ctrl((char *)payload,subItem);
|
||||||
} //valid item
|
} //valid item
|
||||||
|
return;// -7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -414,40 +427,13 @@ if (element && element->type == aJson_String) return element->valuestring;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OTA
|
#ifdef OTA
|
||||||
// #if (defined(ARDUINO_ARCH_ESP32) || defined(ESP8266))
|
|
||||||
void setupOTA(void)
|
void setupOTA(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage, sysConfStream, JSONStream);
|
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage, sysConfStream, JSONStream);
|
||||||
ArduinoOTA.setCustomHandler(httpHandler);
|
ArduinoOTA.setCustomHandler(httpHandler);
|
||||||
infoSerial<<F("OTA initialized\n");
|
infoSerial<<F("OTA initialized\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
#elif defined (ARDUINO_ARCH_AVR)
|
|
||||||
InternalStorageAVRClass flashStorage(EEPROM_offsetJSON);
|
|
||||||
void setupOTA(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", flashStorage);
|
|
||||||
ArduinoOTA.setCustomHandler(httpHandler);
|
|
||||||
infoSerial<<F("OTA initialized\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
//InternalStorageClass flashStorage(EEPROM_offsetJSON);
|
|
||||||
void setupOTA(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage);
|
|
||||||
ArduinoOTA.setCustomHandler(httpHandler);
|
|
||||||
infoSerial<<F("OTA initialized\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
void setupOTA(void) {};
|
void setupOTA(void) {};
|
||||||
#endif
|
#endif
|
||||||
@@ -1256,14 +1242,8 @@ int loadConfigFromEEPROM()
|
|||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
infoSerial<<F("Loading Config from EEPROM")<<endl;
|
infoSerial<<F("Loading Config from EEPROM")<<endl;
|
||||||
|
|
||||||
//ch = EEPROM.read(EEPROM_offsetJSON);
|
|
||||||
//Serial.print(ch);
|
|
||||||
//if (ch == '{') {
|
|
||||||
JSONStream.seek();
|
JSONStream.seek();
|
||||||
if (JSONStream.peek() == '{') {
|
if (JSONStream.peek() == '{') {
|
||||||
//aJsonEEPROMStream as = aJsonEEPROMStream(EEPROM_offsetJSON);
|
|
||||||
//flashStream fs = flashStream(EEPROM_offsetJSON);
|
|
||||||
aJsonStream as = aJsonStream(&JSONStream);
|
aJsonStream as = aJsonStream(&JSONStream);
|
||||||
cleanConf();
|
cleanConf();
|
||||||
root = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
@@ -1276,49 +1256,13 @@ int loadConfigFromEEPROM()
|
|||||||
ethClient.stop(); //Refresh MQTT connect to get retained info
|
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
JSONStream.write(255); //truncate garbage
|
||||||
infoSerial<<F("No stored config")<<endl;
|
infoSerial<<F("No stored config")<<endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void cmdFunctionReq(int arg_cnt, char **args) {
|
|
||||||
mqttConfigRequest(arg_cnt, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mqttConfigRequest(int arg_cnt, char **args)
|
|
||||||
{
|
|
||||||
char buf[25] = "/";
|
|
||||||
infoSerial<<F("\nrequest MQTT Config");
|
|
||||||
SetBytes((uint8_t *) mac, 6, buf + 1);
|
|
||||||
buf[13] = 0;
|
|
||||||
strncat(buf, "/resp/#", 25);
|
|
||||||
debugSerial<<buf;
|
|
||||||
mqttClient.subscribe(buf);
|
|
||||||
buf[13] = 0;
|
|
||||||
strncat(buf, "/req/conf", 25);
|
|
||||||
debugSerial<<buf;
|
|
||||||
mqttClient.publish(buf, "1");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mqttConfigResp(char *as) {
|
|
||||||
infoSerial<<F("got MQTT Config");
|
|
||||||
root = aJson.parse(as);
|
|
||||||
|
|
||||||
if (!root) {
|
|
||||||
errorSerial<<F("\nload failed\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
infoSerial<<F("\nLoaded");
|
|
||||||
applyConfig();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
|
|
||||||
@@ -1415,16 +1359,8 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
||||||
/*
|
|
||||||
for (int i = OFFSET_MAC; i < OFFSET_MAC+EEPROM_FIX_PART_LEN+1; i++) //Fi[ part +{]
|
|
||||||
EEPROM.write(i, 0);
|
|
||||||
|
|
||||||
for (int i = 0; i < EEPROM_SIGNATURE_LENGTH; i++)
|
|
||||||
EEPROM.write(i+OFFSET_SIGNATURE,EEPROM_signature[i]);
|
|
||||||
*/
|
|
||||||
sysConf.clear();
|
sysConf.clear();
|
||||||
infoSerial<<F("EEPROM cleared\n");
|
infoSerial<<F("EEPROM cleared\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionPwd(int arg_cnt, char **args)
|
void cmdFunctionPwd(int arg_cnt, char **args)
|
||||||
@@ -1435,6 +1371,14 @@ void cmdFunctionPwd(int arg_cnt, char **args)
|
|||||||
infoSerial<<F("Password updated\n");
|
infoSerial<<F("Password updated\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmdFunctionOTAPwd(int arg_cnt, char **args)
|
||||||
|
{ //char empty[]="";
|
||||||
|
if (arg_cnt)
|
||||||
|
sysConf.setOTApwd(args[1]);
|
||||||
|
else sysConf.setOTApwd();
|
||||||
|
infoSerial<<F("Password updated\n");
|
||||||
|
}
|
||||||
|
|
||||||
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||||
char dummy;
|
char dummy;
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
@@ -1452,7 +1396,6 @@ void cmdFunctionSetMac(int arg_cnt, char **args) {
|
|||||||
void cmdFunctionGet(int arg_cnt, char **args) {
|
void cmdFunctionGet(int arg_cnt, char **args) {
|
||||||
lanStatus= loadConfigFromHttp(arg_cnt, args);
|
lanStatus= loadConfigFromHttp(arg_cnt, args);
|
||||||
ethClient.stop(); //Refresh MQTT connect to get retained info
|
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||||
//restoreState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printBool(bool arg) { (arg) ? infoSerial<<F("+") : infoSerial<<F("-"); }
|
void printBool(bool arg) { (arg) ? infoSerial<<F("+") : infoSerial<<F("-"); }
|
||||||
@@ -1688,7 +1631,7 @@ void setup_main() {
|
|||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(FS_PREPARE)
|
||||||
|
|
||||||
//Initialize File System
|
//Initialize File System
|
||||||
if(SPIFFS.begin(true))
|
if(SPIFFS.begin(true))
|
||||||
@@ -1699,16 +1642,6 @@ void setup_main() {
|
|||||||
{
|
{
|
||||||
debugSerial<<("SPIFFS Initialization...failed")<<endl;
|
debugSerial<<("SPIFFS Initialization...failed")<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Format File System
|
|
||||||
if(SPIFFS.format())
|
|
||||||
{
|
|
||||||
debugSerial<<("File System Formated")<<endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
debugSerial<<("File System Formatting Error")<<endl;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
@@ -1950,15 +1883,6 @@ void publishStat(){
|
|||||||
|
|
||||||
void setupMacAddress() {
|
void setupMacAddress() {
|
||||||
//Check MAC, stored in NVRAM
|
//Check MAC, stored in NVRAM
|
||||||
//macAddress * mac = sysConf.getMAC();
|
|
||||||
//bool isMacValid = sysConf.getMAC(&mac);
|
|
||||||
|
|
||||||
/*
|
|
||||||
for (short i = 0; i < 6; i++) {
|
|
||||||
mac[i] = EEPROM.read(i);
|
|
||||||
if (mac[i] != 0 && mac[i] != 0xff) isMacValid = true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (!sysConf.getMAC()) {
|
if (!sysConf.getMAC()) {
|
||||||
infoSerial<<F("No MAC configured: set firmware's MAC\n");
|
infoSerial<<F("No MAC configured: set firmware's MAC\n");
|
||||||
|
|
||||||
@@ -1986,8 +1910,6 @@ if (!sysConf.getMAC()) {
|
|||||||
memcpy(sysConf.mac,defaultMac,6);
|
memcpy(sysConf.mac,defaultMac,6);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printMACAddress();
|
printMACAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2005,6 +1927,7 @@ void setupCmdArduino() {
|
|||||||
//cmdAdd("req", cmdFunctionReq);
|
//cmdAdd("req", cmdFunctionReq);
|
||||||
cmdAdd("ip", cmdFunctionIp);
|
cmdAdd("ip", cmdFunctionIp);
|
||||||
cmdAdd("pwd", cmdFunctionPwd);
|
cmdAdd("pwd", cmdFunctionPwd);
|
||||||
|
cmdAdd("otapwd", cmdFunctionOTAPwd);
|
||||||
cmdAdd("clear",cmdFunctionClearEEPROM);
|
cmdAdd("clear",cmdFunctionClearEEPROM);
|
||||||
cmdAdd("reboot",cmdFunctionReboot);
|
cmdAdd("reboot",cmdFunctionReboot);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ typedef union {
|
|||||||
bool isNotRetainingStatus();
|
bool isNotRetainingStatus();
|
||||||
//void watchdogSetup(void);
|
//void watchdogSetup(void);
|
||||||
|
|
||||||
|
//int itemCommand(char *topic, char *payload);
|
||||||
void mqttCallback(char *topic, byte *payload, unsigned int length);
|
void mqttCallback(char *topic, byte *payload, unsigned int length);
|
||||||
|
|
||||||
void printMACAddress();
|
void printMACAddress();
|
||||||
|
|||||||
Reference in New Issue
Block a user