diff --git a/.gitignore b/.gitignore index af7a200..e4aa71d 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ custom-build-flags/build_flags_nrf52840 .vscode/.browse.c_cpp.db .vscode/c_cpp_properties.json .vscode/launch.json +lighthub/modules/out_elevator.cpp +lighthub/modules/out_elevator.h +spare_files/* diff --git a/build-flags/build_flags_due b/build-flags/build_flags_due index d966d23..e519ba9 100644 --- a/build-flags/build_flags_due +++ b/build-flags/build_flags_due @@ -6,5 +6,8 @@ -DOTA -DSTATUSLED #-DPID_DISABLE --DUARTBRIDGE_ENABLE +#-DUARTBRIDGE_ENABLE +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE +-DMCP23017 diff --git a/build-flags/build_flags_due-5100 b/build-flags/build_flags_due-5100 index 2516dad..e94cde9 100644 --- a/build-flags/build_flags_due-5100 +++ b/build-flags/build_flags_due-5100 @@ -4,3 +4,5 @@ -DSYSLOG_ENABLE -DWiz5100 #-DPID_DISABLE +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE diff --git a/build-flags/build_flags_due-5500 b/build-flags/build_flags_due-5500 index 63ccf4f..6be5c9e 100644 --- a/build-flags/build_flags_due-5500 +++ b/build-flags/build_flags_due-5500 @@ -4,3 +4,5 @@ -DSTATUSLED -DSYSLOG_ENABLE #-DPID_DISABLE +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE diff --git a/build-flags/build_flags_esp32-wifi b/build-flags/build_flags_esp32-wifi index a2b7530..6042312 100644 --- a/build-flags/build_flags_esp32-wifi +++ b/build-flags/build_flags_esp32-wifi @@ -9,6 +9,9 @@ -DSYSLOG_ENABLE # - udp errors -DOTA +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE + -DMCP23017 -DMODBUS_TX_PIN=13 #-DARTNET_ENABLE - udp rx errors (( diff --git a/build-flags/build_flags_esp8266-wifi b/build-flags/build_flags_esp8266-wifi index c260343..28ad70a 100644 --- a/build-flags/build_flags_esp8266-wifi +++ b/build-flags/build_flags_esp8266-wifi @@ -8,3 +8,6 @@ -DUSE_1W_PIN=16 -DW5500_CS_PIN=15 #-DPID_DISABLE +-DARDUINO_OTA_MDNS_DISABLE +##-DMDNS_ENABLE +-DMCP23017 diff --git a/build-flags/build_flags_lighthub21 b/build-flags/build_flags_lighthub21 index 5c57c77..1911320 100644 --- a/build-flags/build_flags_lighthub21 +++ b/build-flags/build_flags_lighthub21 @@ -9,3 +9,5 @@ -DSTATUSLED -DMCP23017 #-DPID_DISABLE +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE diff --git a/build-flags/build_flags_m5stack b/build-flags/build_flags_m5stack index 91ac736..7ebced9 100644 --- a/build-flags/build_flags_m5stack +++ b/build-flags/build_flags_m5stack @@ -10,3 +10,6 @@ #-DSYSLOG_ENABLE -DUSE_1W_PIN=16 #-DPID_DISABLE +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE +-DMCP23017 diff --git a/build-flags/build_flags_mega2560-5100 b/build-flags/build_flags_mega2560-5100 index ba410e1..38fc8e7 100644 --- a/build-flags/build_flags_mega2560-5100 +++ b/build-flags/build_flags_mega2560-5100 @@ -3,3 +3,5 @@ -DSYSLOG_ENABLE -DWiz5100 #-DPID_DISABLE +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE diff --git a/build-flags/build_flags_mega2560-5500 b/build-flags/build_flags_mega2560-5500 index dc93f63..def428b 100644 --- a/build-flags/build_flags_mega2560-5500 +++ b/build-flags/build_flags_mega2560-5500 @@ -2,4 +2,6 @@ #-DMODBUS_DIMMER_PARAM=SERIAL_8E1 -DAVR_DMXOUT_PIN=18 -DSYSLOG_ENABLE -#-DPID_DISABLE \ No newline at end of file +#-DPID_DISABLE +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE \ No newline at end of file diff --git a/build-flags/build_flags_mega2560slim2 b/build-flags/build_flags_mega2560slim2 index 7c9f125..477aa66 100644 --- a/build-flags/build_flags_mega2560slim2 +++ b/build-flags/build_flags_mega2560slim2 @@ -15,4 +15,9 @@ -DPID_DISABLE -DOTA -DMOTOR_DISABLE -#-DWiz5100 \ No newline at end of file +#-DWiz5100 +-DARDUINO_OTA_MDNS_DISABLE +-DMDNS_ENABLE + +# Example of UARTBRIDGE configuration +#-DUARTBRIDGE_ENABLE diff --git a/build-flags/build_flags_nrf52840-5500 b/build-flags/build_flags_nrf52840 similarity index 90% rename from build-flags/build_flags_nrf52840-5500 rename to build-flags/build_flags_nrf52840 index 486230d..82b89c4 100644 --- a/build-flags/build_flags_nrf52840-5500 +++ b/build-flags/build_flags_nrf52840 @@ -1,4 +1,4 @@ --DWiz5500 +#-DWiz5500 #-DW5500_CS_PIN=10 -DDMX_DISABLE -DMODBUS_DISABLE @@ -12,3 +12,4 @@ -DSYSLOG_ENABLE -DMBUS_DISABLE -DPID_DISABLE +-DMCP23017 diff --git a/compiled/mega2560slim2/getCNF.sh b/compiled/mega2560slim2/getCNF.sh new file mode 100755 index 0000000..8177ffb --- /dev/null +++ b/compiled/mega2560slim2/getCNF.sh @@ -0,0 +1 @@ +../tools/mac/arduinoOTA -d -address 192.168.88.70 -port 65280 -username arduino -password password -b /config diff --git a/compiled/mega2560slim2/uploadCNF.sh b/compiled/mega2560slim2/uploadCNF.sh new file mode 100755 index 0000000..31f9c0e --- /dev/null +++ b/compiled/mega2560slim2/uploadCNF.sh @@ -0,0 +1 @@ +../tools/mac/arduinoOTA -address elev.local -port 65280 -username arduino -password password -sketch config.json -b -upload /config diff --git a/compiled/mega2560slim2/uploadOTA.sh b/compiled/mega2560slim2/uploadOTA.sh index d46b75b..5c09bdb 100755 --- a/compiled/mega2560slim2/uploadOTA.sh +++ b/compiled/mega2560slim2/uploadOTA.sh @@ -1 +1 @@ -../tools/mac/arduinoOTA -address 192.168.88.67 -port 65280 -username arduino -password password -sketch firmware.bin -b -upload /sketch +../tools/mac/arduinoOTA -address 192.168.11.213 -port 65280 -username arduino -password password -sketch firmware.bin -b -upload /sketch diff --git a/compiled/update_bin.sh b/compiled/update_bin.sh index c366e2f..da06a02 100755 --- a/compiled/update_bin.sh +++ b/compiled/update_bin.sh @@ -7,7 +7,7 @@ cp ../.pio/build/mega2560slim2/firmware.bin mega2560slim2 cp ../.pio/build/due-5100/firmware.bin due-5100 cp ../.pio/build/mega2560-5100/firmware.hex mega2560-5100 cp ../.pio/build/due-5500/firmware.bin due-5500 -cp ../.pio/build/nrf52840-5500/firmware.hex nrf52840-5500 +cp ../.pio/build/nrf52840/firmware.hex nrf52840-5500 cp ../.pio/build/esp32-wifi/firmware.bin esp32-wifi cp ../.pio/build/stm32-enc2860/firmware.bin stm32-enc2860 cp ../.pio/build/esp8266-wifi/firmware.bin esp8266-wifi diff --git a/lighthub/config.cpp b/lighthub/config.cpp new file mode 100644 index 0000000..b0978e4 --- /dev/null +++ b/lighthub/config.cpp @@ -0,0 +1,159 @@ +#include "config.h" + +//#if defined(ARDUINO_ARCH_AVR) +//#include +//#endif + +/* +void saveFlash(short n, char *str) { + short len=strlen(str); + if (len>MAXFLASHSTR-1) len=MAXFLASHSTR-1; + for(int i=0;iseek(offsetof(systemConfigData,signature)); + for (int i=0;iread()!=EEPROM_signature[i]) + { + return false; + } + return true; +}; + + + bool systemConfig::getMAC() + { + if (!stream || !isValidSysConf()) return false; + stream->seek(offsetof(systemConfigData,mac)); + + bool isMacValid = false; + for (short i = 0; i < 6; i++) { + mac[i] = stream->read(); + if (mac[i] != 0 && mac[i] != 0xff) isMacValid = true; + } + return isMacValid; + } + + + bool systemConfig::getMQTTpwd(char * buffer, uint16_t bufLen) + { + + } + + bool systemConfig::setMQTTpwd(char * pwd) + { + + } + + bool systemConfig::setMAC(macAddress mac) + { + + } + + bool systemConfig::setServer(char* url) + { + + } + + bool systemConfig::getServer(char* url) + { + + } + + + bool systemConfig::getIP(IPAddress& ip) + { + + } + + bool systemConfig::getMask(IPAddress& mask) + { + + } + + bool systemConfig::getDNS(IPAddress& dns) + { + + } + + bool systemConfig::getGW(IPAddress& gw) + { + } + + + bool systemConfig::setIP(IPAddress& ip) + { + + } + + bool systemConfig::setMask(IPAddress& mask) + { + + } + + bool systemConfig::setDNS(IPAddress& dns) + { + + } + + bool systemConfig::setGW(IPAddress& gw) + { + + } + + + void systemConfig::clear() + { + + return; + + if (!stream) return ; + stream->seek(0); + for (unsigned int i = 0; i < stream->getSize(); i++) { + mac[i] = stream->write(255); + } + } + + bool systemConfig::getSaveSuccedConfig() + { + return false; + } + + diff --git a/lighthub/config.h b/lighthub/config.h new file mode 100644 index 0000000..1736f57 --- /dev/null +++ b/lighthub/config.h @@ -0,0 +1,86 @@ +#pragma once +#if defined(ESP8266) || defined(ESP32) +#include "FS.h" +#endif + +#include +#include "flashstream.h" +#include + +#define MAXFLASHSTR 32 +#define PWDFLASHSTR 16 +#define EEPROM_SIGNATURE "LHCF" +#define EEPROM_SIGNATURE_LENGTH 4 +const char EEPROM_signature[] = EEPROM_SIGNATURE; + +#define SYSCONF_OFFSET 0 + +#define EEPROM_offset_NotAlligned SYSCONF_OFFSET+sizeof(systemConfigData) +#define EEPROM_offsetJSON EEPROM_offset_NotAlligned + (4 -(EEPROM_offset_NotAlligned & 3)) +//#define EEPROM_offsetJSON IFLASH_PAGE_SIZE +#define EEPROM_FIX_PART_LEN EEPROM_offsetJSON-SYSCONF_OFFSET + + typedef char flashstr[MAXFLASHSTR]; + typedef char flashpwd[PWDFLASHSTR]; + typedef uint8_t macAddress[6]; + + #pragma pack(push, 1) + typedef struct + { + char signature[4]; + macAddress mac; + 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; + + } systemConfigData; + #pragma (pop) + +class systemConfig { + private: + flashStream * stream; + public: + macAddress mac; + systemConfig() {stream=NULL;}; + systemConfig(flashStream * fs){stream=fs;}; + //systemConfigData data; + bool isValidSysConf(); + //bool isValidJSON(); + bool getMAC(); + //inline macAddress * getMAC() {return &mac;}; + + bool getMQTTpwd(char * buffer, uint16_t bufLen); + bool setMQTTpwd(char * pwd = NULL); + bool setMAC(macAddress mac); + bool setServer(char* url); + bool getServer(char* url); + + bool getIP(IPAddress& ip); + bool getMask(IPAddress& mask); + bool getDNS(IPAddress& dns); + bool getGW(IPAddress& gw); + + bool setIP(IPAddress& ip); + bool setMask(IPAddress& mask); + bool setDNS(IPAddress& dns); + bool setGW(IPAddress& gw); + + void clear(); + bool getSaveSuccedConfig(); + bool getLoadHTTPConfig(); + //bool Save(); +}; \ No newline at end of file diff --git a/lighthub/flashstream.cpp b/lighthub/flashstream.cpp new file mode 100644 index 0000000..9c96f7d --- /dev/null +++ b/lighthub/flashstream.cpp @@ -0,0 +1,13 @@ +#include + +#if defined(__SAM3X8E__) +DueFlashStorage EEPROM; +#endif + +#ifdef NRF5 +NRFFlashStorage EEPROM; +#endif + +#ifdef ARDUINO_ARCH_STM32 +NRFFlashStorage EEPROM; +#endif \ No newline at end of file diff --git a/lighthub/flashstream.h b/lighthub/flashstream.h new file mode 100644 index 0000000..b1c7897 --- /dev/null +++ b/lighthub/flashstream.h @@ -0,0 +1,134 @@ +#pragma once +#ifndef _FLASHSTREAM_H_ +#define _FLASHSTREAM_H_ + +#include + +#if defined(ESP32) +#include +#include +#endif + +#if defined(ARDUINO_ARCH_AVR) +#include +#endif + +#if defined(ARDUINO_ARCH_ESP8266) +#include +#endif + + +#if defined(__SAM3X8E__) +#include +extern DueFlashStorage EEPROM; +#endif + +#ifdef NRF5 +#include //STUB +extern NRFFlashStorage EEPROM; +#endif + +#ifdef ARDUINO_ARCH_STM32 +#include //STUB +extern NRFFlashStorage EEPROM; +#endif + + +#include +#include + +class seekableStream : public Stream +{ +unsigned int streamSize; +public: +seekableStream(unsigned int size):Stream(),streamSize(size) {}; +unsigned int getSize() {return streamSize;} +virtual unsigned int seek(unsigned int _pos = 0) = 0; +}; + +#if defined(ESP32) +class flashStream : public seekableStream +{ +private: + File fs; +public: +flashStream(String _filename):seekableStream(65535) {fs = SPIFFS.open(_filename, "r+");} + virtual int available() { return 1; }; + virtual int read() {return fs.read();}; + virtual int peek() { return fs.peek();}; + virtual unsigned int seek(unsigned int _pos = 0){return fs.seek(_pos,SeekSet);}; + virtual void flush() {}; + virtual size_t write(uint8_t ch) {return fs.write(ch);}; + void putEOF(){write (255);}; +virtual ~flashStream () {if (fs) fs.close();} ; +}; + +#else + + +class flashStream : public seekableStream +{ +protected: +unsigned int pos; +unsigned int startPos; +unsigned int size; + +public: +flashStream(unsigned int _startPos=0, unsigned int _size=4096 ):seekableStream(_size) + { + pos = _startPos; startPos = _startPos; size = _size; + #if defined(ESP8266) + size_t len = EEPROM.length(); + if (len) EEPROM.commit(); + EEPROM.begin(len+size); //Re-init + #endif + }; + + virtual unsigned int seek(unsigned int _pos = 0) + { pos=min(startPos+_pos, startPos+size); + debugSerial<state=IS_IDLE; break; #endif diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 7442fc5..87f8175 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -51,6 +51,10 @@ e-mail anklimov@gmail.com #include "modules/out_multivent.h" #include "modules/out_uartbridge.h" +#ifdef ELEVATOR_ENABLE +#include "modules/out_elevator.h" +#endif + short modbusBusy = 0; bool isPendedModbusWrites = false; @@ -104,7 +108,7 @@ int txt2subItem(char *payload) { else if (strcmp_P(payload, TEMP_P) == 0) cmd = S_TEMP; else if (strcmp_P(payload, VAL_P) == 0) cmd = S_VAL; else if (strcmp_P(payload, DEL_P) == 0) cmd = S_DELAYED; - + else if (strcmp_P(payload, _RAW_P) == 0) cmd = S_RAW; return cmd; } @@ -191,6 +195,13 @@ void Item::Parse() { // debugSerial<name << F(" T:") << itemType << F(" =") << getArg() << endl; @@ -489,6 +500,12 @@ if (subItem && strlen(subItem)) if (!suffixCode && defaultSuffixCode) suffixCode = defaultSuffixCode; +if (suffixCode == S_RAW) +{ itemCmd ic; + ic.Str(payload); + ic.setSuffix(suffixCode); + return Ctrl(ic,subItem); +} int i=0; while (payload[i]) {payload[i]=toupper(payload[i]);i++;}; @@ -848,6 +865,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion) if (chActive>0 && !cmd.getInt()) st.Cmd(CMD_OFF); if (chActive==0 && cmd.getInt()) st.Cmd(CMD_ON); setCmd(st.getCmd()); + st.saveItem(this); SendStatus(SEND_COMMAND | SEND_DEFFERED); // continue processing as SET @@ -913,8 +931,10 @@ if (driver) //New style modular code if (!chActive) //if channel was'nt active before CMD_XON { debugSerial<Ctrl(st.Cmd(CMD_ON), subItem); + st.Cmd(CMD_ON); + res = driver->Ctrl(st, subItem); setCmd(CMD_XON); + st.saveItem(this); SendStatus(SEND_COMMAND); } else @@ -926,8 +946,10 @@ if (driver) //New style modular code case CMD_HALT: if (chActive) //if channel was active before CMD_HALT { - res = driver->Ctrl(st.Cmd(CMD_OFF), subItem); + st.Cmd(CMD_OFF); + res = driver->Ctrl(st, subItem); setCmd(CMD_HALT); + st.saveItem(this); SendStatus(SEND_COMMAND); return res; } @@ -940,8 +962,12 @@ if (driver) //New style modular code case CMD_OFF: if (getCmd() != CMD_HALT) //Halted, ignore OFF { - res = driver->Ctrl(st.Cmd(CMD_OFF), subItem); + //debugSerial<<"OFF! "; + //st.debugOut(); + st.Cmd(CMD_OFF); + res = driver->Ctrl(st, subItem); setCmd(CMD_OFF); + st.saveItem(this); SendStatus(SEND_COMMAND); } else @@ -959,10 +985,15 @@ if (driver) //New style modular code break; case CMD_ON: + //debugSerial<<"ON!"<Ctrl(st, subItem); + st.saveItem(this); if (st.isCommand()) { setCmd(st.getCmd()); @@ -1068,12 +1099,14 @@ switch (itemType) { if (chActive>0) //if channel was active before CMD_HALT { setCmd(CMD_HALT); + cmd.saveItem(this); /// SendStatus(SEND_COMMAND); } } else { setCmd(st.getCmd()); + st.saveItem(this); SendStatus(SEND_COMMAND); } } @@ -1261,7 +1294,7 @@ int Item::SendStatus(int sendFlags) { char addrstr[48]; char valstr[20] = ""; char cmdstr[8] = ""; - + st.debugOut(); if (sendFlags & SEND_COMMAND) { // Preparing Command payload ////////////// @@ -1287,6 +1320,8 @@ int Item::SendStatus(int sendFlags) { sendFlags &= ~SEND_COMMAND; } } + + //debugSerial<<"C"<getVal(); cmd.itemArgType= subtype; if (includeCommand) cmd.cmdCode=item->getCmd(); - //debugSerial<itemVal->type) { case aJson_Int: + Int((int32_t)item->itemVal->valueint); + debugSerial<itemVal->valueint); + debugSerial< #endif +#ifdef MDNS_ENABLE + #ifndef WIFI_ENABLE + EthernetUDP mdnsUDP; + #else + WiFiUDP mdnsUDP; + #endif +MDNS mdns(mdnsUDP); +#endif + +/* #if defined(__SAM3X8E__) DueFlashStorage EEPROM; #endif + #ifdef ARDUINO_ARCH_ESP32 NRFFlashStorage EEPROM; #endif @@ -99,6 +130,7 @@ NRFFlashStorage EEPROM; #ifdef NRF5 NRFFlashStorage EEPROM; #endif +*/ #ifdef SYSLOG_ENABLE #include @@ -109,7 +141,7 @@ NRFFlashStorage EEPROM; WiFiUDP udpSyslogClient; #endif Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_BSD); -unsigned long timerSyslogPingTime; +//unsigned long timerSyslogPingTime; static char syslogDeviceHostname[16]; Streamlog debugSerial(&debugSerialPort,LOG_DEBUG,&udpSyslog); @@ -175,7 +207,7 @@ int8_t configLocked = 0; ModbusMaster node; #endif -byte mac[6]; +//byte mac[6]; PubSubClient mqttClient(ethClient); @@ -350,15 +382,12 @@ else void printMACAddress() { + //macAddress * mac = sysConf.getMAC(); infoSerial<type == aJson_String) return element->valuestring; } #ifdef OTA - #if (defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)) + // #if (defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)) void setupOTA(void) { - ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage); + ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage, sysConfStream, JSONStream); ArduinoOTA.setCustomHandler(httpHandler); infoSerial<type == aJson_String) return element->valuestring; } #else - InternalStorageClass flashStorage(EEPROM_offsetJSON); + //InternalStorageClass flashStorage(EEPROM_offsetJSON); void setupOTA(void) { - ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", flashStorage); + ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage); ArduinoOTA.setCustomHandler(httpHandler); infoSerial<= 3) port = aJson.getArrayItem(mqttArr, 2)->valueint; if (n >= 4) user = getStringFromConfig(mqttArr, 3); - if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) + //if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) + if (!sysConf.getMQTTpwd(passwordBuf, sizeof(passwordBuf)) && (n >= 5)) { password = getStringFromConfig(mqttArr, 4); infoSerial<4 && _inet_aton(args[4], ip)) saveFlash(OFFSET_MASK, ip); - else saveFlash(OFFSET_MASK, ip0); + if (arg_cnt>4 && _inet_aton(args[4], ip)) sysConf.setMask(ip); + else sysConf.setMask(ip0); // case 4: - if (arg_cnt>3 && _inet_aton(args[3], ip)) saveFlash(OFFSET_GW, ip); - else saveFlash(OFFSET_GW, ip0); + if (arg_cnt>3 && _inet_aton(args[3], ip)) sysConf.setGW(ip); + else sysConf.setGW(ip0); // case 3: - if (arg_cnt>2 && _inet_aton(args[2], ip)) saveFlash(OFFSET_DNS, ip); - else saveFlash(OFFSET_DNS, ip0); + if (arg_cnt>2 && _inet_aton(args[2], ip)) sysConf.setDNS(ip); + else sysConf.setDNS(ip0); // case 2: - if (arg_cnt>1 && _inet_aton(args[1], ip)) saveFlash(OFFSET_IP, ip); - else saveFlash(OFFSET_IP, ip0); + if (arg_cnt>1 && _inet_aton(args[1], ip)) sysConf.setIP(ip); + else sysConf.setIP(ip0); // break; // case 1: //dynamic IP if (arg_cnt==1) { - saveFlash(OFFSET_IP,ip0); + sysConf.setIP(ip0); infoSerial<MAXFLASHSTR-1) len=MAXFLASHSTR-1; - for(int i=0;i 1) { strncpy(configServer, args[1], sizeof(configServer) - 1); - saveFlash(OFFSET_CONFIGSERVER, configServer); + sysConf.setServer(configServer); + //saveFlash(OFFSET_CONFIGSERVER, configServer); infoSerial< 0) { infoSerial.printf("[HTTP] GET... code: %d\n", httpResponseCode); @@ -1609,6 +1660,7 @@ void postTransmission() { } void setup_main() { + #if defined(__SAM3X8E__) memset(&UniqueID,0,sizeof(UniqueID)); #endif @@ -1622,23 +1674,42 @@ void setup_main() { printFirmwareVersionAndBuildOptions(); //Checkin EEPROM integrity (signature) - for (int i=0;i +//#include #include #include #endif @@ -16,13 +16,13 @@ #include "HTTPClientAVR.h" #include #include -#include +//#include #endif #if defined(ARDUINO_ARCH_ESP8266) #include //this needs to be first, or it all crashes and burns... //#include "SPIFFS.h" -#include +//#include //#include //#include //#include "HttpClient.h" @@ -38,7 +38,7 @@ #include //this needs to be first, or it all crashes and burns... //#include "SPIFFS.h" //#include -#include +//#include //#include "HttpClient.h" //#include //#include @@ -53,14 +53,14 @@ #endif #ifdef NRF5 -#include +//#include #include #endif #ifdef ARDUINO_ARCH_STM32 #include "HttpClient.h" //#include "UIPEthernet.h" -#include +//#include //#include #endif @@ -178,6 +178,10 @@ extern Streamlog errorSerial; #include "sd_card_w5100.h" #endif +#ifdef MDNS_ENABLE +#include +#endif + #include "Arduino.h" #include "utils.h" #include "textconst.h" @@ -243,11 +247,11 @@ void cmdFunctionLoad(int arg_cnt, char **args); int loadConfigFromEEPROM(); -void cmdFunctionReq(int arg_cnt, char **args); +//void cmdFunctionReq(int arg_cnt, char **args); -int mqttConfigRequest(int arg_cnt, char **args); +//int mqttConfigRequest(int arg_cnt, char **args); -int mqttConfigResp(char *as); +//int mqttConfigResp(char *as); void cmdFunctionSave(int arg_cnt, char **args); @@ -256,7 +260,7 @@ void cmdFunctionSetMac(int arg_cnt, char **args); void cmdFunctionGet(int arg_cnt, char **args); void printBool(bool arg); - +/* void saveFlash(short n, char *str); int loadFlash(short n, char *str, short l=MAXFLASHSTR); @@ -264,6 +268,7 @@ int loadFlash(short n, char *str, short l=MAXFLASHSTR); void saveFlash(short n, IPAddress& ip); int ipLoadFromFlash(short n, IPAddress &ip); +*/ lan_status loadConfigFromHttp(int arg_cnt = 0, char **args = NULL); diff --git a/lighthub/modules/out_uartbridge.cpp b/lighthub/modules/out_uartbridge.cpp index 78a7230..05b0b9e 100644 --- a/lighthub/modules/out_uartbridge.cpp +++ b/lighthub/modules/out_uartbridge.cpp @@ -25,6 +25,7 @@ WiFiUDP udpClientB; IPAddress targetIP; uint16_t targetPort=5555; +int loglev=0; short halfduplex=1; bool udpdump=false; @@ -32,6 +33,10 @@ uint32_t timerA = 0; uint32_t timerB = 0; uint16_t sizeA = 0; uint16_t sizeB = 0; +char * PDUbondaries = NULL; + +char bufA[MAX_PDU]; +char bufB[MAX_PDU]; //extern aJsonObject *modbusObj; //extern ModbusMaster node; @@ -73,6 +78,9 @@ bool out_UARTbridge::getConfig() aJsonObject * debugIPObj=aJson.getObjectItem(item->itemArg, "ip"); aJsonObject * debugPortObj=aJson.getObjectItem(item->itemArg, "port"); aJsonObject * hdObj=aJson.getObjectItem(item->itemArg, "hd"); + aJsonObject * logObj=aJson.getObjectItem(item->itemArg, "log"); + aJsonObject * bondObj=aJson.getObjectItem(item->itemArg, "bond"); + if (debugIPObj) { @@ -86,6 +94,8 @@ bool out_UARTbridge::getConfig() if (debugPortObj) targetPort = debugPortObj->valueint; if (hdObj) halfduplex = hdObj->valueint; + if (logObj) loglev = logObj->valueint; + if (bondObj) PDUbondaries = bondObj->valuestring; return true; } @@ -105,6 +115,8 @@ if (!store) sizeB=0; timerA=0; timerB=0; + bufA[0]=0; + bufB[0]=0; if (getConfig()) { @@ -141,15 +153,88 @@ if (store) return CST_UNKNOWN; } +String _RR_A; +String _WR_A; +String _RR_B; +String _WR_B; + + void strcat_c (char *str, char c, int len) + { + char strn[]="-"; + strn[0]=c; + ///str[1]=0; + strncat(str,strn,len); + /* + return; + int i; + for (i=0;*str && (i=HAVE_IP_ADDRESS && udpdump) udpClientA.endPacket(); - debugSerial<=HAVE_IP_ADDRESS && udpdump) udpClientB.endPacket(); - debugSerial<"); + short i=0; + while (curStr[i] && i=HAVE_IP_ADDRESS && udpdump) {udpClientA.write(chA);} sizeA++; } @@ -199,14 +321,14 @@ int out_UARTbridge::Poll(short cause) ////if (timerA) return 1; chB=MODULE_UATRBRIDGE_UARTB.read(); MODULE_UATRBRIDGE_UARTA.write(chB); - debugSerial<")<<((chB<16)?"0":"")<<_HEX(chB); + logB(chB); if (lanStatus>=HAVE_IP_ADDRESS && udpdump) {udpClientB.write(chB);}; sizeB++; } } -if ((timerA && (isTimeOver(timerA,millis(),PDELAY)) || sizeA>=MAX_PDU)) flushA(); -if ((timerB && (isTimeOver(timerB,millis(),PDELAY)) || sizeB>=MAX_PDU)) flushB(); +if ((timerA && (isTimeOver(timerA,millis(),PDELAY)) || (chA=='*') || (chA=='\r') || sizeA>=MAX_PDU)) flushA(); +if ((timerB && (isTimeOver(timerB,millis(),PDELAY)) || (chB=='*') || (chB=='\r') || sizeB>=MAX_PDU)) flushB(); /* diff --git a/lighthub/modules/out_uartbridge.h b/lighthub/modules/out_uartbridge.h index 2144ae1..df403a4 100644 --- a/lighthub/modules/out_uartbridge.h +++ b/lighthub/modules/out_uartbridge.h @@ -14,7 +14,7 @@ #define SOURCE_PORT_A 5551 #define SOURCE_PORT_B 5552 -#define MAX_PDU 1024 +#define MAX_PDU 64 #ifndef MODULE_UATRBRIDGE_UARTA #define MODULE_UATRBRIDGE_UARTA Serial1 @@ -54,7 +54,7 @@ public: //aJsonObject * parameters; }; -#define PDELAY 50 +#define PDELAY 10 class out_UARTbridge : public abstractOut { public: diff --git a/lighthub/options.h b/lighthub/options.h index 1646459..db86dda 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -1,4 +1,19 @@ #include + +#ifndef MAX_JSON_CONF_SIZE + +#if defined(__SAM3X8E__) +#define MAX_JSON_CONF_SIZE 16000 +#elif defined(ARDUINO_ARCH_AVR) +#define MAX_JSON_CONF_SIZE 4096 +#elif defined(ARDUINO_ARCH_ESP32) +#define MAX_JSON_CONF_SIZE 65535 +#else +#define MAX_JSON_CONF_SIZE 32000 +#endif + +#endif + // Configuration of drivers enabled #define SYSLOG_LOCAL_SOCKET 514 @@ -39,7 +54,7 @@ #define TXEnablePin MODBUS_TX_PIN #endif -#define ESP_EEPROM_SIZE 2048 +//#define ESP_EEPROM_SIZE 2048 #ifndef AVR_DMXOUT_PIN #define AVR_DMXOUT_PIN 18 @@ -63,6 +78,7 @@ #define MIN_VOLUME 25 #define INIT_VOLUME 40 +/* #define MAXFLASHSTR 32 #define PWDFLASHSTR 16 #define EEPROM_SIGNATURE "LHCF" @@ -80,7 +96,7 @@ #define EEPROM_offsetJSON EEPROM_offset_NotAlligned + (4 -(EEPROM_offset_NotAlligned & 3)) //#define EEPROM_offsetJSON IFLASH_PAGE_SIZE #define EEPROM_FIX_PART_LEN EEPROM_offsetJSON-OFFSET_MAC - +*/ #ifndef INTERVAL_CHECK_INPUT #define INTERVAL_CHECK_INPUT 15 diff --git a/lighthub/streamlog.h b/lighthub/streamlog.h index bd64392..58dbe70 100644 --- a/lighthub/streamlog.h +++ b/lighthub/streamlog.h @@ -1,3 +1,4 @@ +#pragma once #include #include #include diff --git a/lighthub/textconst.h b/lighthub/textconst.h index 84fb31f..e18a43d 100644 --- a/lighthub/textconst.h +++ b/lighthub/textconst.h @@ -116,9 +116,10 @@ const char HSV_P[] PROGMEM = "HSV"; const char RGB_P[] PROGMEM = "RGB"; const char VAL_P[] PROGMEM = "val"; const char DEL_P[] PROGMEM = "del"; +const char _RAW_P[] PROGMEM = "raw"; /* const char RPM_P[] PROGMEM = "rpm"; const char STATE_P[] PROGMEM = "state"; */ -const char EEPROM_signature[] = EEPROM_SIGNATURE; + diff --git a/platformio.ini b/platformio.ini index 69ea301..f11790a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,7 +20,7 @@ default_envs = ; Another Arduino Mega compact build without 1-wire, DMX, but with OTA ; OPTIBOOT bootloader required! https://github.com/MCUdude/MegaCore ; universal Wiznet network driver -; mega2560slim2 +; mega2560slim2 ; Arduino Mega + Ethernet shield Wiznet 5100 ; mega2560-5100 @@ -54,12 +54,12 @@ default_envs = ; STM32 board + ENC28j60 network ; stm32-enc2860 -; NRF52 board + Wiznet 5500 network -; nrf52840-5500 +; NRF52 board + Wiznet 5x00 network +; nrf52840 ;build_dir = /tmp/pioenvs ;libdeps_dir = /tmp/piolibdeps -[env:nrf52840-5500] +[env:nrf52840] platform = nordicnrf52 board = nrf52840_dk monitor_baud = 115200 @@ -67,7 +67,7 @@ monitor_baud = 115200 ;upload_protocol = mbed ;upload_port = /dev/cu.SLAB_USBtoUART framework = arduino -build_flags = !python get_build_flags.py nrf52840-5500 +build_flags = !python get_build_flags.py nrf52840 lib_ignore = ;DS2482_OneWire //UNCOMMENT for software 1-wire driver ESP_EEPROM @@ -78,7 +78,7 @@ lib_ignore = SD SdFat WifiManager - Ethernet + Ethernet2 Ethernet3 Ethernet5100 httpClient @@ -99,7 +99,7 @@ lib_ignore = lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire - https://github.com/anklimov/Ethernet2 + https://github.com/anklimov/Ethernet ArduinoHttpClient https://github.com/anklimov/aJson https://github.com/anklimov/CmdArduino @@ -113,9 +113,11 @@ lib_deps = https://github.com/anklimov/NRFFlashStorage https://github.com/adafruit/Adafruit_NeoPixel.git https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO https://github.com/arcao/Syslog.git br3ttb/PID@^1.2.1 + ;ArduinoMDNS monitor_speed = 115200 [env:m5stack] @@ -153,7 +155,7 @@ lib_deps = https://github.com/knolleary/pubsubclient.git Streaming ;ESP_EEPROM - https://github.com/anklimov/NRFFlashStorage + ;https://github.com/anklimov/NRFFlashStorage Adafruit Unified Sensor DHT sensor library for ESPx https://github.com/anklimov/Artnet.git @@ -168,9 +170,11 @@ lib_deps = M5Stack Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO https://github.com/arcao/Syslog.git br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 [env:esp32-wifi] @@ -182,8 +186,8 @@ board = esp32-evb monitor_baud = 115200 ;upload_speed = 115200 ;upload_command = arduinoOTA -address 192.168.88.60 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE;sleep 5 -upload_command = arduinoOTA -address 192.168.11.230 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE;sleep 5 -upload_protocol = custom +;upload_command = arduinoOTA -address 192.168.11.230 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE;sleep 5 +;upload_protocol = custom build_flags = !python get_build_flags.py esp32-wifi lib_ignore = @@ -215,7 +219,7 @@ lib_deps = https://github.com/knolleary/pubsubclient.git Streaming ;ESP_EEPROM - https://github.com/anklimov/NRFFlashStorage + ;https://github.com/anklimov/NRFFlashStorage Adafruit Unified Sensor DHT sensor library for ESPx https://github.com/anklimov/Artnet.git @@ -228,9 +232,11 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO https://github.com/arcao/Syslog.git br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 @@ -280,8 +286,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 [env:due] @@ -338,8 +346,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 [env:mega2560slim-5100] @@ -384,8 +394,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 @@ -403,7 +415,10 @@ board_build.f_cpu = 16000000L ; Comment out to enable LTO (this line unflags it) ;build_unflags = -flto - not working without LTO! -upload_protocol = arduino +;upload_protocol = arduino +upload_command = arduinoOTA -address 192.168.11.213 -port 65280 -username arduino -password password -b -upload /sketch -sketch $BUILD_DIR/${PROGNAME}.bin;sleep 5 +upload_protocol = custom + board_upload.speed = ${env:fuses_bootloader.board_bootloader.speed} framework = arduino build_flags = !python get_build_flags.py mega2560slim2 @@ -444,8 +459,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 @@ -491,8 +508,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 [env:esp8266-wifi] @@ -554,8 +573,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA.git - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ;ArduinoMDNS monitor_speed = 115200 [env:mega2560-5100] @@ -602,8 +623,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 [env:due-5500] @@ -653,8 +676,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 [env:lighthub21] @@ -663,8 +688,8 @@ framework = arduino board = due monitor_baud = 115200 build_flags = !python get_build_flags.py lighthub21 -;upload_command = arduinoOTA -address 192.168.11.172 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE ;sleep 4 -;upload_command = arduinoOTA -address 192.168.88.45 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE;sleep 4 +;upload_command = arduinoOTA -address 192.168.11.172 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE ;sleep 6 +;upload_command = arduinoOTA -address 192.168.88.45 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE;sleep 6 ;upload_protocol = custom lib_ignore = ;DS2482_OneWire //UNCOMMENT for software 1-wire driver @@ -708,8 +733,10 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 [env:controllino] @@ -754,9 +781,11 @@ lib_deps = SparkFun CCS811 Arduino Library@~1.0.7 Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO https://github.com/arcao/Syslog.git br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 [env:stm32-enc2860] @@ -807,9 +836,11 @@ lib_deps = UIPEthernet https://github.com/anklimov/NRFFlashStorage Adafruit NeoPixel - https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library + Adafruit MCP23017 Arduino Library + Adafruit BusIO SPI br3ttb/PID@^1.2.1 + ArduinoMDNS monitor_speed = 115200 ; Run the following command to upload with this environment