From 5e06c822cd07a4ffa250247e413b98f755c4af31 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 4 Oct 2018 21:40:55 +0300 Subject: [PATCH 01/13] from IS-STM32Duino --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index 4f3fe38..b33dc6f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -174,6 +174,7 @@ framework = arduino board = due ;lib_ldf_mode = chain+ build_flags = -D Wiz5500 -D ARTNET_ENABLE +build_flags = !sh build_flags_due-5500.sh lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git From ebc7c57fd692035bdc735fd4296d61db45475c26 Mon Sep 17 00:00:00 2001 From: livello Date: Mon, 8 Oct 2018 00:48:56 +0300 Subject: [PATCH 02/13] refactoring --- lighthub/main.cpp | 57 +++++++++++++++++------------------------------ lighthub/main.h | 2 +- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 5d3fafe..03e3122 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -153,23 +153,15 @@ bool wifiInitialized; int mqttErrorRate; -void watchdogSetup(void) { -//Serial.begin(115200); -//debugSerial.println("Watchdog armed."); -} //Do not remove - strong re-definition WDT Init for DUE - - -// MQTT Callback routine - +void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE void mqttCallback(char *topic, byte *payload, unsigned int length) { - debugSerial.print(F("\n[")); debugSerial.print(topic); debugSerial.print(F("] ")); if (!payload) return; - payload[length] = 0; + payload[length] = 0; int fr = freeRam(); if (fr < 250) { debugSerial.println(F("OOM!")); @@ -186,17 +178,15 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) { return; } - boolean retaining = (lanStatus == RETAINING_COLLECTING); //Check if topic = Command topic short intopic = 0; { char buf[MQTT_TOPIC_LENGTH + 1]; strncpy_P(buf, inprefix, sizeof(buf)); - intopic = strncmp(topic, buf, strlen(inprefix)); } // in Retaining status - trying to restore previous state from retained output topic. Retained input topics are not relevant. - if (retaining && !intopic) { + if ((lanStatus == RETAINING_COLLECTING) && !intopic) { debugSerial.println(F("Skipping..")); return; } @@ -208,9 +198,9 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) { strncpy(subtopic, t + 1, MQTT_SUBJECT_LENGTH - 1); Item item(subtopic); if (item.isValid()) { - if (item.itemType == CH_GROUP && retaining) + if (item.itemType == CH_GROUP && (lanStatus == RETAINING_COLLECTING)) return; //Do not restore group channels - they consist not relevant data - item.Ctrl((char *)payload, !retaining); + item.Ctrl((char *)payload, !(lanStatus == RETAINING_COLLECTING)); } //valid item } @@ -249,7 +239,7 @@ lan_status lanLoop() { case HAVE_IP_ADDRESS: if (!configOk) - lanStatus = getConfig(0, NULL); //got config from server or load from NVRAM + lanStatus = loadConfigFromHttp(0, NULL); else lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER; #ifdef _artnet if (artnet) artnet->begin(); @@ -621,12 +611,22 @@ void Changed(int i, DeviceAddress addr, int val) { #endif //_owire void cmdFunctionHelp(int arg_cnt, char **args) -//(char* tokens) { printFirmwareVersionAndBuildOptions(); #ifndef SYSLOG_DISABLE // udpSyslog.logf(LOG_INFO, "free RAM: %d",freeRam()); #endif + + + debugSerial.print(F("Current LAN config(ip,dns,gw,subnet):")); + printIPAddress(Ethernet.localIP()); + debugSerial.print(F(" ,")); + printIPAddress(Ethernet.dnsServerIP()); + debugSerial.print(F(" ,")); + printIPAddress(Ethernet.gatewayIP()); + debugSerial.print(F(" ,")); + printIPAddress(Ethernet.subnetMask()); + debugSerial.println(F(";")); debugSerial.print(F(" free RAM: "));debugSerial.print(freeRam()); debugSerial.println(F(" Use the commands: 'help' - this text\n" "'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n" @@ -756,7 +756,6 @@ void cmdFunctionLoad(int arg_cnt, char **args) { } int loadConfigFromEEPROM(int arg_cnt, char **args) -//(char* tokens) { char ch; debugSerial.println(F("loading Config")); @@ -778,7 +777,6 @@ int loadConfigFromEEPROM(int arg_cnt, char **args) } else { debugSerial.println(F("No stored config")); return 0; - } } @@ -789,7 +787,6 @@ void cmdFunctionReq(int arg_cnt, char **args) { int mqttConfigRequest(int arg_cnt, char **args) -//(char* tokens) { char buf[25] = "/"; debugSerial.println(F("request MQTT Config")); @@ -802,16 +799,11 @@ int mqttConfigRequest(int arg_cnt, char **args) strncat(buf, "/req/conf", 25); debugSerial.println(buf); mqttClient.publish(buf, "1"); - } int mqttConfigResp(char *as) { debugSerial.println(F("got MQTT Config")); - - //aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset); - - //aJson.deleteItem(root); root = aJson.parse(as); debugSerial.println(); if (!root) { @@ -824,7 +816,6 @@ int mqttConfigResp(char *as) { } void cmdFunctionSave(int arg_cnt, char **args) -//(char* tokens) { aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offset); debugSerial.println(F("Saving config to EEPROM..")); @@ -834,7 +825,6 @@ void cmdFunctionSave(int arg_cnt, char **args) } void cmdFunctionIp(int arg_cnt, char **args) -//(char* tokens) { IPAddress ip0(0, 0, 0, 0); IPAddress ip; @@ -913,7 +903,7 @@ void cmdFunctionSetMac(int arg_cnt, char **args) { } void cmdFunctionGet(int arg_cnt, char **args) { - lanStatus=getConfig(arg_cnt, args); + lanStatus= loadConfigFromHttp(arg_cnt, args); ethClient.stop(); //Refresh MQTT connect to get retained info //restoreState(); } @@ -948,7 +938,7 @@ int ipLoadFromFlash(short n, IPAddress &ip) { return 0; } -lan_status getConfig(int arg_cnt, char **args) +lan_status loadConfigFromHttp(int arg_cnt, char **args) { int responseStatusCode = 0; char ch; @@ -1287,7 +1277,7 @@ void setupCmdArduino() { void loop_main() { wdt_res(); cmdPoll(); - if (lanLoop() > 1) { + if (lanLoop() > HAVE_IP_ADDRESS) { mqttClient.loop(); #ifdef _artnet if (artnet) artnet->read(); @@ -1302,7 +1292,6 @@ void loop_main() { // unsigned long lastpacket = DMXSerial.noDataSince(); DMXCheck(); #endif - // if (lastpacket && (lastpacket%10==0)) debugSerial.println(lastpacket); if (items) { #ifndef MODBUS_DISABLE @@ -1333,10 +1322,7 @@ void owIdle(void) { #endif wdt_res(); - return; //TODO: unreached code - debugSerial.print(F("o")); - if (lanLoop() == 1) mqttClient.loop(); -//if (owReady) owLoop(); + return; #ifdef _dmxin DMXCheck(); @@ -1349,7 +1335,6 @@ void owIdle(void) { void ethernetIdle(void){ wdt_res(); inputLoop(); -// debugSerial.print("."); }; void modbusIdle(void) { diff --git a/lighthub/main.h b/lighthub/main.h index 5e4f782..7d28b34 100644 --- a/lighthub/main.h +++ b/lighthub/main.h @@ -196,7 +196,7 @@ void saveFlash(short n, IPAddress& ip); int ipLoadFromFlash(short n, IPAddress &ip); -lan_status getConfig(int arg_cnt=0, char **args=NULL); +lan_status loadConfigFromHttp(int arg_cnt = 0, char **args = NULL); void preTransmission(); From b83badcff80dddb5f3449734c53f3f9fc6fa6ebc Mon Sep 17 00:00:00 2001 From: livello Date: Mon, 8 Oct 2018 18:23:10 +0300 Subject: [PATCH 03/13] refactoring --- lighthub/main.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 03e3122..e32272f 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -178,7 +178,6 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) { return; } - //Check if topic = Command topic short intopic = 0; { char buf[MQTT_TOPIC_LENGTH + 1]; @@ -1063,9 +1062,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args) httpClient.begin(fullURI); int httpResponseCode = httpClient.GET(); if (httpResponseCode > 0) { - // HTTP header has been send and Server response header has been handled debugSerial.printf("[HTTP] GET... code: %d\n", httpResponseCode); - // file found at server if (httpResponseCode == HTTP_CODE_OK) { String response = httpClient.getString(); debugSerial.println(response); @@ -1073,7 +1070,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args) root = aJson.parse((char *) response.c_str()); if (!root) { debugSerial.println(F("Config parsing failed")); - return READ_RE_CONFIG;//-11; //Load from NVRAM + return READ_RE_CONFIG; } else { debugSerial.println(F("Config OK, Applying")); applyConfig(); @@ -1082,12 +1079,12 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args) } else { debugSerial.printf("[HTTP] GET... failed, error: %s\n", httpClient.errorToString(httpResponseCode).c_str()); httpClient.end(); - return READ_RE_CONFIG;//-11; //Load from NVRAM + return READ_RE_CONFIG; } httpClient.end(); #endif - return IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;//2; + return IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER; } void preTransmission() { From 698c2a653a08630c8bf21e86a81413c0e74f920d Mon Sep 17 00:00:00 2001 From: livello Date: Tue, 9 Oct 2018 01:27:56 +0300 Subject: [PATCH 04/13] PrintEx --- lighthub/main.cpp | 385 ++++++++++++++++++++-------------------------- lighthub/main.h | 8 +- platformio.ini | 10 +- 3 files changed, 181 insertions(+), 222 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index e32272f..3633000 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -67,6 +67,8 @@ PWM Out #include "Arduino.h" #include "main.h" #include "options.h" +//#include "Streaming.h" +#include "PrintEx.h" #if defined(__SAM3X8E__) DueFlashStorage EEPROM; @@ -156,22 +158,19 @@ int mqttErrorRate; void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE void mqttCallback(char *topic, byte *payload, unsigned int length) { - debugSerial.print(F("\n[")); - debugSerial.print(topic); - debugSerial.print(F("] ")); + debugSerial< 0) switch (Ethernet.maintain()) { case NO_LINK: - debugSerial.println(F("No link")); + debugSerial<valuestring; int syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint; char *syslogDeviceHostname = aJson.getArrayItem(udpSyslogArr, 2)->valuestring; char *syslogAppname = aJson.getArrayItem(udpSyslogArr, 3)->valuestring; - debugSerial.println("debugSerial:"); - debugSerial.println(syslogServer); - debugSerial.println(syslogPort); - debugSerial.println(syslogDeviceHostname); - debugSerial.println(syslogAppname); + debugSerial<= 4) user = aJson.getArrayItem(mqttArr, 3)->valuestring; if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) { password = aJson.getArrayItem(mqttArr, 4)->valuestring; - debugSerial.println(F("Using MQTT password from config")); + debugSerial<50){ - debugSerial.print(F("Too many MQTT connection errors. Restart LAN")); + debugSerial< 0) { delay(500); wifi_connection_wait -= 500; - debugSerial.print("."); + debugSerial<<"."); } wifiInitialized = true; } @@ -471,12 +454,12 @@ void onInitialStateInitLAN() { #if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266) if (WiFi.status() == WL_CONNECTED) { - debugSerial.print(F("WiFi connected. IP address: ")); - debugSerial.println(WiFi.localIP()); + debugSerial<valuestring; if (owEmit) { strncpy(addrbuf, owEmit, sizeof(addrbuf)); - debugSerial.print(owEmit); - debugSerial.print(F("=")); - debugSerial.println(val); + debugSerial<valuestring; - } else debugSerial.println(F("1w-item not found in config")); + } else debugSerial<=1 ) { DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, 1)->valueint); - //,aJson.getArrayItem(dmxoutArr, 0)->valueint); - debugSerial.print(F("DMX out started. Channels: ")); - debugSerial.println(maxChannels); + debugSerial<child; owReady = owSetup(&Changed); - if (owReady) debugSerial.println(F("One wire Ready")); + if (owReady) debugSerial<type == aJson_Object)) { DeviceAddress addr; - //debugSerial.print(F("Add:")),debugSerial.println(item->name); + //debugSerial<name); SetAddr(item->name, addr); owAdd(addr); } @@ -715,10 +695,7 @@ void applyConfig() { int k; pinMode(pin, OUTPUT); digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW)); - debugSerial.print(F("Pin:")); - debugSerial.print(pin); - debugSerial.print(F("=")); - debugSerial.println(k); + debugSerial<>>")); + debugSerial<<(F(">>>")); cmdAdd("help", cmdFunctionHelp); cmdAdd("save", cmdFunctionSave); cmdAdd("load", cmdFunctionLoad); @@ -1307,7 +1268,7 @@ void loop_main() { #endif #ifndef SYSLOG_DISABLE -// debugSerial.print(F("#")); +// debugSerial<valueint; if (!aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint) { - debugSerial.print(thermoItem->name); - debugSerial.println(F(" Expired")); + debugSerial<name<valueint)) @@ -1427,27 +1387,22 @@ void thermoLoop(void) { if (curTemp > THERMO_OVERHEAT_CELSIUS) mqttClient.publish("/alarm/ovrht", thermoItem->name); - debugSerial.print(thermoItem->name); - debugSerial.print(F(" Set:")); - debugSerial.print(thermoSetting); - debugSerial.print(F(" Cur:")); - debugSerial.print(curTemp); - debugSerial.print(F(" cmd:")); - debugSerial.print(thermoStateCommand); + debugSerial << ios::endl << thermoItem->name << F("Set:") << thermoSetting << F(" Cur:") << curTemp + << F(" cmd:") << thermoStateCommand; pinMode(thermoPin, OUTPUT); if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) { digitalWrite(thermoPin, LOW); - debugSerial.println(F(" OFF")); + debugSerial<= thermoSetting) { digitalWrite(thermoPin, LOW); - debugSerial.println(F(" OFF")); + debugSerial< Date: Tue, 9 Oct 2018 10:00:19 +0300 Subject: [PATCH 05/13] PrintEx --- lighthub/main.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 3633000..f5bf988 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -109,7 +109,6 @@ EthernetClient ethClient; #endif #ifndef SYSLOG_DISABLE -//#include #include EthernetUDP udpSyslogClient; Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_IETF); @@ -493,7 +492,7 @@ void onInitialStateInitLAN() { lanStatus = HAVE_IP_ADDRESS; } else { - debugSerial<<"No IP data found in flash"; + debugSerial<<"\nNo IP data found in flash"; wdt_dis(); #if defined(__AVR__) || defined(__SAM3X8E__) res = Ethernet.begin(mac, 12000); @@ -1412,8 +1411,8 @@ void thermoLoop(void) { nextThermostatCheck = millis() + THERMOSTAT_CHECK_PERIOD; #ifndef DISABLE_FREERAM_PRINT - (thermostatCheckPrinted) ? debugSerial< Date: Tue, 9 Oct 2018 10:01:58 +0300 Subject: [PATCH 06/13] PrintEx --- lighthub/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index f5bf988..b8df546 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -1412,8 +1412,7 @@ void thermoLoop(void) { #ifndef DISABLE_FREERAM_PRINT (thermostatCheckPrinted) ? debugSerial< Date: Tue, 9 Oct 2018 11:11:00 +0300 Subject: [PATCH 07/13] PrintEx --- lighthub/main.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index b8df546..6acf0ff 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -1125,12 +1125,12 @@ void setup_main() { void printFirmwareVersionAndBuildOptions() { debugSerial<valueint == 0) mqttClient.publish("/alarmoff/snsr", thermoItem->name); att->valueint = (int) T_ATTEMPTS; } - } } - } From 5d64a72ea0f125b4785575870ef7a7fd577ab327 Mon Sep 17 00:00:00 2001 From: livello Date: Wed, 10 Oct 2018 13:49:28 +0300 Subject: [PATCH 08/13] printex --- lighthub/main.cpp | 14 +++++++------- platformio.ini | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 6acf0ff..7d28128 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -453,12 +453,12 @@ void onInitialStateInitLAN() { #if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266) if (WiFi.status() == WL_CONNECTED) { - debugSerial< Date: Wed, 10 Oct 2018 13:53:45 +0300 Subject: [PATCH 09/13] printex --- lighthub/main.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 7d28128..101c198 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -421,10 +421,7 @@ void onInitialStateInitLAN() { #if defined(ESP8266) and defined(WIFI_MANAGER_DISABLE) if(!wifiInitialized) { WiFi.mode(WIFI_STA); - debugSerial< Date: Wed, 10 Oct 2018 14:24:18 +0300 Subject: [PATCH 10/13] printex streaming --- lighthub/main.cpp | 32 ++++++++++++++++++++------------ lighthub/options.h | 4 +++- platformio.ini | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 101c198..0ebdc85 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -67,8 +67,13 @@ PWM Out #include "Arduino.h" #include "main.h" #include "options.h" -//#include "Streaming.h" +#ifdef WITH_STREAMING_LIB +#include "Streaming.h" +#else #include "PrintEx.h" +using namespace ios; +#endif + #if defined(__SAM3X8E__) DueFlashStorage EEPROM; @@ -79,7 +84,7 @@ EthernetClient ethClient; EthernetClient ethClient; #endif -#ifdef ESP8266 +#ifdef ARDUINO_ARCH_ESP8266 #include #include WiFiClient ethClient; @@ -169,7 +174,7 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) { for (int i = 0; i < length; i++) debugSerial<<((char) payload[i]); - debugSerial< THERMO_OVERHEAT_CELSIUS) mqttClient.publish("/alarm/ovrht", thermoItem->name); - debugSerial << ios::endl << thermoItem->name << F("Set:") << thermoSetting << F(" Cur:") << curTemp + debugSerial << endl << thermoItem->name << F("Set:") << thermoSetting << F(" Cur:") << curTemp << F(" cmd:") << thermoStateCommand; pinMode(thermoPin, OUTPUT); if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) { diff --git a/lighthub/options.h b/lighthub/options.h index 00a9fcc..b991274 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -112,9 +112,11 @@ #define dmxin DmxDue1 #endif -#if defined(ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) #undef _dmxin #undef _modbus +#define WITH_STREAMING_LIB + #ifndef DMX_DISABLE #define _espdmx #endif diff --git a/platformio.ini b/platformio.ini index afbcc20..01596bd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -146,6 +146,7 @@ lib_deps = WifiManager https://github.com/arcao/Syslog.git https://github.com/livello/PrintEx.git#is-select-redecl + Streaming [env:megaatmega2560-net] platform = atmelavr From 39f655ff78b0a1285e06319a1c535c3d0ef97179 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 11 Oct 2018 00:43:09 +0300 Subject: [PATCH 11/13] log, some small fixes --- README.md | 6 ++++ build_flags_template.sh | 2 ++ lighthub/main.cpp | 71 +++++++++++++++++++---------------------- lighthub/main.h | 4 ++- lighthub/owTerm.cpp | 54 +++++++++++++++---------------- lighthub/utils.cpp | 57 +++++++++++++++++++++++++++++++++ lighthub/utils.h | 5 +-- 7 files changed, 131 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index d7b3606..540a153 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,9 @@ platformio device monitor -b 115200 * WIFI_MANAGER_DISABLE //Disable wifi manager for esp8266 * DHT_DISABLE //disable DHT Input support * RESTART_LAN_ON_MQTT_ERRORS //reinit LAN if many mqtt errors occured +* WITH_STREAMING_LIB use streaming libriary for serial debug output otherwise use PrintEx library +* DEVICE_NAME short handy device name which is used instead of mac for download config http://{MY_CONFIG_SERVER}/{DEVICE_NAME}_config.json +* SYSLOG_ENABLE enable UDP SYSLOG support feature(under DEVELOPMENT) that must be configured through config file @@ -176,5 +179,8 @@ platformio device monitor -b 115200 * DHT support enabled * Wifi manager for esp8266 enabled * RESTART_LAN_ON_MQTT_ERRORS disabled +* WITH_STREAMING_LIB disabled +* DEVICE_NAME disabled +* SYSLOG_ENABLE disabled If you've using Arduino IDE to compile & flash firmware, it will use Default options above and you will not able to configure additional compilers options except edit "options.h" file diff --git a/build_flags_template.sh b/build_flags_template.sh index e66e237..86372f0 100644 --- a/build_flags_template.sh +++ b/build_flags_template.sh @@ -25,5 +25,7 @@ # export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000" # export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS" # export FLAGS="$FLAGS -DW5500_CS_PIN=53" +#export FLAGS="$FLAGS -DSYSLOG_ENABLE" +#export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE" export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) echo $FLAGS diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 0ebdc85..50800ee 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -67,6 +67,7 @@ PWM Out #include "Arduino.h" #include "main.h" #include "options.h" +#include "utils.h" #ifdef WITH_STREAMING_LIB #include "Streaming.h" #else @@ -113,7 +114,7 @@ WiFiClient ethClient; EthernetClient ethClient; #endif -#ifndef SYSLOG_DISABLE +#ifdef SYSLOG_ENABLE #include EthernetUDP udpSyslogClient; Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_IETF); @@ -208,8 +209,11 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) { void printIPAddress(IPAddress ipAddress) { for (byte i = 0; i < 4; i++) -// (i < 3) ? debugSerial << _DEC(ipAddress[i]) << F(".") : debugSerial << _DEC(ipAddress[i])<valuestring; if (owEmit) { strncpy(addrbuf, owEmit, sizeof(addrbuf)); - debugSerial<valuestring; } else debugSerial<reset_search(); for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent @@ -58,18 +58,18 @@ int owUpdate() { if (!memcmp(term[i], term[t_count], 8)) { ifind = i; wstat[i] |= SW_FIND; - Serial.print(F(" Node:")); - PrintBytes(term[t_count], 8); - Serial.println(F(" alive")); + debugSerial.print(F(" Node:")); + PrintBytes(term[t_count], 8,0); + debugSerial.println(F(" alive")); break; }; //alive if (ifind < 0 && sensors) { wstat[t_count] = SW_FIND; //Newly detected - Serial.print(F("dev#")); - Serial.print(t_count); - Serial.print(F(" Addr:")); - PrintBytes(term[t_count], 8); - Serial.println(); + debugSerial.print(F("dev#")); + debugSerial.print(t_count); + debugSerial.print(F(" Addr:")); + PrintBytes(term[t_count], 8,0); + debugSerial.println(); if (term[t_count][0] == 0x28) { sensors->setResolution(term[t_count], TEMPERATURE_PRECISION); net->setStrongPullup(); @@ -80,8 +80,8 @@ int owUpdate() { }//if } //while - Serial.print(F("1-wire count: ")); - Serial.println(t_count); + debugSerial.print(F("1-wire count: ")); + debugSerial.println(t_count); #endif } @@ -91,12 +91,12 @@ int owSetup(owChangedType owCh) { //// todo - move memory allocation to here if (net) return true; // Already initialized #ifdef DS2482_100_I2C_TO_1W_BRIDGE - Serial.println(F("DS2482_100_I2C_TO_1W_BRIDGE init")); + debugSerial.println(F("DS2482_100_I2C_TO_1W_BRIDGE init")); net = new OneWire; #else - Serial.print(F("One wire setup on PIN:")); - Serial.println(QUOTE(USE_1W_PIN)); -net = new OneWire (USE_1W_PIN); + debugSerial.print(F("One wire setup on PIN:")); + debugSerial.println(QUOTE(USE_1W_PIN)); + net = new OneWire (USE_1W_PIN); #endif @@ -112,29 +112,29 @@ net = new OneWire (USE_1W_PIN); #ifdef DS2482_100_I2C_TO_1W_BRIDGE Wire.begin(); if (net->checkPresence()) { - Serial.println(F("DS2482-100 present")); + debugSerial.println(F("DS2482-100 present")); net->deviceReset(); #ifdef APU_OFF - Serial.println(F("APU off")); + debugSerial.println(F("APU off")); #else net->setActivePullup(); #endif - Serial.println(F("\tChecking for 1-Wire devices...")); + debugSerial.println(F("\tChecking for 1-Wire devices...")); if (net->wireReset()) - Serial.println(F("\tReset done")); + debugSerial.println(F("\tReset done")); sensors->begin(); owChanged = owCh; //owUpdate(); - //Serial.println(F("\t1-w Updated")); + //debugSerial.println(F("\t1-w Updated")); sensors->setWaitForConversion(false); return true; } #endif - Serial.println(F("\tDS2482 error")); + debugSerial.println(F("\tDS2482 error")); return false; // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement @@ -158,7 +158,7 @@ int sensors_loop(void) { case 0x28: // Thermomerer t = sensors->getTempC(term[si]);//*10.0; - //Serial.println("o"); + //debugSerial.println("o"); if (owChanged) owChanged(si, term[si], t); sensors->requestTemperaturesByAddress(term[si]); si++; @@ -192,11 +192,11 @@ void owAdd(DeviceAddress addr) { memcpy(term[t_count], addr, 8); //term[t_count]=addr; - Serial.print(F("dev#")); - Serial.print(t_count); - Serial.print(F(" Addr:")); - PrintBytes(term[t_count], 8); - Serial.println(); + debugSerial.print(F("dev#")); + debugSerial.print(t_count); + debugSerial.print(F(" Addr:")); + PrintBytes(term[t_count], 8,0); + debugSerial.println(); if (term[t_count][0] == 0x28) { sensors->setResolution(term[t_count], TEMPERATURE_PRECISION); net->setStrongPullup(); diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index ac5357e..d959d67 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -19,6 +19,7 @@ e-mail anklimov@gmail.com */ #include "utils.h" +#include "options.h" #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1) #include @@ -134,5 +135,61 @@ void parseBytes(const char *str, char separator, byte *bytes, int maxBytes, int str++; // Point to next character after separator } } + +#define ARDBUFFER 16 //Buffer for storing intermediate strings. Performance may vary depending on size. + +int log(const char *str, ...)//TODO: __FlashStringHelper str support +{ + int i, count=0, j=0, flag=0; + char temp[ARDBUFFER+1]; + for(i=0; str[i]!='\0';i++) if(str[i]=='%') count++; //Evaluate number of arguments required to be printed + + va_list argv; + va_start(argv, count); + for(i=0,j=0; str[i]!='\0';i++) //Iterate over formatting string + { + if(str[i]=='%') + { + //Clear buffer + temp[j] = '\0'; + Serial.print(temp); + j=0; + temp[0] = '\0'; + + //Process argument + switch(str[++i]) + { + case 'd': debugSerial.print(va_arg(argv, int)); + break; + case 'l': debugSerial.print(va_arg(argv, long)); + break; + case 'f': debugSerial.print(va_arg(argv, double)); + break; + case 'c': debugSerial.print((char)va_arg(argv, int)); + break; + case 's': debugSerial.print(va_arg(argv, char *)); + break; + default: ; + }; + } + else + { + //Add to buffer + temp[j] = str[i]; + j = (j+1)%ARDBUFFER; + if(j==0) //If buffer is full, empty buffer. + { + temp[ARDBUFFER] = '\0'; + debugSerial.print(temp); + temp[0]='\0'; + } + } + }; + + Serial.println(); //Print trailing newline + return count + 1; //Return number of arguments detected +} + + #pragma message(VAR_NAME_VALUE(debugSerial)) #pragma message(VAR_NAME_VALUE(SERIAL_BAUD)) \ No newline at end of file diff --git a/lighthub/utils.h b/lighthub/utils.h index 1725b59..4a1945a 100644 --- a/lighthub/utils.h +++ b/lighthub/utils.h @@ -25,10 +25,11 @@ e-mail anklimov@gmail.com #include -void PrintBytes(uint8_t* addr, uint8_t count, bool newline=0); +void PrintBytes(uint8_t* addr, uint8_t count, bool newline); void SetBytes(uint8_t* addr, uint8_t count, char * out); void SetAddr(char * out, uint8_t* addr); uint8_t HEX2DEC(char i); int getInt(char ** chan); unsigned long freeRam (); -void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base); \ No newline at end of file +void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base); +int log(const char *str, ...); \ No newline at end of file From dcf2fcf58e85a4dfa99475fd003c3646dd13b074 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 11 Oct 2018 00:50:08 +0300 Subject: [PATCH 12/13] build_flags_envName.sh are customized files and must not be placed into repository --- build_flags_mega2560-net.sh | 30 ------------------------------ build_flags_mega2560.sh | 30 ------------------------------ 2 files changed, 60 deletions(-) delete mode 100644 build_flags_mega2560-net.sh delete mode 100644 build_flags_mega2560.sh diff --git a/build_flags_mega2560-net.sh b/build_flags_mega2560-net.sh deleted file mode 100644 index 3f2c34c..0000000 --- a/build_flags_mega2560-net.sh +++ /dev/null @@ -1,30 +0,0 @@ -#! /bin/bash -# usage: -# first make your own copy of template -# cp build_flags_template.sh build_flags_ENVNAME.sh -# then edit, change or comment something - export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru" - #export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" - #export FLAGS="$FLAGS -DUSE_1W_PIN=12" - #export FLAGS="$FLAGS -DSD_CARD_INSERTED" - export FLAGS="$FLAGS -DSERIAL_BAUD=115200" - #export FLAGS="$FLAGS -DWiz5500" - #export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" - export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:fe" -# export FLAGS="$FLAGS -DDMX_DISABLE" -# export FLAGS="$FLAGS -DARTNET_ENABLE" -# export FLAGS="$FLAGS -DMODBUS_DISABLE" -# export FLAGS="$FLAGS -DOWIRE_DISABLE" -# export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" -# export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" -# export FLAGS="$FLAGS -DCONTROLLINO" -# export FLAGS="$FLAGS -DESP_WIFI_AP=MYAP" -# export FLAGS="$FLAGS -DESP_WIFI_PWD=MYPWD" -# export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE" - export FLAGS="$FLAGS -DDHT_DISABLE" -# export FLAGS="$FLAGS -DRESET_PIN=5" -# export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000" -# export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS" -# export FLAGS="$FLAGS -DW5500_CS_PIN=53" - export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) - echo $FLAGS diff --git a/build_flags_mega2560.sh b/build_flags_mega2560.sh deleted file mode 100644 index ee99442..0000000 --- a/build_flags_mega2560.sh +++ /dev/null @@ -1,30 +0,0 @@ -#! /bin/bash -# usage: -# first make your own copy of template -# cp build_flags_template.sh build_flags_ENVNAME.sh -# then edit, change or comment something - export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru" - #export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" - #export FLAGS="$FLAGS -DUSE_1W_PIN=12" - #export FLAGS="$FLAGS -DSD_CARD_INSERTED" - export FLAGS="$FLAGS -DSERIAL_BAUD=115200" - #export FLAGS="$FLAGS -DWiz5500" - #export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" - export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ed" -# export FLAGS="$FLAGS -DDMX_DISABLE" -# export FLAGS="$FLAGS -DARTNET_ENABLE" -# export FLAGS="$FLAGS -DMODBUS_DISABLE" - export FLAGS="$FLAGS -DOWIRE_DISABLE" -# export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" -# export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" -# export FLAGS="$FLAGS -DCONTROLLINO" -# export FLAGS="$FLAGS -DESP_WIFI_AP=MYAP" -# export FLAGS="$FLAGS -DESP_WIFI_PWD=MYPWD" -# export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE" - export FLAGS="$FLAGS -DDHT_DISABLE" -# export FLAGS="$FLAGS -DRESET_PIN=5" -# export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000" -# export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS" -# export FLAGS="$FLAGS -DW5500_CS_PIN=53" - export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) - echo $FLAGS From db8a48b1c476dee25efdb168852f460d669c27f7 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 11 Oct 2018 11:04:05 +0300 Subject: [PATCH 13/13] lan init fix --- lighthub/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 50800ee..f1a0a23 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -239,7 +239,8 @@ lan_status lanLoop() { switch (lanStatus) { case INITIAL_STATE: - onInitialStateInitLAN(); + if (millis() > nextLanCheckTime) + onInitialStateInitLAN(); break; case HAVE_IP_ADDRESS: @@ -467,7 +468,8 @@ void onInitialStateInitLAN() { lanStatus = HAVE_IP_ADDRESS;//1; } else { - debugSerial<