From 41df3b701e5f549e8211db585079288eaf55c637 Mon Sep 17 00:00:00 2001 From: livello Date: Mon, 15 Oct 2018 21:27:58 +0300 Subject: [PATCH 01/13] remove build_flags --- build_flags_due-5500.sh | 34 ++++++++++++++++------------------ build_flags_mega2560-net.sh | 31 ------------------------------- build_flags_mega2560.sh | 30 ------------------------------ 3 files changed, 16 insertions(+), 79 deletions(-) delete mode 100644 build_flags_mega2560-net.sh delete mode 100644 build_flags_mega2560.sh diff --git a/build_flags_due-5500.sh b/build_flags_due-5500.sh index b92f2f8..9a8943e 100644 --- a/build_flags_due-5500.sh +++ b/build_flags_due-5500.sh @@ -1,31 +1,29 @@ #! /bin/bash # usage: # first make your own copy of template -# cp build_flags_template.sh build_flags_ENVNAME.sh +# cp build_flags_template.sh my_build_flags.sh # then edit, change or comment something - export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru" - #export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" +# nano my_build_flags.sh +# and source it +# source my_build_flags.sh + export FLAGS="-DMY_CONFIG_SERVER=lighthub.elistech.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:ff" + export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" + export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=C2:3E:1f:03:1B:1E" # 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 -DWITH_STREAMING_LIB" + #export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" + #export FLAGS="$FLAGS -DCONTROLLINO" +# export FLAGS="$FLAGS -DRESET_PIN=8" + export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" +# export FLAGS="$FLAGS -DESP_WIFI_AP=vent" +# export FLAGS="$FLAGS -DESP_WIFI_PWD=kk007remont" +# export FLAGS="$FLAGS -DSYSLOG_DISABLE" + export FLAGS="$FLAGS -std=gnu++11" export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) echo $FLAGS diff --git a/build_flags_mega2560-net.sh b/build_flags_mega2560-net.sh deleted file mode 100644 index 87b6b46..0000000 --- a/build_flags_mega2560-net.sh +++ /dev/null @@ -1,31 +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 -DWITH_STREAMING_LIB" - 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 2bf6050f50719036fe4ee057997d33f58a82329d Mon Sep 17 00:00:00 2001 From: livello Date: Tue, 16 Oct 2018 11:36:59 +0300 Subject: [PATCH 02/13] domoticz dht22 support --- lighthub/inputs.cpp | 51 ++++++++++++++++++++++++------------------- lighthub/main.cpp | 7 +----- lighthub/utils.h | 6 +++++ mosquitto_examples.sh | 2 ++ platformio.ini | 4 ++-- 5 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 mosquitto_examples.sh diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index d6ca993..0771a2a 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -20,10 +20,11 @@ e-mail anklimov@gmail.com #include "inputs.h" #include "item.h" +#include "utils.h" #include #ifndef DHT_DISABLE -#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #include #else #include "DHT.h" @@ -149,7 +150,7 @@ void Input::counterPoll() { return; } long counterValue = counter_value[pin]; - Serial.print(F("IN:"));Serial.print(pin);Serial.print(F(" Counter type. val="));Serial.print(counterValue); + debugSerial<valuestring); - strcat(addrstr, "T"); - printFloatValueToStr(temp, valstr); - mqttClient.publish(addrstr, valstr); - addrstr[strlen(addrstr) - 1] = 'H'; - printFloatValueToStr(humidity, valstr); - mqttClient.publish(addrstr, valstr); + if(idx&&idx->valuestring){//DOMOTICZ json format support + debugSerial<valuestring<valuestring,temp,humidity); + debugSerial<valuestring, valstr); + } + else { + char valstr[10]; + strcat(addrstr, emit->valuestring); + strcat(addrstr, "T"); + printFloatValueToStr(temp, valstr); + mqttClient.publish(addrstr, valstr); + addrstr[strlen(addrstr) - 1] = 'H'; + printFloatValueToStr(humidity, valstr); + mqttClient.publish(addrstr, valstr); + } + setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT); - Serial.print(" NextPollMillis="); - Serial.println(nextPollTime()); + debugSerial<<" NextPollMillis="< Date: Tue, 16 Oct 2018 11:43:14 +0300 Subject: [PATCH 03/13] domoticz dht22 support --- build_flags_due-5500.sh | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 build_flags_due-5500.sh diff --git a/build_flags_due-5500.sh b/build_flags_due-5500.sh deleted file mode 100644 index 9a8943e..0000000 --- a/build_flags_due-5500.sh +++ /dev/null @@ -1,29 +0,0 @@ -#! /bin/bash -# usage: -# first make your own copy of template -# cp build_flags_template.sh my_build_flags.sh -# then edit, change or comment something -# nano my_build_flags.sh -# and source it -# source my_build_flags.sh - export FLAGS="-DMY_CONFIG_SERVER=lighthub.elistech.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=C2:3E:1f:03:1B:1E" -# export FLAGS="$FLAGS -DDMX_DISABLE" -# export FLAGS="$FLAGS -DMODBUS_DISABLE" -# export FLAGS="$FLAGS -DOWIRE_DISABLE" - #export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" - #export FLAGS="$FLAGS -DCONTROLLINO" -# export FLAGS="$FLAGS -DRESET_PIN=8" - export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" -# export FLAGS="$FLAGS -DESP_WIFI_AP=vent" -# export FLAGS="$FLAGS -DESP_WIFI_PWD=kk007remont" -# export FLAGS="$FLAGS -DSYSLOG_DISABLE" - export FLAGS="$FLAGS -std=gnu++11" - export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) - echo $FLAGS From fe9300f9215931613e87f1bcfd6ac38186f6b0f2 Mon Sep 17 00:00:00 2001 From: livello Date: Wed, 17 Oct 2018 12:16:20 +0300 Subject: [PATCH 04/13] domoticz dht22 support --- .gitignore | 8 ++++++++ lighthub/inputs.cpp | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 2764386..f1bf334 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,11 @@ .clang_complete .gcc-flags.json CMakeListsPrivate.txt +build_flags_due.sh +build_flags_due_cheb.sh +build_flags_due_riko.sh +build_flags_esp32.sh +build_flags_esp8266.sh +build_flags_stm32.sh +build_flags_due-5500.sh +build_flags_mega2560.sh \ No newline at end of file diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index 0771a2a..0fa7e04 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -26,6 +26,7 @@ e-mail anklimov@gmail.com #ifndef DHT_DISABLE #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #include + #else #include "DHT.h" #endif @@ -40,7 +41,7 @@ static volatile int nextPollMillisPin[5] = {0,0,0,0,0}; static volatile long counter_value[6]; #endif -#if defined(ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) static volatile long counter_value[6]; #endif @@ -204,7 +205,7 @@ void Input::dht22Poll() { #ifndef DHT_DISABLE if(nextPollTime()>millis()) return; -#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) DHTesp dhtSensor; dhtSensor.setup(pin, DHTesp::DHT22); TempAndHumidity dhtSensorData = dhtSensor.getTempAndHumidity(); @@ -223,7 +224,7 @@ void Input::dht22Poll() { if(idx&&idx->valuestring){//DOMOTICZ json format support debugSerial<valuestring<valuestring,temp,humidity); + sprintf( valstr,"{\"command\":\"udevice\",\"idx\":%s,\"svalue\":\"%.1f;%.0f;0\"}",idx->valuestring,temp,humidity); debugSerial<valuestring, valstr); } @@ -277,7 +278,7 @@ void Input::contactPoll() { #if defined(ARDUINO_ARCH_STM32F1) WiringPinMode inputPinMode; #endif -#if defined(__SAM3X8E__)||defined(__AVR__)||defined(ESP8266)||defined(ARDUINO_ARCH_ESP32) +#if defined(__SAM3X8E__)||defined(__AVR__)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) uint32_t inputPinMode; #endif From 655ef79b5d4cbc4a321a83a45d8c3a18b598ab47 Mon Sep 17 00:00:00 2001 From: livello Date: Wed, 17 Oct 2018 22:02:52 +0300 Subject: [PATCH 05/13] dht_counter_disable with_domoticz printex removed because of compilation errors --- README.md | 6 +- build_flags_template.sh | 2 +- lighthub/inputs.cpp | 225 +++++++++++++++++++++------------------- lighthub/inputs.h | 2 +- lighthub/main.cpp | 25 ++--- lighthub/options.h | 4 +- lighthub/utils.h | 6 +- platformio.ini | 11 +- 8 files changed, 140 insertions(+), 141 deletions(-) diff --git a/README.md b/README.md index 540a153..d40954f 100644 --- a/README.md +++ b/README.md @@ -151,9 +151,8 @@ platformio device monitor -b 115200 * ESP_WIFI_AP=MYAP // esp wifi access point name * ESP_WIFI_PWD=MYPWD // esp wifi access point password * WIFI_MANAGER_DISABLE //Disable wifi manager for esp8266 -* DHT_DISABLE //disable DHT Input support +* DHT_COUNTER_DISABLE //disable DHT, Counter, Uptime input support (for RAM savings on mega2560) * 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,10 +175,9 @@ platformio device monitor -b 115200 * Defailt MQTT input topic: /myhome/in * Default MQTT topic to publish device status: /myhome/s_out * Default Alarm output topic /alarm -* DHT support enabled +* DHT, Counter, Uptime support enabled * Wifi manager for esp8266 enabled * RESTART_LAN_ON_MQTT_ERRORS disabled -* WITH_STREAMING_LIB disabled * DEVICE_NAME disabled * SYSLOG_ENABLE disabled diff --git a/build_flags_template.sh b/build_flags_template.sh index 86372f0..6032bbf 100644 --- a/build_flags_template.sh +++ b/build_flags_template.sh @@ -20,12 +20,12 @@ # 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 -DSYSLOG_ENABLE" #export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE" +#export FLAGS="$FLAGS -DDHT_COUNTER_DISABLE" export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) echo $FLAGS diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index 0fa7e04..6b8fd25 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -23,7 +23,7 @@ e-mail anklimov@gmail.com #include "utils.h" #include -#ifndef DHT_DISABLE +#ifndef DHT_COUNTER_DISABLE #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #include @@ -34,9 +34,9 @@ e-mail anklimov@gmail.com extern PubSubClient mqttClient; +#ifndef DHT_COUNTER_DISABLE static volatile unsigned long nextPollMillisValue[5]; static volatile int nextPollMillisPin[5] = {0,0,0,0,0}; - #if defined(__AVR__) static volatile long counter_value[6]; #endif @@ -54,6 +54,9 @@ static short counter_irq_map[54]; static long counter_value[54]; static int counters_count; #endif +#endif + + Input::Input(char * name) //Constructor { if (name) @@ -88,31 +91,24 @@ void Input::Parse() store = NULL; inType = 0; pin = 0; - if (inputObj && (inputObj->type == aJson_Object)) { aJsonObject *s; - s = aJson.getObjectItem(inputObj, "T"); if (s) inType = static_cast(s->valueint); - pin = static_cast(atoi(inputObj->name)); - s = aJson.getObjectItem(inputObj, "S"); if (!s) { - Serial.print(F("In: ")); - Serial.print(pin); - Serial.print(F("/")); - Serial.println(inType); + debugSerial<valueint; } } int Input::poll() { if (!isValid()) return -1; + #ifndef DHT_COUNTER_DISABLE if (inType & IN_DHT22) dht22Poll(); else if (inType & IN_COUNTER) @@ -122,8 +118,11 @@ int Input::poll() { else contactPoll(); return 0; + #endif + contactPoll(); } +#ifndef DHT_COUNTER_DISABLE void Input::counterPoll() { if(nextPollTime()>millis()) return; @@ -166,7 +165,9 @@ void Input::counterPoll() { else debugSerial<millis()) + if (nextPollTime() > millis()) return; #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) DHTesp dhtSensor; dhtSensor.setup(pin, DHTesp::DHT22); TempAndHumidity dhtSensorData = dhtSensor.getTempAndHumidity(); - float temp = roundf(dhtSensorData.temperature*10)/10; + float temp = roundf(dhtSensorData.temperature * 10) / 10; float humidity = roundf(dhtSensorData.humidity); #else DHT dht(pin, DHT22); @@ -217,33 +218,35 @@ void Input::dht22Poll() { float humidity = dht.readHumidity(); #endif aJsonObject *emit = aJson.getObjectItem(inputObj, "emit"); - aJsonObject *idx = aJson.getObjectItem(inputObj, "idx"); - debugSerial<valuestring){//DOMOTICZ json format support - debugSerial<valuestring<valuestring,temp,humidity); - debugSerial<valuestring) {//DOMOTICZ json format support + debugSerial << endl << idx->valuestring << F(" Domoticz valstr:"); + char valstr[50]; + sprintf(valstr, "{\"idx\":%s,\"svalue\":\"%.1f;%.0f;0\"}", idx->valuestring, temp, humidity); + debugSerial << valstr; mqttClient.publish(emit->valuestring, valstr); + setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT); + debugSerial << F(" NextPollMillis=") << nextPollTime() << endl; + return; } - else { - char valstr[10]; - strcat(addrstr, emit->valuestring); - strcat(addrstr, "T"); - printFloatValueToStr(temp, valstr); - mqttClient.publish(addrstr, valstr); - addrstr[strlen(addrstr) - 1] = 'H'; - printFloatValueToStr(humidity, valstr); - mqttClient.publish(addrstr, valstr); - } +#endif + char valstr[10]; + strcat(addrstr, emit->valuestring); + strcat(addrstr, "T"); + printFloatValueToStr(temp, valstr); + mqttClient.publish(addrstr, valstr); + addrstr[strlen(addrstr) - 1] = 'H'; + printFloatValueToStr(humidity, valstr); + mqttClient.publish(addrstr, valstr); setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT); - debugSerial<<" NextPollMillis="<valuestring, valstr); + } + setNextPollTime(millis() +UPTIME_POLL_DELAY_DEFAULT); +} + +void Input::onCounterChanged(int i) { +#if defined(__SAM3X8E__) + counter_value[counter_irq_map[i]]++; +#endif + +#if defined(__AVR__) + counter_value[i]++; +#endif +} + +void Input::onCounterChanged0() { + onCounterChanged(0); +} +void Input::onCounterChanged1() { + onCounterChanged(1); +} +void Input::onCounterChanged2() { + onCounterChanged(2); +} +void Input::onCounterChanged3() { + onCounterChanged(3); +} +void Input::onCounterChanged4() { + onCounterChanged(4); +} +void Input::onCounterChanged5() { + onCounterChanged(5); +} + +#endif + void Input::contactPoll() { @@ -312,85 +360,54 @@ void Input::contactPoll() { store->bounce = SAME_STATE_ATTEMPTS; } -void Input::uptimePoll() { - if(nextPollTime()>millis()) - return; + + +void Input::onContactChanged(int newValue) { + debugSerial << F("IN:") << (pin) << F("=") << newValue << endl; + aJsonObject *item = aJson.getObjectItem(inputObj, "item"); + aJsonObject *scmd = aJson.getObjectItem(inputObj, "scmd"); + aJsonObject *rcmd = aJson.getObjectItem(inputObj, "rcmd"); aJsonObject *emit = aJson.getObjectItem(inputObj, "emit"); if (emit) { - char valstr[11]; -// printUlongValueToStr(valstr,millis()); - printUlongValueToStr(valstr,millis()); - mqttClient.publish(emit->valuestring, valstr); +#ifdef WITH_DOMOTICZ + aJsonObject *idx = aJson.getObjectItem(inputObj, "idx"); + if (idx->valuestring) { + debugSerial << endl << idx->valuestring << F(" Domoticz valstr:"); + char valstr[80]; + char *switchCmd; + (newValue)? sprintf(valstr, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}", idx->valuestring) + : sprintf(valstr,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",idx->valuestring); + debugSerial << valstr; + mqttClient.publish(emit->valuestring, valstr); + } else +#endif + if (newValue) { //send set command + if (!scmd) mqttClient.publish(emit->valuestring, "ON", true); + else if (strlen(scmd->valuestring)) + mqttClient.publish(emit->valuestring, scmd->valuestring, true); + } else { //send reset command + if (!rcmd) mqttClient.publish(emit->valuestring, "OFF", true); + else if (strlen(rcmd->valuestring))mqttClient.publish(emit->valuestring, rcmd->valuestring, true); + } } - setNextPollTime(millis() +UPTIME_POLL_DELAY_DEFAULT); -} -void Input::onContactChanged(int val) -{ - Serial.print(F("IN:")); Serial.print(pin);Serial.print(F("="));Serial.println(val); - aJsonObject * item = aJson.getObjectItem(inputObj,"item"); - aJsonObject * scmd = aJson.getObjectItem(inputObj,"scmd"); - aJsonObject * rcmd = aJson.getObjectItem(inputObj,"rcmd"); - aJsonObject * emit = aJson.getObjectItem(inputObj,"emit"); - - if (emit) - { - - if (val) - { //send set command - if (!scmd) mqttClient.publish(emit->valuestring,"ON",true); else if (strlen(scmd->valuestring)) mqttClient.publish(emit->valuestring,scmd->valuestring,true); + if (item) { + Item it(item->valuestring); + if (it.isValid()) { + if (newValue) { //send set command + if (!scmd) it.Ctrl(CMD_ON, 0, NULL, true); + else if (strlen(scmd->valuestring)) + it.Ctrl(scmd->valuestring, true); + } else { //send reset command + if (!rcmd) it.Ctrl(CMD_OFF, 0, NULL, true); + else if (strlen(rcmd->valuestring)) + it.Ctrl(rcmd->valuestring, true); } - else - { //send reset command - if (!rcmd) mqttClient.publish(emit->valuestring,"OFF",true); else if (strlen(rcmd->valuestring)) mqttClient.publish(emit->valuestring,rcmd->valuestring,true); - } - } - - if (item) - { - Item it(item->valuestring); - if (it.isValid()) - { - if (val) - { //send set command - if (!scmd) it.Ctrl(CMD_ON,0,NULL,true); else if (strlen(scmd->valuestring)) it.Ctrl(scmd->valuestring,true); - } - else - { //send reset command - if (!rcmd) it.Ctrl(CMD_OFF,0,NULL,true); else if (strlen(rcmd->valuestring)) it.Ctrl(rcmd->valuestring,true); - } - } - } + } + } } -void Input::onCounterChanged(int i) { -#if defined(__SAM3X8E__) - counter_value[counter_irq_map[i]]++; -#endif -#if defined(__AVR__) - counter_value[i]++; -#endif -} - -void Input::onCounterChanged0() { - onCounterChanged(0); -} -void Input::onCounterChanged1() { - onCounterChanged(1); -} -void Input::onCounterChanged2() { - onCounterChanged(2); -} -void Input::onCounterChanged3() { - onCounterChanged(3); -} -void Input::onCounterChanged4() { - onCounterChanged(4); -} -void Input::onCounterChanged5() { - onCounterChanged(5); -} void Input::printUlongValueToStr(char *valstr, unsigned long value) { char buf[11]; diff --git a/lighthub/inputs.h b/lighthub/inputs.h index 3e37ee8..262728f 100644 --- a/lighthub/inputs.h +++ b/lighthub/inputs.h @@ -91,7 +91,7 @@ public: boolean isValid(); - void onContactChanged(int val); + void onContactChanged(int newValue); int poll(); diff --git a/lighthub/main.cpp b/lighthub/main.cpp index bc6a3af..90abec1 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -204,21 +204,13 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) { void printIPAddress(IPAddress ipAddress) { for (byte i = 0; i < 4; i++) -#ifdef WITH_STREAMING_LIB (i < 3) ? debugSerial << _DEC(ipAddress[i]) << F(".") : debugSerial << _DEC(ipAddress[i]) << F(", "); -#else - (i < 3) ? debugSerial << (ipAddress[i]) << F(".") : debugSerial << (ipAddress[i])< 0) { delay(500); wifi_connection_wait -= 500; - debugSerial<<"."); + debugSerial<<"."; } wifiInitialized = true; } @@ -458,12 +447,10 @@ void onInitialStateInitLAN() { #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) if (WiFi.status() == WL_CONNECTED) { - debugSerial< Date: Thu, 18 Oct 2018 00:44:16 +0300 Subject: [PATCH 06/13] optional build_scripts --- check_custom_build_flags_controllino.sh | 8 ++++++ check_custom_build_flags_due-5500.sh | 8 ++++++ check_custom_build_flags_due.sh | 6 +++++ check_custom_build_flags_esp32.sh | 6 +++++ check_custom_build_flags_esp8266.sh | 6 +++++ check_custom_build_flags_mega2560-net.sh | 6 +++++ check_custom_build_flags_mega2560.sh | 9 +++++++ check_custom_build_flags_stm32.sh | 6 +++++ .../build_flags_template.sh | 0 platformio.ini | 25 ++++++++++--------- 10 files changed, 68 insertions(+), 12 deletions(-) create mode 100755 check_custom_build_flags_controllino.sh create mode 100755 check_custom_build_flags_due-5500.sh create mode 100755 check_custom_build_flags_due.sh create mode 100755 check_custom_build_flags_esp32.sh create mode 100755 check_custom_build_flags_esp8266.sh create mode 100755 check_custom_build_flags_mega2560-net.sh create mode 100755 check_custom_build_flags_mega2560.sh create mode 100755 check_custom_build_flags_stm32.sh rename build_flags_template.sh => custom-build-flags/build_flags_template.sh (100%) diff --git a/check_custom_build_flags_controllino.sh b/check_custom_build_flags_controllino.sh new file mode 100755 index 0000000..c0411cc --- /dev/null +++ b/check_custom_build_flags_controllino.sh @@ -0,0 +1,8 @@ +#! /bin/bash +export FLAGS="$FLAGS -DCONTROLLINO" +export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:07" +CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_controllino.sh +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/check_custom_build_flags_due-5500.sh b/check_custom_build_flags_due-5500.sh new file mode 100755 index 0000000..c03a0ac --- /dev/null +++ b/check_custom_build_flags_due-5500.sh @@ -0,0 +1,8 @@ +#! /bin/bash +export FLAGS="$FLAGS -DWiz5500" +export FLAGS="$FLAGS -DARTNET_ENABLE" +CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_due-5500.sh +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/check_custom_build_flags_due.sh b/check_custom_build_flags_due.sh new file mode 100755 index 0000000..75bf199 --- /dev/null +++ b/check_custom_build_flags_due.sh @@ -0,0 +1,6 @@ +#! /bin/bash +CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_due.sh +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/check_custom_build_flags_esp32.sh b/check_custom_build_flags_esp32.sh new file mode 100755 index 0000000..093eabc --- /dev/null +++ b/check_custom_build_flags_esp32.sh @@ -0,0 +1,6 @@ +#! /bin/bash +CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp32.sh +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/check_custom_build_flags_esp8266.sh b/check_custom_build_flags_esp8266.sh new file mode 100755 index 0000000..37f2331 --- /dev/null +++ b/check_custom_build_flags_esp8266.sh @@ -0,0 +1,6 @@ +#! /bin/bash +CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp8266.sh +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/check_custom_build_flags_mega2560-net.sh b/check_custom_build_flags_mega2560-net.sh new file mode 100755 index 0000000..af70285 --- /dev/null +++ b/check_custom_build_flags_mega2560-net.sh @@ -0,0 +1,6 @@ +#! /bin/bash +CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_mega2560-net.sh +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/check_custom_build_flags_mega2560.sh b/check_custom_build_flags_mega2560.sh new file mode 100755 index 0000000..acfe945 --- /dev/null +++ b/check_custom_build_flags_mega2560.sh @@ -0,0 +1,9 @@ +#! /bin/bash +CUSTOM_BUILD_FLAGS_FILE="custom-build-flags/build_flags_mega2560.sh" +#CUSTOM_BUILD_FLAGS_FILE="custom-build-flags/build_flags_$PIOENV.sh" +#echo $PIOENV > custom-build-flags/1.txt +#TODO: make one file for all envs +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/check_custom_build_flags_stm32.sh b/check_custom_build_flags_stm32.sh new file mode 100755 index 0000000..6f9d7c2 --- /dev/null +++ b/check_custom_build_flags_stm32.sh @@ -0,0 +1,6 @@ +#! /bin/bash +CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_stm32.sh +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/build_flags_template.sh b/custom-build-flags/build_flags_template.sh similarity index 100% rename from build_flags_template.sh rename to custom-build-flags/build_flags_template.sh diff --git a/platformio.ini b/platformio.ini index d4bb7b5..7a4e33c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,14 +10,14 @@ [platformio] src_dir = lighthub env_default = - megaatmega2560 +; megaatmega2560 ; megaatmega2560-net ; due ; esp8266 ; esp32 ; megaatmega2560-5500 ; due-5500 -; controllino + controllino ; stm32 ;build_dir = !sh pioenvs.sh ${platformio.env_default} @@ -30,7 +30,7 @@ platform = espressif32 framework = arduino board = pico32 lib_ldf_mode = chain+ -build_flags = !sh build_flags_esp32.sh +build_flags = !bash check_custom_build_flags_esp32.sh lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -55,7 +55,7 @@ upload_protocol = stlink debug_tool = stlink extra_scripts = pre:!pre_stm32.sh ;lib_ldf_mode = chain+ -build_flags = !sh build_flags_stm32.sh +build_flags = !bash check_custom_build_flags_stm32.sh lib_deps = DallasTemperature https://github.com/anklimov/aJson @@ -78,7 +78,7 @@ platform = atmelsam framework = arduino board = due lib_ldf_mode = chain+ -build_flags = !sh build_flags_due.sh +build_flags = !bash check_custom_build_flags_due.sh lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -97,6 +97,7 @@ lib_deps = Adafruit Unified Sensor DHT sensor library https://github.com/arcao/Syslog.git + Streaming [env:megaatmega2560] @@ -105,8 +106,10 @@ board = megaatmega2560 ;upload_port = net:192.168.88.31:23 framework = arduino ;lib_ldf_mode = chain+ -build_flags = !sh build_flags_mega2560.sh +build_flags = !bash check_custom_build_flags_mega2560.sh lib_deps = + https://github.com/anklimov/Arduino-Temperature-Control-Library.git + https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DmxSimple https://github.com/anklimov/httpClient https://github.com/anklimov/aJson @@ -129,7 +132,7 @@ platform = espressif8266 framework = arduino board = nodemcuv2 lib_ldf_mode = chain+ -build_flags = !sh build_flags_esp8266.sh +build_flags = !bash check_custom_build_flags_esp8266.sh lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -153,7 +156,7 @@ platform = atmelavr board = megaatmega2560 framework = arduino upload_port = net:192.168.88.2:23000 -build_flags = !sh build_flags_mega2560-net.sh +build_flags = !bash check_custom_build_flags_mega2560-net.sh ;lib_ldf_mode = chain+ lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -180,8 +183,7 @@ platform = atmelsam framework = arduino board = due ;lib_ldf_mode = chain+ -build_flags = -D Wiz5500 -D ARTNET_ENABLE -build_flags = !sh build_flags_due-5500.sh +build_flags = !bash check_custom_build_flags_due-5500.sh lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -207,8 +209,7 @@ platform = atmelavr board = megaatmega2560 framework = arduino ;lib_ldf_mode = chain+ -build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) -build_flags = -D CONTROLLINO -D CUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:07 +build_flags = !bash check_custom_build_flags_controllino.sh lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire From 4101f7bd2e90e1d91c9d237baf25f8faf4d4b8a0 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 18 Oct 2018 00:57:00 +0300 Subject: [PATCH 07/13] ARDUINO_ARCH_AVR --- lighthub/dmx.cpp | 6 +++--- lighthub/dmx.h | 4 ++-- lighthub/inputs.cpp | 10 +++++----- lighthub/main.cpp | 12 ++++++------ lighthub/main.h | 6 +++--- lighthub/options.h | 2 +- lighthub/utils.cpp | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lighthub/dmx.cpp b/lighthub/dmx.cpp index d604985..9e6ad0c 100644 --- a/lighthub/dmx.cpp +++ b/lighthub/dmx.cpp @@ -23,7 +23,7 @@ e-mail anklimov@gmail.com #include "options.h" #ifdef _dmxin -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) #include #endif #endif @@ -207,7 +207,7 @@ void DMXinSetup(int channels) #if defined(_dmxin) DMXin = new uint8_t [channels]; -#if defined(__AVR__) +#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")); //DMXSerial.maxChannel(channels); @@ -230,7 +230,7 @@ dmxin.begin(); void DMXoutSetup(int channels) { #ifdef _dmxout -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) DmxSimple.usePin(AVR_DMXOUT_PIN); DmxSimple.maxChannel(channels); #endif diff --git a/lighthub/dmx.h b/lighthub/dmx.h index f879b16..387aaa7 100644 --- a/lighthub/dmx.h +++ b/lighthub/dmx.h @@ -33,7 +33,7 @@ e-mail anklimov@gmail.com #if defined(_dmxout) -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) #include #define DmxWrite DmxSimple.write #endif @@ -56,7 +56,7 @@ extern Artnet *artnet; #endif #ifdef _dmxin -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) #include #endif #endif diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index 6b8fd25..31aed83 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -37,7 +37,7 @@ extern PubSubClient mqttClient; #ifndef DHT_COUNTER_DISABLE static volatile unsigned long nextPollMillisValue[5]; static volatile int nextPollMillisPin[5] = {0,0,0,0,0}; -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) static volatile long counter_value[6]; #endif @@ -127,7 +127,7 @@ void Input::counterPoll() { if(nextPollTime()>millis()) return; if (store->logicState == 0) { -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) #define interrupt_number pin if (interrupt_number >= 0 && interrupt_number < 6) { const short mega_interrupt_array[6] = {2, 3, 21, 20, 19, 18}; @@ -171,7 +171,7 @@ void Input::counterPoll() { void Input::attachInterruptPinIrq(int realPin, int irq) { pinMode(realPin, INPUT); int real_irq; -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) real_irq = irq; #endif #if defined(__SAM3X8E__) @@ -293,7 +293,7 @@ void Input::onCounterChanged(int i) { counter_value[counter_irq_map[i]]++; #endif -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) counter_value[i]++; #endif } @@ -326,7 +326,7 @@ void Input::contactPoll() { #if defined(ARDUINO_ARCH_STM32F1) WiringPinMode inputPinMode; #endif -#if defined(__SAM3X8E__)||defined(__AVR__)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) +#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) uint32_t inputPinMode; #endif diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 90abec1..2b1dbd6 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -76,7 +76,7 @@ DueFlashStorage EEPROM; EthernetClient ethClient; #endif -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) EthernetClient ethClient; #endif @@ -286,7 +286,7 @@ lan_status lanLoop() { { -#if defined(__AVR__) || defined(__SAM3X8E__) +#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) wdt_dis(); if (lanStatus > 0) switch (Ethernet.maintain()) { @@ -456,7 +456,7 @@ void onInitialStateInitLAN() { } #endif -#if defined(__AVR__) || defined(__SAM3X8E__)||defined(ARDUINO_ARCH_STM32F1) +#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)||defined(ARDUINO_ARCH_STM32F1) #ifdef W5500_CS_PIN Ethernet.w5500_cspin = W5500_CS_PIN; debugSerial< #endif -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) #include "HTTPClient.h" #include #include @@ -104,7 +104,7 @@ #endif -#if defined(__AVR__) || defined(__SAM3X8E__) || defined(ESP8266) +#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(ESP8266) #ifdef Wiz5500 #include #else diff --git a/lighthub/options.h b/lighthub/options.h index 9fc627b..31ad60f 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -95,7 +95,7 @@ #define LAN_INIT_DELAY 500 #endif -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) //All options available #ifdef CONTROLLINO #define modbusSerial Serial3 diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index feb1351..db88ab5 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -86,7 +86,7 @@ unsigned long freeRam () {return system_get_free_heap_size();} #endif -#if defined(__AVR__) +#if defined(ARDUINO_ARCH_AVR) unsigned long freeRam () { extern int __heap_start, *__brkval; @@ -141,7 +141,7 @@ void printFloatValueToStr(float value, char *valstr) { #if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32) sprintf(valstr, "%2.1f", value); #endif - #if defined(__AVR__) + #if defined(ARDUINO_ARCH_AVR) sprintf(valstr, "%d", (int)value); int fractional = 10.0*((float)abs(value)-(float)abs((int)value)); int val_len =strlen(valstr); From 321e4843bad2bc833f0cb783621e94b06064bad7 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 18 Oct 2018 08:49:39 +0300 Subject: [PATCH 08/13] return WITH_PRINTEX_LIB and still has compilation problems --- .gitignore | 5 ++--- README.md | 2 ++ custom-build-flags/build_flags_template.sh | 1 + lighthub/main.cpp | 10 ++++++++-- lighthub/utils.h | 5 +++++ platformio.ini | 10 ++++++---- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f1bf334..a194c49 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,9 @@ .gcc-flags.json CMakeListsPrivate.txt build_flags_due.sh -build_flags_due_cheb.sh -build_flags_due_riko.sh build_flags_esp32.sh build_flags_esp8266.sh build_flags_stm32.sh build_flags_due-5500.sh -build_flags_mega2560.sh \ No newline at end of file +build_flags_mega2560.sh +build_flags_controllino.sh \ No newline at end of file diff --git a/README.md b/README.md index d40954f..9404663 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ platformio device monitor -b 115200 * RESTART_LAN_ON_MQTT_ERRORS //reinit LAN if many mqtt errors occured * 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 +* WITH_PRINTEX_LIB use PrintEx library (develop experimental feature) @@ -180,5 +181,6 @@ platformio device monitor -b 115200 * RESTART_LAN_ON_MQTT_ERRORS disabled * DEVICE_NAME disabled * SYSLOG_ENABLE disabled +* WITH_PRINTEX_LIB diabled, using Streaming library 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/custom-build-flags/build_flags_template.sh b/custom-build-flags/build_flags_template.sh index 6032bbf..517a351 100644 --- a/custom-build-flags/build_flags_template.sh +++ b/custom-build-flags/build_flags_template.sh @@ -27,5 +27,6 @@ #export FLAGS="$FLAGS -DSYSLOG_ENABLE" #export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE" #export FLAGS="$FLAGS -DDHT_COUNTER_DISABLE" +#export FLAGS="$FLAGS -DWITH_PRINTEX_LIB" 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 2b1dbd6..33e6ca7 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -69,8 +69,6 @@ PWM Out #include "options.h" #include "utils.h" - - #if defined(__SAM3X8E__) DueFlashStorage EEPROM; EthernetClient ethClient; @@ -204,13 +202,21 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) { void printIPAddress(IPAddress ipAddress) { for (byte i = 0; i < 4; i++) +#ifdef WITH_PRINTEX_LIB + (i < 3) ? debugSerial << (ipAddress[i]) << F(".") : debugSerial << (ipAddress[i])< #include "options.h" +#ifdef WITH_PRINTEX_LIB +#include "PrintEx.h" +using namespace ios; +#else #include "Streaming.h" +#endif void PrintBytes(uint8_t* addr, uint8_t count, bool newline); void SetBytes(uint8_t* addr, uint8_t count, char * out); diff --git a/platformio.ini b/platformio.ini index 7a4e33c..a4bf2cf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,14 +16,14 @@ env_default = ; esp8266 ; esp32 ; megaatmega2560-5500 -; due-5500 - controllino + due-5500 +; controllino ; stm32 ;build_dir = !sh pioenvs.sh ${platformio.env_default} ;libdeps_dir = !sh piolibdeps.sh ${platformio.env_default} -;build_dir = /tmp/pioenvs -;libdeps_dir = /tmp/piolibdeps +build_dir = /tmp/pioenvs +libdeps_dir = /tmp/piolibdeps [env:esp32] platform = espressif32 @@ -203,6 +203,7 @@ lib_deps = DHT sensor library https://github.com/arcao/Syslog.git Streaming + https://github.com/livello/PrintEx#is-select-redecl [env:controllino] platform = atmelavr @@ -228,3 +229,4 @@ lib_deps = Adafruit Unified Sensor DHT sensor library Streaming + https://github.com/livello/PrintEx#is-select-redecl From 67c7e373a09f7b74aed4a29e04a13023e9aba2b8 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 18 Oct 2018 16:19:44 +0300 Subject: [PATCH 09/13] lib_ignore almost allow keep piolibdeps --- custom-build-flags/build_flags_controllino.sh | 31 +++++++++++ platformio.ini | 55 ++++++++++++++++--- 2 files changed, 77 insertions(+), 9 deletions(-) create mode 100755 custom-build-flags/build_flags_controllino.sh diff --git a/custom-build-flags/build_flags_controllino.sh b/custom-build-flags/build_flags_controllino.sh new file mode 100755 index 0000000..a7ec009 --- /dev/null +++ b/custom-build-flags/build_flags_controllino.sh @@ -0,0 +1,31 @@ +#! /bin/bash +# usage: +# first make your own copy of template +# cp build_flags_template.sh my_build_flags.sh +# then edit, change or comment something +# nano my_build_flags.sh +# and source it +# source my_build_flags.sh + export FLAGS="-DMY_CONFIG_SERVER=lighthub.elistech.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=C2:3E:1f:03:1B:1E" +# export FLAGS="$FLAGS -DDMX_DISABLE" +# export FLAGS="$FLAGS -DMODBUS_DISABLE" +# export FLAGS="$FLAGS -DOWIRE_DISABLE" + #export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" + #export FLAGS="$FLAGS -DCONTROLLINO" +# export FLAGS="$FLAGS -DRESET_PIN=8" + export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" +# export FLAGS="$FLAGS -DESP_WIFI_AP=vent" +# export FLAGS="$FLAGS -DESP_WIFI_PWD=kk007remont" +# export FLAGS="$FLAGS -DSYSLOG_ENABLE" + export FLAGS="$FLAGS -DDEVICE_NAME=kk007_mega2560" +export FLAGS="$FLAGS -DDHT_COUNTER_DISABLE" +#export FLAGS="$FLAGS -DWITH_DOMOTICZ" +#export FLAGS="$FLAGS -DWITH_PRINTEX_LIB" + export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index a4bf2cf..d6ff1cf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,9 +14,9 @@ env_default = ; megaatmega2560-net ; due ; esp8266 -; esp32 + esp32 ; megaatmega2560-5500 - due-5500 +; due-5500 ; controllino ; stm32 @@ -29,8 +29,17 @@ libdeps_dir = /tmp/piolibdeps platform = espressif32 framework = arduino board = pico32 -lib_ldf_mode = chain+ +;lib_ldf_mode = chain+ build_flags = !bash check_custom_build_flags_esp32.sh +lib_ignore = + DmxSimple + DMXSerial + DmxDue + DueFlashStorage + SD + SdFat + httpClient + ;Ethernet library??? lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -46,6 +55,7 @@ lib_deps = DHT sensor library for ESPx DHT sensor library Streaming + https://github.com/livello/PrintEx#is-select-redecl [env:stm32] platform = ststm32 @@ -77,8 +87,12 @@ lib_deps = platform = atmelsam framework = arduino board = due -lib_ldf_mode = chain+ build_flags = !bash check_custom_build_flags_due.sh +lib_ignore = + DHT sensor library for ESPx + DMXSerial + DmxSimple + httpClient lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -105,8 +119,11 @@ platform = atmelavr board = megaatmega2560 ;upload_port = net:192.168.88.31:23 framework = arduino -;lib_ldf_mode = chain+ build_flags = !bash check_custom_build_flags_mega2560.sh +lib_ignore = + DHT sensor library for ESPx + DmxDue + DueFlashStorage lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -118,6 +135,7 @@ lib_deps = https://github.com/anklimov/DMXSerial https://github.com/anklimov/Ethernet https://github.com/PaulStoffregen/SPI.git + ;TODO: need to rename SPI lib https://github.com/knolleary/pubsubclient.git https://github.com/anklimov/Artnet.git FastLED @@ -131,8 +149,15 @@ lib_deps = platform = espressif8266 framework = arduino board = nodemcuv2 -lib_ldf_mode = chain+ build_flags = !bash check_custom_build_flags_esp8266.sh +lib_ignore = + DmxSimple + DMXSerial + DmxDue + DueFlashStorage + SD + SdFat + httpClient lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -157,7 +182,11 @@ board = megaatmega2560 framework = arduino upload_port = net:192.168.88.2:23000 build_flags = !bash check_custom_build_flags_mega2560-net.sh -;lib_ldf_mode = chain+ +lib_ignore = + DHT sensor library for ESPx + DmxDue + DueFlashStorage + ESP-Dmx lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -182,8 +211,12 @@ lib_deps = platform = atmelsam framework = arduino board = due -;lib_ldf_mode = chain+ build_flags = !bash check_custom_build_flags_due-5500.sh +lib_ignore = + DHT sensor library for ESPx + https://github.com/anklimov/Ethernet + ESP-Dmx + DMXSerial lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -209,8 +242,12 @@ lib_deps = platform = atmelavr board = megaatmega2560 framework = arduino -;lib_ldf_mode = chain+ build_flags = !bash check_custom_build_flags_controllino.sh +lib_ignore = + DHT sensor library for ESPx + DmxDue + DueFlashStorage + ESP-Dmx lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire From b5112c2a29b067913d62b50eb61e8dc24461710d Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 18 Oct 2018 19:43:40 +0300 Subject: [PATCH 10/13] lib_ignore all envs except stm32 compiles ok at one time --- platformio.ini | 87 ++++++++++++++++++++++++++++++-------------------- pre_stm32.sh | 4 --- 2 files changed, 53 insertions(+), 38 deletions(-) delete mode 100644 pre_stm32.sh diff --git a/platformio.ini b/platformio.ini index d6ff1cf..96f7a8e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,12 +9,12 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] src_dir = lighthub -env_default = +;env_default = ; megaatmega2560 ; megaatmega2560-net ; due ; esp8266 - esp32 +; esp32 ; megaatmega2560-5500 ; due-5500 ; controllino @@ -29,7 +29,6 @@ libdeps_dir = /tmp/piolibdeps platform = espressif32 framework = arduino board = pico32 -;lib_ldf_mode = chain+ build_flags = !bash check_custom_build_flags_esp32.sh lib_ignore = DmxSimple @@ -39,11 +38,12 @@ lib_ignore = SD SdFat httpClient - ;Ethernet library??? + WifiManager + Ethernet lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire - ESP8266HTTPClient +; ESP8266HTTPClient Ethernet3 https://github.com/anklimov/aJson https://github.com/anklimov/CmdArduino @@ -57,32 +57,6 @@ lib_deps = Streaming https://github.com/livello/PrintEx#is-select-redecl -[env:stm32] -platform = ststm32 -framework = arduino -board = nucleo_f103rb -upload_protocol = stlink -debug_tool = stlink -extra_scripts = pre:!pre_stm32.sh -;lib_ldf_mode = chain+ -build_flags = !bash check_custom_build_flags_stm32.sh -lib_deps = - DallasTemperature - https://github.com/anklimov/aJson - https://github.com/anklimov/CmdArduino - ArduinoHttpClient - https://github.com/anklimov/ModbusMaster -; https://github.com/Serasidis/Ethernet_STM.git -; https://github.com/livello/Ethernet_STM.git - https://github.com/knolleary/pubsubclient.git - Adafruit Unified Sensor - DHT sensor library -; https://github.com/anklimov/DMXSerial -; Syslog -; https://github.com/No3x/Syslog.git - https://github.com/arcao/Syslog.git -; UIPEthernet - [env:due] platform = atmelsam framework = arduino @@ -93,6 +67,8 @@ lib_ignore = DMXSerial DmxSimple httpClient + ESPDMX + WifiManager lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -124,6 +100,7 @@ lib_ignore = DHT sensor library for ESPx DmxDue DueFlashStorage + WifiManager lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -134,7 +111,7 @@ lib_deps = https://github.com/anklimov/ModbusMaster https://github.com/anklimov/DMXSerial https://github.com/anklimov/Ethernet - https://github.com/PaulStoffregen/SPI.git +; https://github.com/PaulStoffregen/SPI.git ;TODO: need to rename SPI lib https://github.com/knolleary/pubsubclient.git https://github.com/anklimov/Artnet.git @@ -187,6 +164,7 @@ lib_ignore = DmxDue DueFlashStorage ESP-Dmx + WifiManager lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -197,7 +175,7 @@ lib_deps = https://github.com/anklimov/ModbusMaster https://github.com/anklimov/DMXSerial https://github.com/anklimov/Ethernet - https://github.com/PaulStoffregen/SPI.git +; https://github.com/PaulStoffregen/SPI.git https://github.com/knolleary/pubsubclient.git https://github.com/anklimov/Artnet.git FastLED @@ -217,6 +195,12 @@ lib_ignore = https://github.com/anklimov/Ethernet ESP-Dmx DMXSerial + ESPDMX + WifiManager + DmxSimple + httpClient + Ethernet + lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -248,6 +232,7 @@ lib_ignore = DmxDue DueFlashStorage ESP-Dmx + WifiManager lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -258,7 +243,7 @@ lib_deps = https://github.com/anklimov/ModbusMaster https://github.com/anklimov/DMXSerial https://github.com/anklimov/Ethernet - https://github.com/PaulStoffregen/SPI.git +; https://github.com/PaulStoffregen/SPI.git https://github.com/knolleary/pubsubclient.git https://github.com/anklimov/Artnet.git FastLED @@ -267,3 +252,37 @@ lib_deps = DHT sensor library Streaming https://github.com/livello/PrintEx#is-select-redecl + +;TODO:STM32 compilation problems +;[env:stm32] +;platform = ststm32 +;framework = arduino +;board = nucleo_f103rb +;upload_protocol = stlink +;debug_tool = stlink +;build_flags = !bash check_custom_build_flags_stm32.sh +;lib_ignore = +; DHT sensor library for ESPx +; DmxDue +; DueFlashStorage +; ESP-Dmx +; WifiManager +; FastLED +; Ethernet +;lib_deps = +; DallasTemperature +; https://github.com/anklimov/aJson +; https://github.com/anklimov/CmdArduino +; ArduinoHttpClient +; https://github.com/anklimov/ModbusMaster +;; https://github.com/Serasidis/Ethernet_STM.git +;; https://github.com/livello/Ethernet_STM.git +; https://github.com/knolleary/pubsubclient.git +; Adafruit Unified Sensor +; DHT sensor library +;; https://github.com/anklimov/DMXSerial +;; Syslog +;; https://github.com/No3x/Syslog.git +; https://github.com/arcao/Syslog.git +;; UIPEthernet +; Streaming diff --git a/pre_stm32.sh b/pre_stm32.sh deleted file mode 100644 index d544c4f..0000000 --- a/pre_stm32.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /bin/bash -rm /tmp/piolibdeps -Rf -mkdir /tmp/piolibdeps_stm32 -ln -s /tmp/piolibdeps_stm32 /tmp/piolibdeps From cd03599b838bce7c33c8333064c3d3350a7193f1 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 18 Oct 2018 22:10:18 +0300 Subject: [PATCH 11/13] merge upstream/develop --- lighthub/item.cpp | 79 +++++++++++++++++++++++++++++++++++++--------- lighthub/item.h | 13 +++++++- lighthub/options.h | 8 ++++- 3 files changed, 83 insertions(+), 17 deletions(-) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 152a8f0..adc0318 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -574,14 +574,16 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) { case CH_MODBUS: { short numpar=0; if ((itemArg->type == aJson_Array) && ((numpar = aJson.getArraySize(itemArg)) >= 2)) { - int _addr = aJson.getArrayItem(itemArg, 0)->valueint; - int _reg = aJson.getArrayItem(itemArg, 1)->valueint; + int _addr = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_ADDR)->valueint; + int _reg = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG)->valueint; int _mask = -1; - if (numpar >= 3) _mask = aJson.getArrayItem(itemArg, 2)->valueint; + if (numpar >= (MODBUS_CMD_ARG_MASK+1)) _mask = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_MASK)->valueint; int _maxval = 0x3f; - if (numpar >=4) _maxval = aJson.getArrayItem(itemArg, 3)->valueint; - if (_maxval) modbusDimmerSet(_addr, _reg, _mask, map(Par[0], 0, 100, 0, _maxval)); - else modbusDimmerSet(_addr, _reg, _mask, Par[0]); + if (numpar >= (MODBUS_CMD_ARG_MAX_SCALE+1)) _maxval = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_MAX_SCALE)->valueint; + int _regType = MODBUS_HOLDING_REG_TYPE; + if (numpar >= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint; + if (_maxval) modbusDimmerSet(_addr, _reg, _regType, _mask, map(Par[0], 0, 100, 0, _maxval)); + else modbusDimmerSet(_addr, _reg, _regType, _mask, Par[0]); } break; } @@ -886,7 +888,11 @@ int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) { modbusBusy = 0; } -int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) { +int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value) { + + if (_regType != MODBUS_COIL_REG_TYPE || _regType != MODBUS_HOLDING_REG_TYPE) { + + } if (modbusBusy) { mb_fail(3, addr, value, 0); @@ -895,7 +901,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) { }; modbusBusy = 1; - modbusSerial.begin(9600, dimPar); + modbusSerial.begin(MODBUS_SERIAL_BAUD, dimPar); node.begin(addr, modbusSerial); @@ -912,10 +918,22 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) { Serial.print(addr); Serial.print(F("=>")); Serial.print(_reg, HEX); - Serial.print(F(":")); + Serial.print(F("(T:")); + Serial.print(_regType); + Serial.print(F("):")); Serial.println(value, HEX); - node.writeSingleRegister(_reg, value); + switch (_regType) { + case MODBUS_HOLDING_REG_TYPE: + node.writeSingleRegister(_reg, value); + break; + case MODBUS_COIL_REG_TYPE: + node.writeSingleCoil(_reg, value); + break; + default: + Serial.println(F("Not supported reg type")); + } + modbusBusy = 0; } @@ -1033,6 +1051,7 @@ boolean Item::checkModbusRetry() { if (cmd & CMD_RETRY) { // if last sending attempt of command was failed int val = getVal(); Serial.println(F("Retrying CMD")); + cmd &= ~CMD_RETRY; // Clean retry flag Ctrl(cmd,1,&val); // Execute command again return true; @@ -1043,23 +1062,53 @@ return false; int Item::checkModbusDimmer() { if (modbusBusy) return -1; if (checkModbusRetry()) return -2; + + short numpar = 0; + if ((itemArg->type != aJson_Array) || ((numpar = aJson.getArraySize(itemArg)) < 2)) { + Serial.println(F("Illegal arguments")); + return -3; + } + modbusBusy = 1; uint8_t result; - uint16_t addr = getArg(0); - uint16_t reg = getArg(1); + uint16_t addr = getArg(MODBUS_CMD_ARG_ADDR); + uint16_t reg = getArg(MODBUS_CMD_ARG_REG); + int _regType = MODBUS_HOLDING_REG_TYPE; + if (numpar >= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint; // short mask = getArg(2); + // Serial.print(F("Modbus polling ")); + // Serial.print(addr); + // Serial.print(F("=>")); + // Serial.print(reg, HEX); + // Serial.print(F("(T:")); + // Serial.print(_regType); + // Serial.println(F(")")); int data; //node.setSlave(addr); - modbusSerial.begin(9600, dimPar); + modbusSerial.begin(MODBUS_SERIAL_BAUD, dimPar); node.begin(addr, modbusSerial); - - result = node.readHoldingRegisters(reg, 1); + switch (_regType) { + case MODBUS_HOLDING_REG_TYPE: + result = node.readHoldingRegisters(reg, 1); + break; + case MODBUS_COIL_REG_TYPE: + result = node.readCoils(reg, 1); + break; + case MODBUS_DISCRETE_REG_TYPE: + result = node.readDiscreteInputs(reg, 1); + break; + case MODBUS_INPUT_REG_TYPE: + result = node.readInputRegisters(reg, 1); + break; + default: + Serial.println(F("Not supported reg type")); + } if (result == node.ku8MBSuccess) { data = node.getResponseBuffer(0); diff --git a/lighthub/item.h b/lighthub/item.h index 7a854dd..75d916f 100644 --- a/lighthub/item.h +++ b/lighthub/item.h @@ -53,6 +53,17 @@ e-mail anklimov@gmail.com #define I_CMD 3 //Latest CMD received #define I_EXT 4 //Chanell-depended extension - array +#define MODBUS_CMD_ARG_ADDR 0 +#define MODBUS_CMD_ARG_REG 1 +#define MODBUS_CMD_ARG_MASK 2 +#define MODBUS_CMD_ARG_MAX_SCALE 3 +#define MODBUS_CMD_ARG_REG_TYPE 4 + +#define MODBUS_COIL_REG_TYPE 0 +#define MODBUS_DISCRETE_REG_TYPE 1 +#define MODBUS_HOLDING_REG_TYPE 2 +#define MODBUS_INPUT_REG_TYPE 3 + #include "aJSON.h" extern aJsonObject *items; @@ -114,7 +125,7 @@ class Item protected: int VacomSetFan (int8_t val, int8_t cmd=0); int VacomSetHeat(int addr, int8_t val, int8_t cmd=0); - int modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value); + int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value); void mb_fail(short addr, short op, int val, int cmd); int isActive(); void Parse(); diff --git a/lighthub/options.h b/lighthub/options.h index 31ad60f..87bbde6 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -29,7 +29,9 @@ #define OFFSET_MQTT_PWD OFFSET_CONFIGSERVER+32 #define EEPROM_offset OFFSET_MQTT_PWD+16 +#ifndef INTERVAL_CHECK_INPUT #define INTERVAL_CHECK_INPUT 50 +#endif #define INTERVAL_CHECK_MODBUS 2000 #define INTERVAL_POLLING 100 #define THERMOSTAT_CHECK_PERIOD 5000 @@ -42,7 +44,11 @@ #define MODBUS_SERIAL_BAUD 9600 #endif -#define dimPar SERIAL_8E1 +#ifndef MODBUS_DIMMER_PARAM +#define MODBUS_DIMMER_PARAM SERIAL_8E1 +#endif + +#define dimPar MODBUS_DIMMER_PARAM #define fmPar SERIAL_8N1 #ifndef SERIAL_BAUD From e75813e7212071f4cd4a15eae02e52f3a013c500 Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 18 Oct 2018 22:25:33 +0300 Subject: [PATCH 12/13] modbus merge --- lighthub/item.cpp | 6 +++++- platformio.ini | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 3f5880e..adc0318 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -888,7 +888,11 @@ int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) { modbusBusy = 0; } -int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) { +int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value) { + + if (_regType != MODBUS_COIL_REG_TYPE || _regType != MODBUS_HOLDING_REG_TYPE) { + + } if (modbusBusy) { mb_fail(3, addr, value, 0); diff --git a/platformio.ini b/platformio.ini index 96f7a8e..360efb9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,8 +9,8 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] src_dir = lighthub -;env_default = -; megaatmega2560 +env_default = + megaatmega2560 ; megaatmega2560-net ; due ; esp8266 From 2ff511be35e78d8fbcdb7e99ea137e2a3ebef22a Mon Sep 17 00:00:00 2001 From: livello Date: Thu, 18 Oct 2018 22:33:58 +0300 Subject: [PATCH 13/13] platformio clean --- platformio.ini | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index 360efb9..b902bbb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,8 +9,8 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] src_dir = lighthub -env_default = - megaatmega2560 +;env_default = +; megaatmega2560 ; megaatmega2560-net ; due ; esp8266 @@ -20,10 +20,8 @@ env_default = ; controllino ; stm32 -;build_dir = !sh pioenvs.sh ${platformio.env_default} -;libdeps_dir = !sh piolibdeps.sh ${platformio.env_default} -build_dir = /tmp/pioenvs -libdeps_dir = /tmp/piolibdeps +;build_dir = /tmp/pioenvs +;libdeps_dir = /tmp/piolibdeps [env:esp32] platform = espressif32 @@ -43,7 +41,6 @@ lib_ignore = lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire -; ESP8266HTTPClient Ethernet3 https://github.com/anklimov/aJson https://github.com/anklimov/CmdArduino @@ -111,8 +108,6 @@ lib_deps = https://github.com/anklimov/ModbusMaster https://github.com/anklimov/DMXSerial https://github.com/anklimov/Ethernet -; https://github.com/PaulStoffregen/SPI.git - ;TODO: need to rename SPI lib https://github.com/knolleary/pubsubclient.git https://github.com/anklimov/Artnet.git FastLED @@ -175,7 +170,6 @@ lib_deps = https://github.com/anklimov/ModbusMaster https://github.com/anklimov/DMXSerial https://github.com/anklimov/Ethernet -; https://github.com/PaulStoffregen/SPI.git https://github.com/knolleary/pubsubclient.git https://github.com/anklimov/Artnet.git FastLED @@ -243,7 +237,6 @@ lib_deps = https://github.com/anklimov/ModbusMaster https://github.com/anklimov/DMXSerial https://github.com/anklimov/Ethernet -; https://github.com/PaulStoffregen/SPI.git https://github.com/knolleary/pubsubclient.git https://github.com/anklimov/Artnet.git FastLED