diff --git a/build_flags_template.sh b/build_flags_template.sh index f8d841b..d8ed177 100644 --- a/build_flags_template.sh +++ b/build_flags_template.sh @@ -1,32 +1,28 @@ #! /bin/bash # usage: # first make your own copy of template -# cp build_flags_template.sh my_build_flags.sh +# cp build_flags_template.sh build_flags_{ENVNAME}.sh # then edit, change or comment something -# nano my_build_flags.sh -# and source it -# source my_build_flags.sh - echo "==============================================Custom build flags are:=====================================================" 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 -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 -DWiz5500" + #export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00" - 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 -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 -DDHT_DISABLE" - export FLAGS="$FLAGS -DRESET_PIN=5" - export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000" - export PLATFORMIO_BUILD_FLAGS="$FLAGS" - echo PLATFORMIO_BUILD_FLAGS=$PLATFORMIO_BUILD_FLAGS - echo "==============================================Custom build flags END=====================================================" - unset FLAGS \ No newline at end of file +# 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 -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 -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) + echo $FLAGS \ No newline at end of file diff --git a/lighthub/dmx.cpp b/lighthub/dmx.cpp index e46d283..d604985 100644 --- a/lighthub/dmx.cpp +++ b/lighthub/dmx.cpp @@ -28,7 +28,7 @@ e-mail anklimov@gmail.com #endif #endif -#if defined(__ESP__) +#if defined(ESP8266) #ifndef DMX_DISABLE DMXESPSerial dmxout; #endif @@ -236,7 +236,7 @@ void DMXoutSetup(int channels) #endif -#if defined(__ESP__) +#if defined(ESP8266) dmxout.init(channels); #endif diff --git a/lighthub/dmx.h b/lighthub/dmx.h index f78ddb7..f879b16 100644 --- a/lighthub/dmx.h +++ b/lighthub/dmx.h @@ -38,7 +38,7 @@ e-mail anklimov@gmail.com #define DmxWrite DmxSimple.write #endif -#if defined(__ESP__) +#if defined(ESP8266) #include extern DMXESPSerial dmxout; #define DmxWrite dmxout.write diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index a27c46c..e274706 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -33,6 +33,14 @@ extern PubSubClient mqttClient; static volatile long encoder_value[6]; #endif +#if defined(ESP8266) +static volatile long encoder_value[6]; +#endif + +#if defined(ARDUINO_ARCH_ESP32) +static volatile long encoder_value[6]; +#endif + #if defined(__SAM3X8E__) static short encoder_irq_map[54]; static long encoder_value[54]; @@ -216,7 +224,7 @@ void Input::dht22Poll() { } void Input::printFloatValueToStr(float temp, char *valstr) { - #if defined(__ESP__) + #if defined(ESP8266) sprintf(valstr, "%2.1f", temp); #endif #if defined(__AVR__) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 1e6b135..f43ab1c 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -186,7 +186,7 @@ void Item::copyPar (aJsonObject *itemV) } */ -#ifdef ESP32 +#if defined(ARDUINO_ARCH_ESP32) void analogWrite(int pin, int val) { //TBD @@ -218,6 +218,7 @@ int Item::Ctrl(char * payload, boolean send){ case -1: //Not known command case -2: //JSON input (not implemented yet break; +#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) case -3: //RGB color in #RRGGBB notation { CRGB rgb; @@ -231,6 +232,7 @@ int Item::Ctrl(char * payload, boolean send){ } break; } +#endif case CMD_ON: // if (item.getEnableCMD(500) || lanStatus == 4) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 41dc504..310a640 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -77,12 +77,20 @@ EthernetClient ethClient; EthernetClient ethClient; #endif -#ifdef __ESP__ +#ifdef ESP8266 #include #include WiFiClient ethClient; #endif +#ifdef ARDUINO_ARCH_ESP32 +#include +#include +#include +#include +WiFiClient ethClient; +#endif + lan_status lanStatus = INITIAL_STATE; const char outprefix[] PROGMEM = OUTTOPIC; @@ -270,7 +278,7 @@ lan_status lanLoop() { { -#ifndef __ESP__ +#if defined(__AVR__) || defined(__SAM3X8E__) wdt_dis(); if (lanStatus > 0) switch (Ethernet.maintain()) { @@ -395,8 +403,7 @@ void ip_ready_config_loaded_connecting_to_broker() { } void onInitialStateInitLAN() { -#ifdef __ESP__ -#ifdef WIFI_MANAGER_DISABLE +#if defined(ESP8266) and defined(WIFI_MANAGER_DISABLE) if(!wifiInitialized) { WiFi.mode(WIFI_STA); Serial.print(F("WIFI AP/Password:")); @@ -408,15 +415,40 @@ void onInitialStateInitLAN() { wifiInitialized = true; } #endif - if (WiFi.status() == WL_CONNECTED) { - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - lanStatus=HAVE_IP_ADDRESS;//1; - } + +#ifdef ARDUINO_ARCH_ESP32 + if(!wifiInitialized) { + WiFi.mode(WIFI_STA); + WiFi.disconnect(); + Serial.print(F("WIFI AP/Password:")); + Serial.print(QUOTE(ESP_WIFI_AP)); + Serial.print(F("/")); + Serial.println(QUOTE(ESP_WIFI_PWD)); + WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD)); + + int wifi_connection_wait = 10000; + while (WiFi.status() != WL_CONNECTED && wifi_connection_wait > 0) { + delay(500); + wifi_connection_wait -= 500; + Serial.print("."); + } + wifiInitialized = true; + } #endif -#if not defined(__ESP__) +#if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266) + if (WiFi.status() == WL_CONNECTED) { + Serial.print(F("WiFi connected. IP address: ")); + Serial.println(WiFi.localIP()); + lanStatus = HAVE_IP_ADDRESS;//1; + } else + { + Serial.println(F("Problem with WiFi connected")); + nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL/5; + } +#endif + + #if defined(__AVR__) || defined(__SAM3X8E__) IPAddress ip, dns, gw, mask; int res = 1; Serial.println(F("Starting lan")); @@ -956,7 +988,7 @@ lan_status getConfig(int arg_cnt, char **args) return READ_RE_CONFIG;//-11; //Load from NVRAM } #endif -#if defined(__ESP__) +#if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266) HTTPClient httpClient; String fullURI = "http://"; fullURI+=configServer; @@ -1047,7 +1079,7 @@ void setup_main() { ArtnetSetup(); #endif -#if defined(__ESP__) and not defined(WIFI_MANAGER_DISABLE) +#if defined(ESP8266) and not defined(WIFI_MANAGER_DISABLE) WiFiManager wifiManager; #if defined(ESP_WIFI_AP) and defined(ESP_WIFI_PWD) wifiManager.autoConnect(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD)); @@ -1060,6 +1092,10 @@ void setup_main() { //TODO: checkForRemoteSketchUpdate(); } +#ifdef MMMMMM +errro!!! +#endif + void printFirmwareVersionAndBuildOptions() { Serial.print(F("\nLazyhome.ru LightHub controller ")); Serial.println(F(QUOTE(PIO_SRC_REV))); diff --git a/lighthub/main.h b/lighthub/main.h index 67088d1..ec5e129 100644 --- a/lighthub/main.h +++ b/lighthub/main.h @@ -14,18 +14,24 @@ #define DHCP_RETRY_INTERVAL 60000 #endif -#if defined(__AVR__) +#if defined(ESP8266) #define wdt_en() wdt_enable(WDTO_8S) #define wdt_dis() wdt_disable() #define wdt_res() wdt_reset() #endif -#if defined(__ESP__) +#ifdef ARDUINO_ARCH_ESP32 #define wdt_res() #define wdt_en() #define wdt_dis() #endif +//#if defined(ESP8266) +//#define wdt_res() +//#define wdt_en() +//#define wdt_dis() +//#endif + #if defined(WATCH_DOG_TICKER_DISABLE) && defined(__AVR__) #define wdt_en() wdt_disable() #define wdt_dis() wdt_disable() @@ -63,16 +69,13 @@ #include #endif -#if defined(__ESP__) +#if defined(ESP8266) #include //this needs to be first, or it all crashes and burns... #include #include - -#ifndef WIFI_MANAGER_DISABLE #include #include #include -#endif #endif @@ -88,11 +91,19 @@ #endif +#if defined(__AVR__) || defined(__SAM3X8E__) || defined(ESP8266) #ifdef Wiz5500 #include #else #include #endif +#endif + +#ifdef ARDUINO_ARCH_ESP32 +#include +#include +#endif + #ifdef _artnet #include @@ -122,12 +133,9 @@ enum lan_status { void mqttCallback(char *topic, byte *payload, unsigned int length); -//#ifndef __ESP__ void printIPAddress(IPAddress ipAddress); -//#endif - void printMACAddress(); void restoreState(); diff --git a/lighthub/options.h b/lighthub/options.h index 0509d12..a3fb25b 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -95,10 +95,6 @@ #define LAN_INIT_DELAY 500 #endif -#if defined(ESP8266) -#define __ESP__ -#endif - #if defined(__AVR__) //All options available #ifdef CONTROLLINO @@ -116,7 +112,7 @@ #define dmxin DmxDue1 #endif -#if defined(__ESP__) +#if defined(ESP8266) #undef _dmxin #undef _modbus #ifndef DMX_DISABLE diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index 0509cf0..5a771c9 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -80,7 +80,7 @@ int getInt(char **chan) { } -#if defined(ESP8266) +#if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266) unsigned long freeRam () {return system_get_free_heap_size();} #endif diff --git a/my_build_flags.py b/my_build_flags.py deleted file mode 100644 index 43992c8..0000000 --- a/my_build_flags.py +++ /dev/null @@ -1,32 +0,0 @@ -# from time import time -# -# from SCons.Script import DefaultEnvironment -# -# print("==============================================Custom build flags are:=====================================================") -# #FLAGS="-MY_CONFIG_SERVER=192.168.10.110" -# #FLAGS+=" -WATCH_DOG_TICKER_DISABLE" -# #FLAGS+=" -USE_1W_PIN=12" -# #FLAGS+=" -SD_CARD_INSERTED" -# #FLAGS+=" -SERIAL_BAUD=115200" -# #FLAGS+=" -Wiz5500" -# #FLAGS+=" -DISABLE_FREERAM_PRINT" -# #FLAGS+=" -CUSTOM_FIRMWARE_MAC=C4:3E:1f:03:1B:1B" -# #FLAGS+=" -DMX_DISABLE" -# FLAGS="MODBUS_DISABLE" -# #FLAGS+=" -OWIRE_DISABLE" -# #FLAGS+=" -ARTNET_ENABLE" -# #FLAGS+=" -CONTROLLINO" -# #FLAGS+=" -AVR_DMXOUT_PIN=18" -# -# print(FLAGS) -# print("==============================================Custom build flags END=====================================================") -# -# env = DefaultEnvironment() -# env.Append(CPPDEFINES=['MODBUS_DISABLE=1']) - -from time import time - -from SCons.Script import DefaultEnvironment - -env = DefaultEnvironment() -env.Append(CPPDEFINES=['BUILD_TIMESTAMP=%d' % time()]) diff --git a/platformio.ini b/platformio.ini index 19eee9e..75db53e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,19 +14,68 @@ env_default = ; megaatmega2560-net ; due ; esp8266 +; esp32 ; megaatmega2560-5500 ; due-5500 ; controllino +; stm32f407 + build_dir = /tmp/pioenvs libdeps_dir = /tmp/piolibdeps +[env:esp32] +platform = espressif32 +framework = arduino +board = pico32 +lib_ldf_mode = chain+ +build_flags = !sh build_flags_esp32.sh +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 + https://github.com/anklimov/ModbusMaster + https://github.com/knolleary/pubsubclient.git + https://github.com/anklimov/Artnet.git + FastLED + Adafruit Unified Sensor + DHT sensor library for ESPx + DHT sensor library + +[env:stm32f407] +platform = ststm32 +framework = arduino +board = genericSTM32F407VET6 +;lib_ldf_mode = chain+ +build_flags = !sh build_flags_stm32f407.sh +lib_deps = + https://github.com/sebnil/DueFlashStorage + https://github.com/anklimov/Arduino-Temperature-Control-Library.git + https://github.com/anklimov/DS2482_OneWire + https://github.com/anklimov/DmxDue + https://github.com/anklimov/ArduinoHttpClient + https://github.com/anklimov/aJson + https://github.com/anklimov/CmdArduino + https://github.com/anklimov/ModbusMaster + https://github.com/anklimov/Ethernet + https://github.com/anklimov/Ethernet2 + https://github.com/knolleary/pubsubclient.git + https://github.com/anklimov/Artnet.git +; FastLED + SD + SdFat + Adafruit Unified Sensor + DHT sensor library + + [env:due] platform = atmelsam framework = arduino board = due lib_ldf_mode = chain+ -extra_scripts = pre:my_build_flags.py -build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) +build_flags = !sh build_flags_due.sh lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -52,7 +101,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 = !sh build_flags_mega2560.sh lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -77,8 +126,7 @@ platform = espressif8266 framework = arduino board = nodemcuv2 lib_ldf_mode = chain+ -build_flags = !echo -n "-DMODBUS_DISABLE -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) -;extra_scripts = pre:my_build_flags.py +build_flags = !sh build_flags_esp8266.sh lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -95,14 +143,13 @@ lib_deps = DHT sensor library WifiManager - [env:megaatmega2560-net] platform = atmelavr board = megaatmega2560 framework = arduino upload_port = net:192.168.88.2:23000 +build_flags = !sh build_flags_mega2560-net.sh ;lib_ldf_mode = chain+ -build_flags = !echo -n "-DPIO_SRC_REV="$(git rev-parse --short HEAD) lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -124,9 +171,7 @@ lib_deps = platform = atmelsam framework = arduino board = due -lib_ldf_mode = chain+ -extra_scripts = pre:my_build_flags.py -build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) +;lib_ldf_mode = chain+ build_flags = -D Wiz5500 -D ARTNET_ENABLE lib_deps = https://github.com/sebnil/DueFlashStorage diff --git a/prepareDue.sh b/prepareDue.sh new file mode 100755 index 0000000..6be6e61 --- /dev/null +++ b/prepareDue.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +sed -i -- 's/void USART0_Handler(void)/void USART0_Handler(void ) __attribute__((weak));\nvoid USART0_Handler(void )/g' ~/.platformio/packages/framework-arduinosam/variants/arduino_due_x/variant.cpp