diff --git a/build-flags/build_flags_esp8266-wifi b/build-flags/build_flags_esp8266-wifi index 12eea7e..ca0d4d5 100644 --- a/build-flags/build_flags_esp8266-wifi +++ b/build-flags/build_flags_esp8266-wifi @@ -1,2 +1,3 @@ -DMODBUS_DISABLE #-DCOUNTER_DISABLE +-DOTA diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 31e3200..29ed8e0 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -685,7 +685,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode case CMD_ON: - if (itemType==CH_RGBW && getCmd() == CMD_ON && send /*&& getEnableCMD(500) */) { + if (itemType==CH_RGBW && getCmd() == CMD_ON && send && (chActive>0)/*&& getEnableCMD(500) */) { debugSerial<0) { // Using white DmxWrite(iaddr + 3, map((50 - Par[1]) * Par[2], 0, 5000, 0, 255)); int rgbvLevel = map (Par[1],0,50,0,255*2); @@ -978,8 +978,8 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode //prescaler = 4 ---> PWM frequency is 120 Hz //prescaler = 5 ---> PWM frequency is 30 Hz //prescaler = 6 ---> PWM frequency is <20 Hz - int tval = 7; // this is 111 in binary and is used as an eraser #if defined(__AVR_ATmega2560__) + int tval = 7; // this is 111 in binary and is used as an eraser TCCR4B &= ~tval; // this operation (AND plus NOT), set the three bits in TCCR2B to 0 TCCR3B &= ~tval; tval = 2; @@ -997,9 +997,9 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode VacomSetFan(Par[0], cmd); break; case CH_VCTEMP: { - Item it(itemArg->valuestring); - if (it.isValid() && it.itemType == CH_VC) - VacomSetHeat(it.getArg(), Par[0], cmd); +// Item it(itemArg->valuestring); +// if (it.isValid() && it.itemType == CH_VC) + VacomSetHeat(Par[0], cmd); break; } #endif @@ -1172,8 +1172,8 @@ int Item::modbusDimmerSet(uint16_t value) 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(value, 0, 100, 0, _maxval)); - else modbusDimmerSet(_addr, _reg, _regType, _mask, value); + if (_maxval) return modbusDimmerSet(_addr, _reg, _regType, _mask, map(value, 0, 100, 0, _maxval)); + else return modbusDimmerSet(_addr, _reg, _regType, _mask, value); } } #endif @@ -1221,8 +1221,14 @@ int Item::VacomSetFan(int8_t val, int8_t cmd) { #define a 0.1842f #define b -36.68f -int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) { +int Item::VacomSetHeat(int8_t val, int8_t cmd) { uint8_t result; + int addr; + + Item it(itemArg->valuestring); + if (it.isValid() && it.itemType == CH_VC) addr=it.getArg(); + else return 0; + debugSerial< +#endif #if defined(__SAM3X8E__) DueFlashStorage EEPROM; @@ -301,6 +304,11 @@ lan_status lanLoop() { break; case HAVE_IP_ADDRESS: + #ifdef OTA + // start the OTEthernet library with internal (flash) based storage + ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage); + #endif + if (!configOk) lanStatus = loadConfigFromHttp(0, NULL); else lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER; @@ -308,12 +316,15 @@ lan_status lanLoop() { case IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER: wdt_res(); + + + ip_ready_config_loaded_connecting_to_broker(); break; case RETAINING_COLLECTING: if (millis() > nextLanCheckTime) { - char buf[MQTT_TOPIC_LENGTH]; + char buf[MQTT_TOPIC_LENGTH+1]; //Unsubscribe from status topics.. //strncpy_P(buf, outprefix, sizeof(buf)); @@ -579,7 +590,7 @@ void ip_ready_config_loaded_connecting_to_broker() { // wdt_en(); configOk = true; // ... Temporary subscribe to status topic - char buf[MQTT_TOPIC_LENGTH]; + char buf[MQTT_TOPIC_LENGTH+1]; // strncpy_P(buf, outprefix, sizeof(buf)); setTopic(buf,sizeof(buf),T_OUT); @@ -1641,6 +1652,10 @@ void setupCmdArduino() { } void loop_main() { + #if defined(OTA) + ArduinoOTA.poll(); + #endif + #if defined(M5STACK) // Initialize the M5Stack object M5.update(); diff --git a/lighthub/modules/in_ccs811_hdc1080.cpp b/lighthub/modules/in_ccs811_hdc1080.cpp index 55bd1af..c790b8b 100644 --- a/lighthub/modules/in_ccs811_hdc1080.cpp +++ b/lighthub/modules/in_ccs811_hdc1080.cpp @@ -73,7 +73,7 @@ return 1; void i2cReset(){ Wire.endTransmission(true); -#if defined (ARDUINO_ARCH_ESP8266) +#if defined (SCL_RESET) SCL_LOW(); delay(300); SCL_HIGH(); diff --git a/lighthub/modules/in_ccs811_hdc1080.h b/lighthub/modules/in_ccs811_hdc1080.h index d5433fa..aece938 100644 --- a/lighthub/modules/in_ccs811_hdc1080.h +++ b/lighthub/modules/in_ccs811_hdc1080.h @@ -18,8 +18,17 @@ #define SCL_LOW() (GPES = (1 << twi_scl)) #define SCL_HIGH() (GPEC = (1 << twi_scl)) +#define SCL_RESET #endif +/* +#if defined (__SAM3X8E__) +#define SCL_LOW() digitalWrite(21,LOW) +#define SCL_HIGH() digitalWrite(21,HIGH) +#define SCL_RESET +#endif +*/ + #if defined (ARDUINO_ARCH_ESP32) #undef WAK_PIN //#ifndef WAK_PIN diff --git a/platformio.ini b/platformio.ini index 19150ad..272303f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,7 +29,7 @@ default_envs = ; due-5100 ; Arduino DUE + Ethernet shield Wiznet 5500 -; due-5500 + due-5500 ; ESP 8266 ; esp8266-wifi @@ -86,6 +86,7 @@ lib_ignore = SparkFun CCS811 Arduino Library ESP8266HTTPClient M5Stack + lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -102,6 +103,7 @@ lib_deps = Streaming https://github.com/anklimov/NRFFlashStorage Adafruit NeoPixel + ArduinoOTA ; https://github.com/livello/PrintEx#is-select-redecl @@ -152,6 +154,7 @@ lib_deps = https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library.git M5Stack Adafruit NeoPixel + ArduinoOTA [env:esp32-wifi] platform = espressif32 @@ -200,6 +203,8 @@ lib_deps = ;SparkFun CCS811 Arduino Library https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library.git Adafruit NeoPixel + ArduinoOTA + [env:due-5100] platform = atmelsam framework = arduino @@ -242,6 +247,7 @@ lib_deps = ClosedCube HDC1080 SparkFun CCS811 Arduino Library Adafruit NeoPixel + ArduinoOTA [env:mega2560slim-5100] platform = atmelavr @@ -282,6 +288,7 @@ lib_deps = ClosedCube HDC1080 SparkFun CCS811 Arduino Library Adafruit NeoPixel + ArduinoOTA [env:mega2560-5500] platform = atmelavr @@ -321,12 +328,19 @@ lib_deps = ClosedCube HDC1080 SparkFun CCS811 Arduino Library Adafruit NeoPixel + ArduinoOTA [env:esp8266-wifi] platform = espressif8266 framework = arduino board = nodemcuv2 +upload_protocol = espota +upload_port = Lighthub.local + ;192.168.88.46 +upload_flags = + --auth=password +; --port=65280 build_flags = !python get_build_flags.py esp8266-wifi lib_ignore = DmxSimple @@ -368,6 +382,7 @@ lib_deps = ClosedCube HDC1080 SparkFun CCS811 Arduino Library Adafruit NeoPixel + ArduinoOTA [env:mega2560-5100] platform = atmelavr @@ -409,6 +424,7 @@ lib_deps = ClosedCube HDC1080 SparkFun CCS811 Arduino Library Adafruit NeoPixel + ArduinoOTA [env:due-5500] platform = atmelsam @@ -432,6 +448,7 @@ lib_ignore = ESP_EEPROM EEPROM M5Stack + ArduinoOTA lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -456,6 +473,7 @@ lib_deps = SparkFun CCS811 Arduino Library Adafruit NeoPixel + [env:lighthub21] platform = atmelsam framework = arduino @@ -500,6 +518,7 @@ lib_deps = ClosedCube HDC1080 SparkFun CCS811 Arduino Library Adafruit NeoPixel + ArduinoOTA [env:controllino] @@ -542,6 +561,7 @@ lib_deps = ClosedCube HDC1080 SparkFun CCS811 Arduino Library Adafruit NeoPixel + ArduinoOTA [env:stm32-enc2860] platform = ststm32 @@ -588,3 +608,4 @@ lib_deps = UIPEthernet https://github.com/anklimov/NRFFlashStorage Adafruit NeoPixel + ArduinoOTA