mirror of
https://github.com/anklimov/lighthub
synced 2025-12-12 06:39:51 +03:00
pre-release, save2flash, mdns bugs, dmx, .....
This commit is contained in:
@@ -10,10 +10,10 @@ uint8_t getBright255(uint8_t percent255)
|
||||
/*
|
||||
int val = stepvar[index];
|
||||
if (val>255) val=255;
|
||||
Serial.print(F("Bright:"));
|
||||
Serial.print(percent);
|
||||
Serial.print(F("->"));
|
||||
Serial.println(val);
|
||||
debugSerialPort.print(F("Bright:"));
|
||||
debugSerialPort.print(percent);
|
||||
debugSerialPort.print(F("->"));
|
||||
debugSerialPort.println(val);
|
||||
return val;*/
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,49 +1,5 @@
|
||||
#include "config.h"
|
||||
|
||||
//#if defined(ARDUINO_ARCH_AVR)
|
||||
//#include <EEPROM.h>
|
||||
//#endif
|
||||
|
||||
/*
|
||||
void saveFlash(short n, char *str) {
|
||||
short len=strlen(str);
|
||||
if (len>MAXFLASHSTR-1) len=MAXFLASHSTR-1;
|
||||
for(int i=0;i<len;i++) EEPROM.write(n+i,str[i]);
|
||||
EEPROM.write(n+len,0);
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
// write the data to EEPROM
|
||||
short res = EEPROM.commitReset();
|
||||
Serial.println((res) ? "EEPROM Commit OK" : "Commit failed");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void saveFlash(short n, IPAddress& ip) {
|
||||
for(int i=0;i<4;i++) EEPROM.write(n++,ip[i]);
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
// write the data to EEPROM
|
||||
short res = EEPROM.commitReset();
|
||||
Serial.println((res) ? "EEPROM Commit OK" : "Commit failed");
|
||||
#endif
|
||||
}
|
||||
|
||||
int ipLoadFromFlash(short n, IPAddress &ip) {
|
||||
for (int i = 0; i < 4; i++)
|
||||
ip[i] = EEPROM.read(n++);
|
||||
return (ip[0] && ((ip[0] != 0xff) || (ip[1] != 0xff) || (ip[2] != 0xff) || (ip[3] != 0xff)));
|
||||
}
|
||||
*/
|
||||
|
||||
bool systemConfig::isValidSysConf()
|
||||
{
|
||||
@@ -75,7 +31,7 @@ bool systemConfig::isValidSysConf()
|
||||
{
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,mac));
|
||||
///stream->write ((const uint8_t *)&_mac,sizeof(_mac));
|
||||
stream->write ((const uint8_t *)&_mac,sizeof(_mac));
|
||||
memcpy(mac, _mac, sizeof(mac));
|
||||
|
||||
return true;
|
||||
@@ -85,16 +41,21 @@ bool systemConfig::isValidSysConf()
|
||||
{
|
||||
if (!stream || !isValidSysConf()) return NULL;
|
||||
stream->seek(offsetof(systemConfigData,MQTTpwd));
|
||||
if (stream->readBytesUntil(0,buffer,bufLen)) return buffer;
|
||||
short bytes=stream->readBytesUntil(0,buffer,bufLen-1);
|
||||
if (bytes)
|
||||
{
|
||||
buffer[bytes]=0;
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool systemConfig::setMQTTpwd(char * pwd)
|
||||
{
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
if (!stream || !isValidSysConf() || (strlen(pwd)>=sizeof(systemConfigData::MQTTpwd))) return false;
|
||||
stream->seek(offsetof(systemConfigData,MQTTpwd));
|
||||
stream->print(pwd);
|
||||
return stream->write(0);
|
||||
return stream->write((uint8_t)'\0');
|
||||
}
|
||||
|
||||
|
||||
@@ -102,87 +63,112 @@ bool systemConfig::isValidSysConf()
|
||||
{
|
||||
if (!stream || !isValidSysConf()) return NULL;
|
||||
stream->seek(offsetof(systemConfigData,OTApwd));
|
||||
if (stream->readBytesUntil(0,buffer,bufLen)) return buffer;
|
||||
short bytes=stream->readBytesUntil(0,buffer,bufLen-1);
|
||||
if (bytes)
|
||||
{
|
||||
buffer[bytes]=0;
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool systemConfig::setOTApwd(char * pwd)
|
||||
{
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
if (!stream || !isValidSysConf() || (strlen(pwd)>=sizeof(systemConfigData::OTApwd))) return false;
|
||||
stream->seek(offsetof(systemConfigData,OTApwd));
|
||||
stream->print(pwd);
|
||||
return stream->write(0);
|
||||
return stream->write((uint8_t)'\0');
|
||||
}
|
||||
|
||||
|
||||
char * systemConfig::getServer(char * buffer, uint16_t bufLen)
|
||||
char * systemConfig::getServer(char * buffer, uint16_t bufLen)
|
||||
{
|
||||
if (!stream || !isValidSysConf()) return NULL;
|
||||
stream->seek(offsetof(systemConfigData,configURL));
|
||||
if (stream->readBytesUntil(0,buffer,bufLen)) return buffer;
|
||||
short bytes=stream->readBytesUntil(0,buffer,bufLen-1);
|
||||
if (bytes)
|
||||
{
|
||||
buffer[bytes]=0;
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool systemConfig::setServer(char* url)
|
||||
{
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,OTApwd));
|
||||
if (!stream || !isValidSysConf() || (strlen(url)>=sizeof(systemConfigData::configURL))) return false;
|
||||
stream->seek(offsetof(systemConfigData,configURL));
|
||||
stream->print(url);
|
||||
return stream->write(0);
|
||||
|
||||
return stream->write((uint8_t)'\0');
|
||||
}
|
||||
|
||||
|
||||
bool systemConfig::getIP(IPAddress& ip)
|
||||
{
|
||||
uint32_t addr;
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,ip));
|
||||
stream->readBytes((char *)&ip,sizeof(ip));
|
||||
return ip;
|
||||
|
||||
stream->readBytes((uint8_t *) &addr,4);
|
||||
ip=addr;
|
||||
return (ip[0] && ((ip[0] != 0xff) || (ip[1] != 0xff) || (ip[2] != 0xff) || (ip[3] != 0xff)));
|
||||
}
|
||||
|
||||
bool systemConfig::getMask(IPAddress& mask)
|
||||
{
|
||||
return 0;
|
||||
|
||||
uint32_t addr;
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,mask));
|
||||
stream->readBytes((uint8_t *) &addr,4);
|
||||
mask=addr;
|
||||
return (mask[0] && ((mask[0] != 0xff) || (mask[1] != 0xff) || (mask[2] != 0xff) || (mask[3] != 0xff)));
|
||||
}
|
||||
|
||||
bool systemConfig::getDNS(IPAddress& dns)
|
||||
{
|
||||
return 0;
|
||||
|
||||
{ uint32_t addr;
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,dns));
|
||||
stream->readBytes((uint8_t *) &addr,4);
|
||||
dns = addr;
|
||||
return (dns[0] && ((dns[0] != 0xff) || (dns[1] != 0xff) || (dns[2] != 0xff) || (dns[3] != 0xff)));
|
||||
}
|
||||
|
||||
bool systemConfig::getGW(IPAddress& gw)
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
{ uint32_t addr;
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,gw));
|
||||
stream->readBytes((uint8_t *) &addr,4);
|
||||
gw=addr;
|
||||
return (gw[0] && ((gw[0] != 0xff) || (gw[1] != 0xff) || (gw[2] != 0xff) || (gw[3] != 0xff)));
|
||||
}
|
||||
|
||||
|
||||
bool systemConfig::setIP(IPAddress& ip)
|
||||
{
|
||||
return 0;
|
||||
|
||||
{ uint32_t addr=ip;
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,ip));
|
||||
return stream->write((uint8_t *) &addr, 4);
|
||||
}
|
||||
|
||||
bool systemConfig::setMask(IPAddress& mask)
|
||||
{
|
||||
return 0;
|
||||
|
||||
{ uint32_t addr = mask;
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,mask));
|
||||
return stream->write((uint8_t *) &addr, 4);
|
||||
}
|
||||
|
||||
bool systemConfig::setDNS(IPAddress& dns)
|
||||
{
|
||||
return 0;
|
||||
{ uint32_t addr = dns;
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,dns));
|
||||
return stream->write((uint8_t *) &addr, 4);
|
||||
|
||||
}
|
||||
|
||||
bool systemConfig::setGW(IPAddress& gw)
|
||||
{
|
||||
return 0;
|
||||
|
||||
{ uint32_t addr = gw;
|
||||
if (!stream || !isValidSysConf()) return false;
|
||||
stream->seek(offsetof(systemConfigData,gw));
|
||||
return stream->write((uint8_t *) &addr, 4);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +177,7 @@ bool systemConfig::isValidSysConf()
|
||||
if (!stream) return ;
|
||||
stream->seek(0);
|
||||
for (unsigned int i = 0; i < stream->getSize(); i++) {
|
||||
stream->write(0);
|
||||
stream->write((uint8_t)'\0');
|
||||
}
|
||||
stream->seek(offsetof(systemConfigData,signature));
|
||||
for (unsigned int i=0;i<sizeof(systemConfigData::signature);i++)
|
||||
@@ -199,9 +185,49 @@ bool systemConfig::isValidSysConf()
|
||||
stream->flush();
|
||||
}
|
||||
|
||||
///
|
||||
bool systemConfig::getSaveSuccedConfig()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool systemConfig::setSaveSuccedConfig(bool)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
|
||||
bool systemConfig::setSerialDebuglevel(short level)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool systemConfig::setUdpDebuglevel(short level)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint8_t systemConfig::getSerialDebuglevel()
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
uint8_t systemConfig::getUdpDebuglevel()
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
//
|
||||
bool systemConfig::setLoadHTTPConfig(bool load)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool systemConfig::getLoadHTTPConfig()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,22 +28,26 @@ const char EEPROM_signature[] = EEPROM_SIGNATURE;
|
||||
typedef struct
|
||||
{
|
||||
char signature[4];
|
||||
macAddress mac;
|
||||
macAddress mac; //6 bytes
|
||||
union {
|
||||
uint16_t configFlags;
|
||||
struct
|
||||
{
|
||||
uint8_t serialDebugLevel:4;
|
||||
uint8_t syslogDebugLevel:4;
|
||||
uint8_t notGetConfigFromHTTP:1;
|
||||
uint8_t saveToFlash:1;
|
||||
};
|
||||
};
|
||||
uint32_t ip;
|
||||
uint32_t dns;
|
||||
uint32_t gw;
|
||||
uint32_t mask;
|
||||
union {
|
||||
uint8_t configFlags;
|
||||
struct
|
||||
{ uint8_t notGetConfigFromHTTP:1;
|
||||
uint8_t saveToFlash:1;
|
||||
};
|
||||
};
|
||||
|
||||
flashstr configURL;
|
||||
flashpwd MQTTpwd;
|
||||
flashpwd OTApwd;
|
||||
uint8_t serialDebugLevel;
|
||||
|
||||
uint16_t sysConfigHash;
|
||||
uint16_t JSONHash;
|
||||
|
||||
@@ -82,8 +86,15 @@ class systemConfig {
|
||||
bool setDNS(IPAddress& dns);
|
||||
bool setGW(IPAddress& gw);
|
||||
|
||||
bool setSerialDebuglevel(short);
|
||||
bool setUdpDebuglevel(short);
|
||||
uint8_t getSerialDebuglevel();
|
||||
uint8_t getUdpDebuglevel();
|
||||
|
||||
void clear();
|
||||
bool getSaveSuccedConfig();
|
||||
bool setSaveSuccedConfig(bool);
|
||||
bool getLoadHTTPConfig();
|
||||
bool setLoadHTTPConfig(bool);
|
||||
//bool Save();
|
||||
};
|
||||
@@ -39,14 +39,14 @@ DMXESPSerial dmxout;
|
||||
uint8_t * DMXin = NULL;
|
||||
|
||||
#ifdef DMX_SMOOTH
|
||||
uint8_t * DMXinterimBuf = NULL;
|
||||
uint16_t DMXOUT_Channels=0;
|
||||
uint32_t checkTimestamp=0L;
|
||||
volatile uint8_t * DMXinterimBuf = NULL;
|
||||
volatile uint16_t DMXOUT_Channels=0;
|
||||
volatile uint32_t checkTimestamp=0L;
|
||||
#endif
|
||||
|
||||
int D_State=0;
|
||||
volatile uint32_t D_State=0;
|
||||
|
||||
unsigned long D_checkT=0;
|
||||
volatile unsigned long D_checkT=0;
|
||||
|
||||
#ifdef _artnet
|
||||
#include <Artnet.h>
|
||||
@@ -123,6 +123,7 @@ void DMXSemiImmediateUpdate(short tch,short trh, int val)
|
||||
|
||||
void DMXput(void)
|
||||
{
|
||||
if (!DMXin) return;
|
||||
for (short tch=0; tch<=3 ; tch++)
|
||||
{
|
||||
short base = tch*4;
|
||||
@@ -130,34 +131,44 @@ for (short tch=0; tch<=3 ; tch++)
|
||||
}
|
||||
};
|
||||
|
||||
extern volatile uint8_t timerHandlerBusy;
|
||||
volatile int DMXinDoublecheck=0;
|
||||
|
||||
void DMXUpdate(void)
|
||||
{
|
||||
#if defined(_dmxin)
|
||||
int t;
|
||||
if(!DMXin) return;
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
if (dmxin.getRxLength()<16) return;
|
||||
#endif
|
||||
for (short tch=0; tch<=3 ; tch++)
|
||||
{
|
||||
short base = tch*4;
|
||||
bool updated = 0;
|
||||
bool updated = 0;
|
||||
bool confirmed = 0;
|
||||
|
||||
for (short trh=0; trh<4 ; trh++)
|
||||
if ((t=dmxin.read(base+trh+1)) != DMXin[base+trh])
|
||||
if (((t=dmxin.read(base+trh+1)) != DMXin[base+trh]))
|
||||
{
|
||||
D_State |= (1<<tch);
|
||||
updated=1;
|
||||
//Serial.print("onContactChanged :"); Serial.print(DMXin[tch*4+trh]); Serial.print(" => "); Serial.print(t);Serial.println();
|
||||
DMXin[base+trh]=t;
|
||||
//DMXImmediateUpdate(tch,trh,t);
|
||||
//break;
|
||||
}
|
||||
if (DMXinDoublecheck>2)
|
||||
{
|
||||
D_State |= (1<<tch);
|
||||
DMXin[base+trh]=t;
|
||||
confirmed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (updated)
|
||||
if (updated) DMXinDoublecheck++; else DMXinDoublecheck=0;
|
||||
|
||||
|
||||
if (confirmed)
|
||||
{
|
||||
|
||||
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
||||
//for (int i=1; i<17; i++) {debugSerial.print(dmxin.read(i));debugSerial.print("-");};debugSerial.print("|");
|
||||
D_checkT=millisNZ();
|
||||
}
|
||||
}
|
||||
@@ -191,11 +202,14 @@ D_checkT=0;
|
||||
|
||||
// Here code for network update
|
||||
//int ch = 0;
|
||||
|
||||
DMXput();
|
||||
|
||||
#ifdef _dmxout
|
||||
for (int i=1; i<17; i++) {Serial.print(dmxin.read(i));Serial.print(";");}
|
||||
for (int i=1; i<17; i++) {debugSerial.print(dmxin.read(i));debugSerial.print(";");}
|
||||
debugSerial.println();
|
||||
#endif
|
||||
Serial.println();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -221,7 +235,7 @@ void DMXinSetup(int channels)
|
||||
DMXin = new uint8_t [channels];
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
DMXSerial.init(DMXReceiver,0,channels);
|
||||
if (DMXSerial.getBuffer()) {Serial.print(F("Init in ch:"));Serial.println(channels);} else Serial.println(F("DMXin Buffer alloc err"));
|
||||
if (DMXSerial.getBuffer()) {debugSerial.print(F("Init in ch:"));debugSerial.println(channels);} else debugSerial.println(F("DMXin Buffer alloc err"));
|
||||
//DMXSerial.maxChannel(channels);
|
||||
DMXSerial.attachOnUpdate(&DMXUpdate);
|
||||
#endif
|
||||
@@ -271,36 +285,41 @@ debugSerial<<F("DMXInterim. Free:")<<freeRam()<<endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
volatile int8_t propagateBusy = 0;
|
||||
void DMXOUT_propagate()
|
||||
{
|
||||
#ifdef DMX_SMOOTH
|
||||
if (propagateBusy) return;
|
||||
propagateBusy++;
|
||||
uint32_t now = millis();
|
||||
//if (now<checkTimestamp) return;
|
||||
if (!isTimeOver(checkTimestamp,now,DMX_SMOOTH_DELAY)) return;
|
||||
|
||||
for(int i=1;i<=DMXOUT_Channels;i++)
|
||||
if (isTimeOver(checkTimestamp,now,DMX_SMOOTH_DELAY))
|
||||
{
|
||||
uint8_t currLevel=dmxout.getTx(i);
|
||||
int32_t delta = currLevel-DMXinterimBuf[i-1];
|
||||
if (delta)
|
||||
{
|
||||
uint16_t step = abs(delta) >> 4;
|
||||
if (!step) step=1;
|
||||
for(int i=1;i<=DMXOUT_Channels;i++)
|
||||
{
|
||||
uint8_t currLevel=dmxout.getTx(i);
|
||||
int32_t delta = currLevel-DMXinterimBuf[i-1];
|
||||
if (delta)
|
||||
{
|
||||
uint16_t step = abs(delta) >> 4;
|
||||
if (!step) step=1;
|
||||
|
||||
if (delta<0)
|
||||
{
|
||||
DmxWrite2(i,currLevel+step);
|
||||
//debugSerial<<"<";
|
||||
}
|
||||
if (delta<0)
|
||||
{
|
||||
DmxWrite2(i,currLevel+step);
|
||||
//debugSerial<<"<";
|
||||
}
|
||||
|
||||
if (delta>0)
|
||||
{
|
||||
DmxWrite2(i,currLevel-step);
|
||||
//debugSerial<<">";
|
||||
}
|
||||
}
|
||||
if (delta>0)
|
||||
{
|
||||
DmxWrite2(i,currLevel-step);
|
||||
//debugSerial<<">";
|
||||
}
|
||||
}
|
||||
}
|
||||
checkTimestamp=now;
|
||||
}
|
||||
checkTimestamp=now;
|
||||
propagateBusy--;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,369 +0,0 @@
|
||||
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
|
||||
@@ -1,54 +0,0 @@
|
||||
#include "options.h"
|
||||
#ifdef __ESP__
|
||||
#include "esp.h"
|
||||
|
||||
ESP8266WiFiMulti wifiMulti;
|
||||
WiFiClient ethClient;
|
||||
|
||||
char mqtt_password[16];
|
||||
|
||||
//default custom static IP
|
||||
//char static_ip[16] = "10.0.1.56";
|
||||
//char static_gw[16] = "10.0.1.1";
|
||||
//char static_sn[16] = "255.255.255.0";
|
||||
|
||||
//flag for saving data
|
||||
bool shouldSaveConfig = false;
|
||||
|
||||
//callback notifying us of the need to save config
|
||||
void saveConfigCallback () {
|
||||
Serial.println(F("Should save config"));
|
||||
shouldSaveConfig = true;
|
||||
}
|
||||
|
||||
|
||||
void espSetup () {
|
||||
Serial.println(F("Setting up Wifi"));
|
||||
shouldSaveConfig = true;
|
||||
//WiFiManager
|
||||
|
||||
WiFiManagerParameter custom_mqtt_password("", "mqtt password", mqtt_password, 16);
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
WiFiManager wifiManager;
|
||||
|
||||
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
||||
|
||||
wifiManager.addParameter(&custom_mqtt_password);
|
||||
wifiManager.setMinimumSignalQuality();
|
||||
|
||||
if (!wifiManager.autoConnect()) {
|
||||
Serial.println(F("failed to connect and hit timeout"));
|
||||
delay(3000);
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.reset();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
//if you get here you have connected to the WiFi
|
||||
Serial.println(F("connected...yeey :)"));
|
||||
|
||||
//read updated parameters
|
||||
strcpy(mqtt_password, custom_mqtt_password.getValue());
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,24 +0,0 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
|
||||
extern ESP8266WiFiMulti wifiMulti;
|
||||
extern WiFiClient ethClient;
|
||||
//WiFiManager wifiManager;
|
||||
|
||||
//define your default values here, if there are different values in config.json, they are overwritten.
|
||||
//length should be max size + 1
|
||||
extern char mqtt_password[16];
|
||||
|
||||
//default custom static IP
|
||||
//char static_ip[16] = "10.0.1.56";
|
||||
//char static_gw[16] = "10.0.1.1";
|
||||
//char static_sn[16] = "255.255.255.0";
|
||||
|
||||
//flag for saving data
|
||||
extern bool shouldSaveConfig;
|
||||
|
||||
void espSetup ();
|
||||
@@ -68,6 +68,7 @@ flashStream(String _filename):seekableStream(65535)
|
||||
virtual unsigned int seek(unsigned int _pos = 0){return fs.seek(_pos,SeekSet);};
|
||||
virtual void flush() {return fs.flush();};
|
||||
virtual size_t write(uint8_t ch) {return fs.write(ch);};
|
||||
using Print::write;
|
||||
void putEOF(){write (255);};
|
||||
virtual ~flashStream () {if (fs) fs.close();} ;
|
||||
};
|
||||
@@ -95,7 +96,7 @@ flashStream(unsigned int _startPos=0, unsigned int _size=4096 ):seekableStream(_
|
||||
|
||||
virtual unsigned int seek(unsigned int _pos = 0)
|
||||
{ pos=min(startPos+_pos, startPos+streamSize);
|
||||
debugSerial<<F("Seek:")<<pos<<endl;
|
||||
//debugSerial<<F("Seek:")<<pos<<endl;
|
||||
return pos;
|
||||
};
|
||||
virtual int available() { return (pos<streamSize);};
|
||||
@@ -116,20 +117,10 @@ flashStream(unsigned int _startPos=0, unsigned int _size=4096 ):seekableStream(_
|
||||
EEPROM.commit();
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) override
|
||||
{
|
||||
debugSerial<<("Write from:")<<pos<<" "<<size<<" bytes"<<endl;
|
||||
EEPROM.write(pos,(byte*)buffer,size);
|
||||
pos+=size;
|
||||
return size;
|
||||
};
|
||||
#endif
|
||||
|
||||
virtual size_t write(uint8_t ch)
|
||||
{
|
||||
#if defined(__AVR__)
|
||||
//Serial.print (ch);
|
||||
EEPROM.update(pos++,(char)ch);
|
||||
return 1;
|
||||
#endif
|
||||
@@ -139,6 +130,18 @@ flashStream(unsigned int _startPos=0, unsigned int _size=4096 ):seekableStream(_
|
||||
#endif
|
||||
return 0;
|
||||
};
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) override
|
||||
{
|
||||
//debugSerial<<("Write from:")<<pos<<" "<<size<<" bytes"<<endl;
|
||||
EEPROM.write(pos,(byte*)buffer,size);
|
||||
pos+=size;
|
||||
return size;
|
||||
};
|
||||
#else
|
||||
using Print::write;//(const uint8_t *buffer, size_t size);
|
||||
#endif
|
||||
void putEOF(){write (255);
|
||||
#if defined(ESP8266)
|
||||
EEPROM.commit();
|
||||
|
||||
@@ -300,9 +300,9 @@ void Input::counterPoll() {
|
||||
short real_pin = mega_interrupt_array[interrupt_number];
|
||||
attachInterruptPinIrq(real_pin,interrupt_number);
|
||||
} else {
|
||||
Serial.print(F("IRQ:"));
|
||||
Serial.print(pin);
|
||||
Serial.print(F(" Counter type. INCORRECT Interrupt number!!!"));
|
||||
debugSerial.print(F("IRQ:"));
|
||||
debugSerial.print(pin);
|
||||
debugSerial.print(F(" Counter type. INCORRECT Interrupt number!!!"));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -365,7 +365,7 @@ void Input::attachInterruptPinIrq(int realPin, int irq) {
|
||||
attachInterrupt(real_irq, onCounterChanged5, RISING);
|
||||
break;
|
||||
default:
|
||||
Serial.print(F("Incorrect irq:"));Serial.println(irq);
|
||||
debugSerial.print(F("Incorrect irq:"));debugSerial.println(irq);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,6 +653,7 @@ return false;
|
||||
//Main routine to control Item
|
||||
int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
|
||||
{
|
||||
uint32_t time=millis();
|
||||
int suffixCode = cmd.getSuffix();
|
||||
bool operation = isNotRetainingStatus();
|
||||
|
||||
@@ -730,7 +731,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
|
||||
toExecute=true;
|
||||
scale100=true; //openHab topic format
|
||||
chActive=(isActive()>0);
|
||||
|
||||
debugSerial<<chActive<<" "<<cmd.getInt()<<endl;
|
||||
if (chActive>0 && !cmd.getInt()) {cmd.Cmd(CMD_OFF);status2Send |= SEND_COMMAND | SEND_IMMEDIATE;}
|
||||
if (chActive==0 && cmd.getInt()) {cmd.Cmd(CMD_ON);status2Send |= SEND_COMMAND | SEND_IMMEDIATE;}
|
||||
|
||||
@@ -1132,7 +1133,7 @@ switch (itemType) {
|
||||
if (command2Set) setCmd(command2Set | SEND_COMMAND);
|
||||
if (operation) SendStatus(status2Send);
|
||||
|
||||
debugSerial<<F("Ctrl Res:")<<res<<endl;
|
||||
debugSerial<<F("Ctrl Res:")<<res<<F(" time:")<<millis()-time<<endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -321,7 +321,9 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType)
|
||||
setColorTemp(t);
|
||||
}
|
||||
cmd.suffixCode=from.cmd.suffixCode;
|
||||
|
||||
cmd.cmdCode=from.cmd.cmdCode;
|
||||
//cmd.cmdFlag
|
||||
//cmd.cmdParam
|
||||
|
||||
switch (cmd.itemArgType){ //Destination
|
||||
case ST_HSV255:
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "main.h"
|
||||
void setup(){
|
||||
//if (millis()>1000)
|
||||
setup_main();
|
||||
//else Serial.println("Hello");
|
||||
//delay(1000);
|
||||
void setup()
|
||||
{
|
||||
setup_main();
|
||||
}
|
||||
void loop(){
|
||||
//if (millis()>10000)
|
||||
void loop()
|
||||
{
|
||||
loop_main();
|
||||
}
|
||||
|
||||
@@ -64,25 +64,6 @@ EthernetClient ethClient;
|
||||
MDNS mdns(mdnsUDP);
|
||||
#endif
|
||||
|
||||
/*
|
||||
#if defined(__SAM3X8E__)
|
||||
DueFlashStorage EEPROM;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
NRFFlashStorage EEPROM;
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_STM32
|
||||
NRFFlashStorage EEPROM;
|
||||
#endif
|
||||
|
||||
#ifdef NRF5
|
||||
NRFFlashStorage EEPROM;
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifdef SYSLOG_ENABLE
|
||||
#include <Syslog.h>
|
||||
|
||||
@@ -138,12 +119,12 @@ aJsonObject *dmxArr = NULL;
|
||||
bool syslogInitialized = false;
|
||||
#endif
|
||||
|
||||
uint32_t timerPollingCheck = 0;
|
||||
uint32_t timerInputCheck = 0;
|
||||
uint32_t timerLanCheckTime = 0;
|
||||
uint32_t timerThermostatCheck = 0;
|
||||
uint32_t timerSensorCheck =0;
|
||||
uint32_t WiFiAwaitingTime =0;
|
||||
volatile uint32_t timerPollingCheck = 0;
|
||||
volatile uint32_t timerInputCheck = 0;
|
||||
volatile uint32_t timerLanCheckTime = 0;
|
||||
volatile uint32_t timerThermostatCheck = 0;
|
||||
volatile uint32_t timerSensorCheck =0;
|
||||
volatile uint32_t WiFiAwaitingTime =0;
|
||||
|
||||
aJsonObject *pollingItem = NULL;
|
||||
|
||||
@@ -269,7 +250,7 @@ int httpHandler(Client& client, String request, long contentLength, bool authori
|
||||
if (!item.isValid() || !item.Ctrl((char*) body.c_str())) return 400;
|
||||
|
||||
itemCmd ic;
|
||||
ic.loadItem(&item,true);
|
||||
ic.loadItem(&item,SEND_COMMAND|SEND_PARAMETERS);
|
||||
char buf[32];
|
||||
response=ic.toString(buf, sizeof(buf));
|
||||
}
|
||||
@@ -280,7 +261,7 @@ int httpHandler(Client& client, String request, long contentLength, bool authori
|
||||
if (!item.isValid()) return 400;
|
||||
|
||||
itemCmd ic;
|
||||
ic.loadItem(&item,true);
|
||||
ic.loadItem(&item,SEND_COMMAND|SEND_PARAMETERS);
|
||||
char buf[32];
|
||||
response=ic.toString(buf, sizeof(buf));
|
||||
|
||||
@@ -424,8 +405,15 @@ if (element && element->type == aJson_String) return element->valuestring;
|
||||
|
||||
#ifdef OTA
|
||||
void setupOTA(void)
|
||||
{
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage, sysConfStream, JSONStream);
|
||||
{ char passwordBuf[16];
|
||||
if (!sysConf.getOTApwd(passwordBuf, sizeof(passwordBuf)))
|
||||
{
|
||||
strcpy(passwordBuf,"password");
|
||||
errorSerial<<F("DEFAULT password for OTA API. Use otapwd command to set")<<endl;
|
||||
}
|
||||
|
||||
debugSerial<<passwordBuf<<endl;
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", passwordBuf, InternalStorage, sysConfStream, JSONStream);
|
||||
ArduinoOTA.setCustomHandler(httpHandler);
|
||||
infoSerial<<F("OTA initialized\n");
|
||||
|
||||
@@ -838,12 +826,12 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
//strncpy_P(buf, inprefix, sizeof(buf));
|
||||
setTopic(buf,sizeof(buf),T_BCST);
|
||||
strncat(buf, "#", sizeof(buf));
|
||||
Serial.println(buf);
|
||||
debugSerial.println(buf);
|
||||
mqttClient.subscribe(buf);
|
||||
|
||||
setTopic(buf,sizeof(buf),T_DEV);
|
||||
strncat(buf, "#", sizeof(buf));
|
||||
Serial.println(buf);
|
||||
debugSerialPort.println(buf);
|
||||
mqttClient.subscribe(buf);
|
||||
|
||||
onMQTTConnect();
|
||||
@@ -966,27 +954,24 @@ if (WiFi.status() == WL_CONNECTED) {
|
||||
infoSerial<<F("Got IP address:");
|
||||
printIPAddress(Ethernet.localIP());
|
||||
lanStatus = HAVE_IP_ADDRESS;
|
||||
|
||||
#ifdef MDNS_ENABLE
|
||||
}
|
||||
}//DHCP
|
||||
|
||||
#ifdef MDNS_ENABLE
|
||||
#ifndef OTA_PORT
|
||||
#define OTA_PORT 65280
|
||||
#endif
|
||||
|
||||
mdns.begin(Ethernet.localIP(), "lighthub");
|
||||
mdns.addServiceRecord(("LightHub controller._http"),
|
||||
OTA_PORT,
|
||||
MDNSServiceTCP);
|
||||
|
||||
mdns.addServiceRecord("Lighthub TXT"
|
||||
"._http",
|
||||
OTA_PORT,
|
||||
MDNSServiceTCP,
|
||||
"\x7path=/2");
|
||||
|
||||
|
||||
char txtRecord[32] = "\x7mac=";
|
||||
SetBytes(sysConf.mac,6,txtRecord+5);
|
||||
char mdnsName[32] = "LightHub";
|
||||
SetBytes(sysConf.mac+4,2,mdnsName+8);
|
||||
strncat(mdnsName,"._http",sizeof(mdnsName));
|
||||
mdns.addServiceRecord(mdnsName, OTA_PORT, MDNSServiceTCP, txtRecord);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1070,10 +1055,12 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
||||
infoSerial<<F("\nUse these commands: 'help' - this text\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"
|
||||
"'save' - save config in NVRAM\n"
|
||||
"'get' [config addr]' - get config from pre-configured URL and store addr\n"
|
||||
"'save' - save current config in NVRAM; ON|OFF - enable/disable autosave\n"
|
||||
"'get' [config addr]' - get config from pre-configured URL and store addr, ON|OFF - enable/disable download on startup\n"
|
||||
"'load' - load config from NVRAM\n"
|
||||
"'pwd' - define MQTT password\n"
|
||||
"'pwd' - define and store MQTT password\n"
|
||||
"'otapwd' - define and store HTTP API password\n"
|
||||
"'log [serial_loglevel] [udp_loglevel]' - define log level (0..7)\n"
|
||||
"'kill' - test watchdog\n"
|
||||
"'clear' - clear EEPROM\n"
|
||||
"'reboot' - reboot controller");
|
||||
@@ -1081,9 +1068,12 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
||||
void printCurentLanConfig() {
|
||||
infoSerial << F("Current LAN config(ip,dns,gw,subnet):");
|
||||
printIPAddress(Ethernet.localIP());
|
||||
// printIPAddress(Ethernet.dnsServerIP());
|
||||
#if not defined(ESP8266) and not defined(ESP32)
|
||||
printIPAddress(Ethernet.dnsServerIP());
|
||||
#endif
|
||||
printIPAddress(Ethernet.gatewayIP());
|
||||
printIPAddress(Ethernet.subnetMask());
|
||||
|
||||
}
|
||||
|
||||
void cmdFunctionKill(int arg_cnt, char **args) {
|
||||
@@ -1262,12 +1252,16 @@ int loadConfigFromEEPROM()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
|
||||
//#define saveBufLen 16000
|
||||
void cmdFunctionSave(int arg_cnt, char **args)
|
||||
{
|
||||
if (arg_cnt>1)
|
||||
{
|
||||
if (!strcasecmp_P(args[1],ON_P)) sysConf.setSaveSuccedConfig(true);
|
||||
if (!strcasecmp_P(args[1],OFF_P)) sysConf.setSaveSuccedConfig(false);
|
||||
infoSerial<<F("Config autosave:")<<sysConf.getSaveSuccedConfig()<<endl;
|
||||
return;
|
||||
}
|
||||
#if defined(__SAM3X8E__)
|
||||
char* outBuf = (char*) malloc(MAX_JSON_CONF_SIZE); /* XXX: Dynamic size. */
|
||||
if (outBuf == NULL)
|
||||
{
|
||||
@@ -1278,32 +1272,36 @@ void cmdFunctionSave(int arg_cnt, char **args)
|
||||
aJson.print(root, &stringStream);
|
||||
int len = strlen(outBuf);
|
||||
outBuf[len++]= EOF;
|
||||
|
||||
//EEPROM.write(EEPROM_offsetJSON,(byte*) outBuf,len);
|
||||
JSONStream.seek();
|
||||
size_t res = JSONStream.write((byte*) outBuf,len);
|
||||
free (outBuf);
|
||||
infoSerial<<res<< F("bytes from ")<<len<<F(" are saved to EEPROM")<<endl;
|
||||
}
|
||||
|
||||
#else
|
||||
void cmdFunctionSave(int arg_cnt, char **args)
|
||||
{
|
||||
//aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offsetJSON);
|
||||
//flashStream fs = flashStream(EEPROM_offsetJSON);
|
||||
JSONStream.seek();
|
||||
aJsonStream jsonEEPROMStream = aJsonStream(&JSONStream);
|
||||
|
||||
infoSerial<<F("Saving config to EEPROM..");
|
||||
|
||||
aJson.print(root, &jsonEEPROMStream);
|
||||
JSONStream.putEOF();
|
||||
|
||||
|
||||
infoSerial<<F("Saved to EEPROM")<<endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void cmdFunctionLoglevel(int arg_cnt, char **args)
|
||||
{
|
||||
if (arg_cnt>1)
|
||||
{
|
||||
serialDebugLevel=atoi(args[1]);
|
||||
sysConf.setSerialDebuglevel(serialDebugLevel);
|
||||
}
|
||||
|
||||
if (arg_cnt>2)
|
||||
{
|
||||
udpDebugLevel=atoi(args[2]);
|
||||
sysConf.setUdpDebuglevel(udpDebugLevel);
|
||||
}
|
||||
infoSerial<<F("Serial debug level:")<<serialDebugLevel<<F("\nSyslog debug level:")<<udpDebugLevel<<endl;
|
||||
}
|
||||
|
||||
void cmdFunctionIp(int arg_cnt, char **args)
|
||||
{
|
||||
@@ -1367,7 +1365,7 @@ void cmdFunctionPwd(int arg_cnt, char **args)
|
||||
if (arg_cnt)
|
||||
sysConf.setMQTTpwd(args[1]);
|
||||
else sysConf.setMQTTpwd();
|
||||
infoSerial<<F("Password updated\n");
|
||||
infoSerial<<F("MQTT Password updated\n");
|
||||
}
|
||||
|
||||
void cmdFunctionOTAPwd(int arg_cnt, char **args)
|
||||
@@ -1375,7 +1373,7 @@ void cmdFunctionOTAPwd(int arg_cnt, char **args)
|
||||
if (arg_cnt)
|
||||
sysConf.setOTApwd(args[1]);
|
||||
else sysConf.setOTApwd();
|
||||
infoSerial<<F("Password updated\n");
|
||||
infoSerial<<F("OTA Password updated\n");
|
||||
}
|
||||
|
||||
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||
@@ -1393,6 +1391,14 @@ void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||
}
|
||||
|
||||
void cmdFunctionGet(int arg_cnt, char **args) {
|
||||
if (arg_cnt>1)
|
||||
{
|
||||
if (!strcasecmp_P(args[1],ON_P)) sysConf.setLoadHTTPConfig(true);
|
||||
if (!strcasecmp_P(args[1],OFF_P)) sysConf.setLoadHTTPConfig(false);
|
||||
infoSerial<<F("Loading HTTP config on startup:")<<sysConf.getLoadHTTPConfig()<<endl;
|
||||
return;
|
||||
}
|
||||
|
||||
lanStatus= loadConfigFromHttp(arg_cnt, args);
|
||||
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||
}
|
||||
@@ -1613,7 +1619,9 @@ void TimerHandler(void)
|
||||
interrupts();
|
||||
timerCount=micros();
|
||||
if (configLoaded && !timerHandlerBusy) inputLoop(CHECK_INTERRUPT);
|
||||
#ifdef DMX_SMOOTH
|
||||
DMXOUT_propagate();
|
||||
#endif
|
||||
timerCount=micros()-timerCount;
|
||||
timerHandlerBusy--;
|
||||
}
|
||||
@@ -1633,6 +1641,19 @@ int16_t attachTimer(double microseconds, timerCallback callback, const char* Tim
|
||||
|
||||
void setup_main() {
|
||||
|
||||
#if (SERIAL_BAUD)
|
||||
debugSerialPort.begin(SERIAL_BAUD);
|
||||
#else
|
||||
|
||||
#if not defined (__SAM3X8E__)
|
||||
debugSerialPort.begin();
|
||||
#endif
|
||||
delay(1000);
|
||||
#endif
|
||||
|
||||
serialDebugLevel=sysConf.getSerialDebuglevel();
|
||||
udpDebugLevel=sysConf.getUdpDebuglevel();
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
memset(&UniqueID,0,sizeof(UniqueID));
|
||||
#endif
|
||||
@@ -1943,7 +1964,8 @@ if (!sysConf.getMAC()) {
|
||||
}
|
||||
|
||||
void setupCmdArduino() {
|
||||
cmdInit(uint32_t(SERIAL_BAUD));
|
||||
//cmdInit(uint32_t(SERIAL_BAUD));
|
||||
cmdInit();
|
||||
debugSerial<<(F(">>>"));
|
||||
cmdAdd("help", cmdFunctionHelp);
|
||||
cmdAdd("save", cmdFunctionSave);
|
||||
@@ -1959,6 +1981,7 @@ void setupCmdArduino() {
|
||||
cmdAdd("otapwd", cmdFunctionOTAPwd);
|
||||
cmdAdd("clear",cmdFunctionClearEEPROM);
|
||||
cmdAdd("reboot",cmdFunctionReboot);
|
||||
cmdAdd("log",cmdFunctionLoglevel);
|
||||
}
|
||||
|
||||
void loop_main() {
|
||||
@@ -1983,7 +2006,11 @@ void loop_main() {
|
||||
|
||||
#ifdef _artnet
|
||||
yield();
|
||||
if (artnet) artnet->read(); ///hung
|
||||
if (artnet) artnet->read(); ///hung if network not initialized
|
||||
#endif
|
||||
#ifdef MDNS_ENABLE
|
||||
yield();
|
||||
mdns.run();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2011,9 +2038,7 @@ void loop_main() {
|
||||
dmxout.update();
|
||||
#endif
|
||||
|
||||
#ifdef MDNS_ENABLE
|
||||
mdns.run();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void owIdle(void) {
|
||||
@@ -2044,27 +2069,32 @@ ethernetIdleCount--;
|
||||
};
|
||||
|
||||
void modbusIdle(void) {
|
||||
wdt_res();
|
||||
statusLED.poll();
|
||||
yield();
|
||||
cmdPoll();
|
||||
wdt_res();
|
||||
if (lanLoop() > HAVE_IP_ADDRESS) {
|
||||
yield();
|
||||
inputLoop(CHECK_INPUT);
|
||||
|
||||
if (lanLoop() > HAVE_IP_ADDRESS)
|
||||
{ // Begin network runners
|
||||
yield();
|
||||
mqttClient.loop();
|
||||
#ifdef _artnet
|
||||
if (artnet) artnet->read();
|
||||
#endif
|
||||
#if defined(OTA)
|
||||
yield();
|
||||
inputLoop(CHECK_INPUT);
|
||||
}
|
||||
ArduinoOTA.poll();
|
||||
#endif
|
||||
#ifdef MDNS_ENABLE
|
||||
mdns.run();
|
||||
#endif
|
||||
#endif
|
||||
} //End network runners
|
||||
|
||||
#ifdef _dmxin
|
||||
DMXCheck();
|
||||
#endif
|
||||
|
||||
#if defined (_espdmx)
|
||||
dmxout.update();
|
||||
#endif
|
||||
|
||||
@@ -261,6 +261,8 @@ void cmdFunctionSetMac(int arg_cnt, char **args);
|
||||
|
||||
void cmdFunctionGet(int arg_cnt, char **args);
|
||||
|
||||
void cmdFunctionLoglevel(int arg_cnt, char **args);
|
||||
|
||||
void printBool(bool arg);
|
||||
/*
|
||||
void saveFlash(short n, char *str);
|
||||
|
||||
@@ -28,7 +28,7 @@ int in_ccs811::Setup()
|
||||
digitalWrite(WAK_PIN,LOW);
|
||||
#endif
|
||||
|
||||
Serial.println("CCS811 Init");
|
||||
debugSerial.println("CCS811 Init");
|
||||
|
||||
Wire.begin(); //Inialize I2C Harware
|
||||
Wire.setClock(4000);
|
||||
@@ -41,7 +41,7 @@ Wire.setClock(4000);
|
||||
//if (returnCode != CCS811Core::CCS811_Stat_SUCCESS)
|
||||
{
|
||||
Serial.print("CCS811 Init error ");
|
||||
//Serial.println(ccs811.statusString(returnCode));
|
||||
//debugSerial.println(ccs811.statusString(returnCode));
|
||||
printDriverError(returnCode);
|
||||
return 0;
|
||||
}
|
||||
@@ -61,16 +61,16 @@ return 1;
|
||||
int in_hdc1080::Setup()
|
||||
{
|
||||
if (HDC1080ready) {debugSerial<<F("hdc1080 is already initialized")<<endl; return 0;}
|
||||
Serial.println("HDC1080 Init ");
|
||||
debugSerial.println("HDC1080 Init ");
|
||||
Wire.begin(); //Inialize I2C Harware
|
||||
// Default settings:
|
||||
// - Heater off
|
||||
// - 14 bit Temperature and Humidity Measurement Resolutions
|
||||
hdc1080.begin(0x40);
|
||||
Serial.print("Manufacturer ID=0x");
|
||||
Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
|
||||
Serial.print("Device ID=0x");
|
||||
Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
|
||||
debugSerial.print("Manufacturer ID=0x");
|
||||
debugSerial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
|
||||
debugSerial.print("Device ID=0x");
|
||||
debugSerial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
|
||||
printSerialNumber();
|
||||
HDC1080ready = true;
|
||||
return 1;
|
||||
@@ -91,15 +91,15 @@ int in_hdc1080::Poll(short cause)
|
||||
int reg;
|
||||
if (cause!=POLLING_SLOW) return 0;
|
||||
if (!HDC1080ready) {debugSerial<<F("HDC1080 not initialized")<<endl; return 0;}
|
||||
Serial.print("HDC Status=");
|
||||
Serial.println(reg=hdc1080.readRegister().rawData,HEX);
|
||||
debugSerial.print("HDC Status=");
|
||||
debugSerial.println(reg=hdc1080.readRegister().rawData,HEX);
|
||||
if (reg!=0xff)
|
||||
{
|
||||
Serial.print(" T=");
|
||||
Serial.print(t=hdc1080.readTemperature());
|
||||
Serial.print("C, RH=");
|
||||
Serial.print(h=hdc1080.readHumidity());
|
||||
Serial.println("%");
|
||||
debugSerial.print(" T=");
|
||||
debugSerial.print(t=hdc1080.readTemperature());
|
||||
debugSerial.print("C, RH=");
|
||||
debugSerial.print(h=hdc1080.readHumidity());
|
||||
debugSerial.println("%");
|
||||
|
||||
|
||||
#ifdef M5STACK
|
||||
@@ -125,7 +125,7 @@ if (reg!=0xff)
|
||||
}
|
||||
else //ESP I2C glitch
|
||||
{
|
||||
Serial.println("I2C Reset");
|
||||
debugSerial.println("I2C Reset");
|
||||
i2cReset();
|
||||
}
|
||||
return INTERVAL_SLOW_POLLING;
|
||||
@@ -147,15 +147,15 @@ int in_ccs811::Poll(short cause)
|
||||
CCS811Core::status returnCode = ccs811.readAlgorithmResults();
|
||||
printDriverError(returnCode);
|
||||
float co2,tvoc;
|
||||
Serial.print(" CO2[");
|
||||
debugSerial.print(" CO2[");
|
||||
//Returns calculated CO2 reading
|
||||
Serial.print(co2 = ccs811.getCO2());
|
||||
Serial.print("] tVOC[");
|
||||
debugSerial.print(co2 = ccs811.getCO2());
|
||||
debugSerial.print("] tVOC[");
|
||||
//Returns calculated TVOC reading
|
||||
|
||||
Serial.print(tvoc = ccs811.getTVOC());
|
||||
Serial.print("] baseline[");
|
||||
Serial.print(ccs811Baseline = ccs811.getBaseline());
|
||||
debugSerial.print(tvoc = ccs811.getTVOC());
|
||||
debugSerial.print("] baseline[");
|
||||
debugSerial.print(ccs811Baseline = ccs811.getBaseline());
|
||||
|
||||
#ifdef M5STACK
|
||||
M5.Lcd.print(" CO2[");
|
||||
@@ -181,7 +181,7 @@ int in_ccs811::Poll(short cause)
|
||||
publish(co2,"/CO2");
|
||||
publish(tvoc,"/TVOC");
|
||||
publish(ccs811Baseline,"/base");}
|
||||
Serial.println("]");
|
||||
debugSerial.println("]");
|
||||
printSensorError();
|
||||
|
||||
#ifdef WAK_PIN
|
||||
@@ -192,11 +192,11 @@ int in_ccs811::Poll(short cause)
|
||||
}
|
||||
|
||||
void in_hdc1080::printSerialNumber() {
|
||||
Serial.print("Device Serial Number=");
|
||||
debugSerial.print("Device Serial Number=");
|
||||
HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
|
||||
char format[16];
|
||||
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
|
||||
Serial.println(format);
|
||||
debugSerial.println(format);
|
||||
}
|
||||
|
||||
//printDriverError decodes the CCS811Core::status type and prints the
|
||||
@@ -209,22 +209,22 @@ void in_ccs811::printDriverError( CCS811Core::status errorCode )
|
||||
switch ( errorCode )
|
||||
{
|
||||
case CCS811Core::SENSOR_SUCCESS:
|
||||
Serial.print("SUCCESS");
|
||||
debugSerial.print("SUCCESS");
|
||||
break;
|
||||
case CCS811Core::SENSOR_ID_ERROR:
|
||||
Serial.print("ID_ERROR");
|
||||
debugSerial.print("ID_ERROR");
|
||||
break;
|
||||
case CCS811Core::SENSOR_I2C_ERROR:
|
||||
Serial.print("I2C_ERROR");
|
||||
debugSerial.print("I2C_ERROR");
|
||||
break;
|
||||
case CCS811Core::SENSOR_INTERNAL_ERROR:
|
||||
Serial.print("INTERNAL_ERROR");
|
||||
debugSerial.print("INTERNAL_ERROR");
|
||||
break;
|
||||
case CCS811Core::SENSOR_GENERIC_ERROR:
|
||||
Serial.print("GENERIC_ERROR");
|
||||
debugSerial.print("GENERIC_ERROR");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unspecified error.");
|
||||
debugSerial.print("Unspecified error.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,18 +236,18 @@ void in_ccs811::printSensorError()
|
||||
|
||||
if ( error == 0xFF ) //comm error
|
||||
{
|
||||
Serial.println("Failed to get ERROR_ID register.");
|
||||
debugSerial.println("Failed to get ERROR_ID register.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Serial.print("");
|
||||
if (error & 1 << 5) Serial.print("Error: HeaterSupply");
|
||||
if (error & 1 << 4) Serial.print("Error: HeaterFault");
|
||||
if (error & 1 << 3) Serial.print("Error: MaxResistance");
|
||||
if (error & 1 << 2) Serial.print("Error: MeasModeInvalid");
|
||||
if (error & 1 << 1) Serial.print("Error: ReadRegInvalid");
|
||||
if (error & 1 << 0) Serial.print("Error: MsgInvalid");
|
||||
Serial.println();
|
||||
//debugSerial.print("");
|
||||
if (error & 1 << 5) debugSerial.print("Error: HeaterSupply");
|
||||
if (error & 1 << 4) debugSerial.print("Error: HeaterFault");
|
||||
if (error & 1 << 3) debugSerial.print("Error: MaxResistance");
|
||||
if (error & 1 << 2) debugSerial.print("Error: MeasModeInvalid");
|
||||
if (error & 1 << 1) debugSerial.print("Error: ReadRegInvalid");
|
||||
if (error & 1 << 0) debugSerial.print("Error: MsgInvalid");
|
||||
debugSerial.println();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -82,8 +82,8 @@ void out_AC::InsertData(byte data[], size_t size){
|
||||
}
|
||||
*/
|
||||
|
||||
Serial.print ("Power=");
|
||||
Serial.println(power);
|
||||
debugSerial.print ("Power=");
|
||||
debugSerial.println(power);
|
||||
|
||||
if (power & 0x08)
|
||||
publishTopic(item->itemArr->name, "ON", "/quiet");
|
||||
@@ -189,7 +189,7 @@ void SendData(byte req[], size_t size){
|
||||
AC_Serial.write(req, size - 1);
|
||||
AC_Serial.write(getCRC(req, size-1));
|
||||
AC_Serial.flush();
|
||||
|
||||
/*
|
||||
Serial.print("<<");
|
||||
for (int i=0; i < size-1; i++)
|
||||
{
|
||||
@@ -203,6 +203,7 @@ void SendData(byte req[], size_t size){
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
*/
|
||||
}
|
||||
|
||||
inline unsigned char toHex( char ch ){
|
||||
@@ -214,7 +215,7 @@ inline unsigned char toHex( char ch ){
|
||||
int out_AC::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
Serial.println("AC Init");
|
||||
debugSerial.println("AC Init");
|
||||
AC_Serial.begin(9600);
|
||||
driverStatus = CST_INITIALIZED;
|
||||
return 1;
|
||||
@@ -222,7 +223,7 @@ return 1;
|
||||
|
||||
int out_AC::Stop()
|
||||
{
|
||||
Serial.println("AC De-Init");
|
||||
debugSerial.println("AC De-Init");
|
||||
|
||||
driverStatus = CST_UNKNOWN;
|
||||
return 1;
|
||||
@@ -246,7 +247,7 @@ if (cause!=POLLING_SLOW) return 0;
|
||||
//if (now - prevPolling > INTERVAL_AC_POLLING) {
|
||||
if (isTimeOver(prevPolling,millis(),INTERVAL_AC_POLLING)) {
|
||||
prevPolling = millisNZ();
|
||||
Serial.println ("Polling");
|
||||
debugSerial.println ("Polling");
|
||||
SendData(qstn, sizeof(qstn)/sizeof(byte)); //Опрос кондиционера
|
||||
}
|
||||
delay(100);
|
||||
|
||||
@@ -187,7 +187,7 @@ else
|
||||
|
||||
int out_Modbus::Stop()
|
||||
{
|
||||
Serial.println("Modbus De-Init");
|
||||
debugSerial.println("Modbus De-Init");
|
||||
|
||||
delete store;
|
||||
item->setPersistent(NULL);
|
||||
|
||||
@@ -50,7 +50,7 @@ int out_Motor::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
getConfig();
|
||||
Serial.println("Motor Init");
|
||||
debugSerial.println("Motor Init");
|
||||
pinMode(pinUp,OUTPUT);
|
||||
pinMode(pinDown,OUTPUT);
|
||||
|
||||
@@ -70,7 +70,7 @@ return 1;
|
||||
|
||||
int out_Motor::Stop()
|
||||
{
|
||||
Serial.println("Motor De-Init");
|
||||
debugSerial.println("Motor De-Init");
|
||||
digitalWrite(pinUp,INACTIVE);
|
||||
digitalWrite(pinDown,INACTIVE);
|
||||
|
||||
@@ -240,7 +240,7 @@ else
|
||||
|
||||
}
|
||||
else //Target zone
|
||||
{ Serial.println("Target");
|
||||
{ debugSerial.println("Target");
|
||||
digitalWrite(pinUp,INACTIVE);
|
||||
digitalWrite(pinDown,INACTIVE);
|
||||
item->setExt(0);
|
||||
|
||||
@@ -113,7 +113,7 @@ else
|
||||
|
||||
int out_pid::Stop()
|
||||
{
|
||||
Serial.println("PID De-Init");
|
||||
debugSerial.println("PID De-Init");
|
||||
if (store) delete (store->pid);
|
||||
delete store;
|
||||
item->setPersistent(NULL);
|
||||
|
||||
@@ -45,7 +45,7 @@ int out_SPILed::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
getConfig();
|
||||
Serial.println("SPI-LED Init");
|
||||
debugSerial.println("SPI-LED Init");
|
||||
|
||||
if (!leds)
|
||||
{
|
||||
@@ -69,7 +69,7 @@ return 1;
|
||||
|
||||
int out_SPILed::Stop()
|
||||
{
|
||||
Serial.println("SPI-LED De-Init");
|
||||
debugSerial.println("SPI-LED De-Init");
|
||||
//FastLED.addLeds<TM1809, DATA_PIN, BRG>(leds, NUM_LEDS);
|
||||
#ifdef ADAFRUIT_LED
|
||||
leds->clear();
|
||||
|
||||
@@ -134,7 +134,7 @@ else
|
||||
|
||||
int out_UARTbridge::Stop()
|
||||
{
|
||||
Serial.println("UARTbridge De-Init");
|
||||
debugSerial.println("UARTbridge De-Init");
|
||||
|
||||
udpClientA.stop();
|
||||
udpClientB.stop();
|
||||
|
||||
@@ -2,13 +2,21 @@
|
||||
#include <Arduino.h>
|
||||
#include "statusled.h"
|
||||
|
||||
#ifdef SYSLOG_ENABLE
|
||||
char logBuffer[LOGBUFFER_SIZE];
|
||||
int logBufferPos=0;
|
||||
#endif
|
||||
|
||||
uint8_t serialDebugLevel = 7;
|
||||
uint8_t udpDebugLevel =7;
|
||||
|
||||
#if defined (STATUSLED)
|
||||
extern StatusLED statusLED;
|
||||
#endif
|
||||
|
||||
#ifdef SYSLOG_ENABLE
|
||||
extern bool syslogInitialized;
|
||||
Streamlog::Streamlog (HardwareSerial * _serialPort, int _severity , Syslog * _syslog, uint8_t _ledPattern )
|
||||
Streamlog::Streamlog (SerialPortType * _serialPort, uint8_t _severity , Syslog * _syslog, uint8_t _ledPattern )
|
||||
{
|
||||
serialPort=_serialPort;
|
||||
severity=_severity;
|
||||
@@ -16,7 +24,7 @@ Streamlog::Streamlog (HardwareSerial * _serialPort, int _severity , Syslog * _sy
|
||||
ledPattern=_ledPattern;
|
||||
}
|
||||
#else
|
||||
Streamlog::Streamlog (HardwareSerial * _serialPort, int _severity, uint8_t _ledPattern)
|
||||
Streamlog::Streamlog (SerialPortType * _serialPort, uint8_t _severity, uint8_t _ledPattern)
|
||||
{
|
||||
serialPort=_serialPort;
|
||||
severity=_severity;
|
||||
@@ -61,7 +69,7 @@ void Streamlog::flush(void)
|
||||
size_t Streamlog::write(uint8_t ch)
|
||||
{
|
||||
#ifdef SYSLOG_ENABLE
|
||||
if (syslogInitialized)
|
||||
if (syslogInitialized && (udpDebugLevel>=severity))
|
||||
{
|
||||
if (ch=='\n')
|
||||
{
|
||||
@@ -80,7 +88,7 @@ if (syslogInitialized)
|
||||
if ((ch=='\n') && ledPattern) statusLED.flash(ledPattern);
|
||||
#endif
|
||||
|
||||
if (serialPort) return serialPort->write(ch);
|
||||
if (serialPort && (serialDebugLevel>=severity)) return serialPort->write(ch);
|
||||
|
||||
return 1;
|
||||
};
|
||||
|
||||
@@ -1,34 +1,41 @@
|
||||
#pragma once
|
||||
#include <Print.h>
|
||||
#include <Arduino.h>
|
||||
#include <HardwareSerial.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined (STM32)
|
||||
#include <USBSerial.h>
|
||||
#endif
|
||||
|
||||
#ifndef LOGBUFFER_SIZE
|
||||
#define LOGBUFFER_SIZE 80
|
||||
#endif
|
||||
|
||||
#ifdef SYSLOG_ENABLE
|
||||
#include <Syslog.h>
|
||||
static char logBuffer[LOGBUFFER_SIZE];
|
||||
static int logBufferPos=0;
|
||||
#endif
|
||||
|
||||
extern uint8_t serialDebugLevel;
|
||||
extern uint8_t udpDebugLevel;
|
||||
|
||||
|
||||
#ifndef SerialPortType
|
||||
#define SerialPortType HardwareSerial
|
||||
#endif
|
||||
|
||||
#define LOG_DEBUG 7
|
||||
#define LOG_INFO 6
|
||||
#define LOG_INFO 6
|
||||
#define LOG_ERROR 3
|
||||
|
||||
static uint8_t serialDebugLevel = 7;
|
||||
static uint8_t udpDebugLevel =7;
|
||||
|
||||
class Streamlog : public Print
|
||||
{
|
||||
public:
|
||||
#ifdef SYSLOG_ENABLE
|
||||
Streamlog (HardwareSerial * _serialPort, int _severity = LOG_DEBUG, Syslog * _syslog = NULL, uint8_t _ledPattern = 0);
|
||||
Streamlog (SerialPortType * _serialPort, uint8_t _severity = LOG_DEBUG, Syslog * _syslog = NULL, uint8_t _ledPattern = 0);
|
||||
#else
|
||||
Streamlog (HardwareSerial * _serialPort, int _severity = LOG_DEBUG, uint8_t _ledPattern = 0);
|
||||
Streamlog (SerialPortType * _serialPort, uint8_t _severity = LOG_DEBUG, uint8_t _ledPattern = 0);
|
||||
#endif
|
||||
// {serialPort=_serialPort;severity=_severity; syslog=_syslog; }
|
||||
void begin(unsigned long speed);
|
||||
void end() ;
|
||||
|
||||
@@ -40,8 +47,8 @@ class Streamlog : public Print
|
||||
using Print::write; // pull in write(str) and write(buf, size) from Print
|
||||
operator bool() {return true;};
|
||||
private:
|
||||
uint16_t severity;
|
||||
HardwareSerial *serialPort;
|
||||
uint8_t severity;
|
||||
SerialPortType *serialPort;
|
||||
#ifdef SYSLOG_ENABLE
|
||||
Syslog * syslog;
|
||||
uint8_t ledPattern;
|
||||
|
||||
@@ -28,6 +28,10 @@ e-mail anklimov@gmail.com
|
||||
#include <PubSubClient.h>
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
#ifndef debugSerialPort
|
||||
#define debugSerialPort Serial
|
||||
#endif
|
||||
|
||||
extern int8_t configLocked;
|
||||
extern int8_t ethernetIdleCount;
|
||||
extern PubSubClient mqttClient;
|
||||
@@ -63,7 +67,7 @@ void PrintBytes(uint8_t *addr, uint8_t count, bool newline) {
|
||||
const char HEXSTR[] = "0123456789ABCDEF";
|
||||
|
||||
void SetBytes(uint8_t *addr, uint8_t count, char *out) {
|
||||
// Serial.println("SB:");
|
||||
// debugSerialPort.println("SB:");
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
*(out++) = HEXSTR[(addr[i] >> 4)];
|
||||
*(out++) = HEXSTR[(addr[i] & 0x0f)];
|
||||
@@ -101,7 +105,7 @@ int getInt(char **chan) {
|
||||
//Move pointer to next element (after ,)
|
||||
*chan = strchr(*chan, ',');
|
||||
if (*chan) *chan += 1;
|
||||
//Serial.print(F("Par:")); Serial.println(ch);
|
||||
//debugSerialPort.print(F("Par:")); debugSerialPort.println(ch);
|
||||
return ch;
|
||||
}
|
||||
return 0;
|
||||
@@ -131,7 +135,7 @@ itemCmd getNumber(char **chan) {
|
||||
//Move pointer to next element (after ,)
|
||||
*chan = strchr(*chan, ',');
|
||||
if (*chan) *chan += 1;
|
||||
//Serial.print(F("Par:")); Serial.println(ch);
|
||||
//debugSerialPort.print(F("Par:")); debugSerialPort.println(ch);
|
||||
|
||||
if (fract)
|
||||
val.Tens(ch*10+((ch>0)?fract:-fract));
|
||||
@@ -248,7 +252,7 @@ int log(const char *str, ...)//TODO: __FlashStringHelper str support
|
||||
{
|
||||
//Clear buffer
|
||||
temp[j] = '\0';
|
||||
Serial.print(temp);
|
||||
debugSerialPort.print(temp);
|
||||
j=0;
|
||||
temp[0] = '\0';
|
||||
|
||||
@@ -282,7 +286,7 @@ int log(const char *str, ...)//TODO: __FlashStringHelper str support
|
||||
}
|
||||
};
|
||||
|
||||
Serial.println(); //Print trailing newline
|
||||
debugSerialPort.println(); //Print trailing newline
|
||||
return count + 1; //Return number of arguments detected
|
||||
}
|
||||
|
||||
@@ -415,9 +419,9 @@ for(n = 0; n < 4; n++) {
|
||||
void printIPAddress(IPAddress ipAddress) {
|
||||
for (byte i = 0; i < 4; i++)
|
||||
#ifdef WITH_PRINTEX_LIB
|
||||
(i < 3) ? debugSerial << (ipAddress[i]) << F(".") : debugSerial << (ipAddress[i])<<F(", ");
|
||||
(i < 3) ? debugSerial << (ipAddress[i]) << F(".") : infoSerial << (ipAddress[i])<<F(", ");
|
||||
#else
|
||||
(i < 3) ? debugSerial << _DEC(ipAddress[i]) << F(".") : debugSerial << _DEC(ipAddress[i]) << F(" ");
|
||||
(i < 3) ? debugSerial << _DEC(ipAddress[i]) << F(".") : infoSerial << _DEC(ipAddress[i]) << F(" ");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user