From 7817422e1d1737da9d5ad8d903b93e561776ad2d Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 26 Jan 2020 15:50:13 +0100 Subject: [PATCH 1/6] Added platform support for ttgo-lora32-v1 --- .gitignore | 5 +++++ .vscode/extensions.json | 7 +++++++ platformio.ini | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 platformio.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..272828b --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..903e320 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,24 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = + ttgo-lora32-v1 + +lib_dir = libraries +src_dir = ESP-sc-gway + +[env] +platform = espressif32 +framework = arduino +monitor_speed = 115200 + +[env:ttgo-lora32-v1] +board = ttgo-lora32-v1 + From 1689f35195af2c39b647d86ebe250061f5b55736 Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 26 Jan 2020 15:50:13 +0100 Subject: [PATCH 2/6] Added platformio support for ttgo-lora32-v1 --- .gitignore | 5 +++++ .vscode/extensions.json | 7 +++++++ platformio.ini | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 platformio.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..272828b --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..903e320 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,24 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = + ttgo-lora32-v1 + +lib_dir = libraries +src_dir = ESP-sc-gway + +[env] +platform = espressif32 +framework = arduino +monitor_speed = 115200 + +[env:ttgo-lora32-v1] +board = ttgo-lora32-v1 + From 34711f2dad4e62bcba9a59a5659cd1ce8dae02fa Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 26 Jan 2020 16:12:49 +0100 Subject: [PATCH 3/6] Added possibility to set Static IP instead DHCP --- ESP-sc-gway/_WiFi.ino | 17 +++++++++++++++++ ESP-sc-gway/configNode.h | 14 +++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ESP-sc-gway/_WiFi.ino b/ESP-sc-gway/_WiFi.ino index 995f870..82cf64c 100644 --- a/ESP-sc-gway/_WiFi.ino +++ b/ESP-sc-gway/_WiFi.ino @@ -194,6 +194,13 @@ int wifiMgr() // because WiFi problems would make webserver (which works on WiFi) useless. // ---------------------------------------------------------------------------- int WlanConnect(int maxTry) { + + #if USE_STATIC_IP==1 + IPAddress local_IP(_STATIC_IP); + IPAddress subnet(_SUBNET_MASK); + IPAddress gateway(_GATEWAY_IP); + IPAddress primaryDNS(_DNS_IP); + #endif unsigned char agains = 0; unsigned char wpa_index = 0; @@ -237,6 +244,16 @@ int WlanConnect(int maxTry) { WiFi.mode(WIFI_STA); delay(1000); + + #if USE_STATIC_IP==1 + WiFi.config(local_IP, gateway, subnet, primaryDNS); +# if _MONITOR>=1 + if ( debug>=0 ) { + Serial.println(F("Using Static IP")); + } +# endif + #endif + WiFi.begin(ssid, password); delay(8000); diff --git a/ESP-sc-gway/configNode.h b/ESP-sc-gway/configNode.h index 1e3c1f1..99cc053 100644 --- a/ESP-sc-gway/configNode.h +++ b/ESP-sc-gway/configNode.h @@ -126,13 +126,25 @@ wpas wpa[] = { }; +// Static IP +// If you would use static IP instead Dynamic IP (DHCP) +// flasg this as 1 and set IP, Subnet mask, Gateway IP and DNS +#define USE_STATIC_IP 1 + +#if USE_STATIC_IP==1 +#define _STATIC_IP { 192, 168, 100, 254 } +#define _SUBNET_MASK { 255, 255, 255, 0 } +#define _GATEWAY_IP { 192, 168, 100, 1 } +#define _DNS_IP { 8, 8, 8, 8 } +#endif + + // Define the name of the accesspoint if the gateway is in accesspoint mode (is // getting WiFi SSID and password using WiFiManager) #define AP_NAME "ESP8266-Gway-Things4U" #define AP_PASSWD "ttnAutoPw" - // For asserting and testing the following defines are used. // #if !defined(CFG_noassert) From 6e4a21a138bdd469a592c8380c1a371b803a860b Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 26 Jan 2020 16:42:34 +0100 Subject: [PATCH 4/6] Added possibility to use a led for notification status --- ESP-sc-gway/ESP-sc-gway.ino | 31 +++++++++++++++++++++++++++++++ ESP-sc-gway/_WiFi.ino | 12 ++++++++++++ ESP-sc-gway/configGway.h | 4 ++++ 3 files changed, 47 insertions(+) diff --git a/ESP-sc-gway/ESP-sc-gway.ino b/ESP-sc-gway/ESP-sc-gway.ino index ffc4077..adde349 100644 --- a/ESP-sc-gway/ESP-sc-gway.ino +++ b/ESP-sc-gway/ESP-sc-gway.ino @@ -255,6 +255,33 @@ void pullData(); // _udpSemtech.ino void ICACHE_FLASH_ATTR ReleaseMutex(int *mutex); #endif +#if USE_STATUS_LED==1 + void blink_led (uint32_t delay_time, uint8_t times); +#endif + +// ---------------------------------------------------------------------------- +// Blink STATUS led +// ---------------------------------------------------------------------------- +#if USE_STATUS_LED==1 + void blink_led (uint32_t delay_time=1000, uint8_t times=1) + { + for(uint8_t i=0; i=1 Serial.begin(_BAUDRATE); // As fast as possible for bus delay(500); diff --git a/ESP-sc-gway/_WiFi.ino b/ESP-sc-gway/_WiFi.ino index 82cf64c..a29af37 100644 --- a/ESP-sc-gway/_WiFi.ino +++ b/ESP-sc-gway/_WiFi.ino @@ -215,6 +215,12 @@ int WlanConnect(int maxTry) { while ( (WiFi.status() != WL_CONNECTED) && (( i<= maxTry ) || (maxTry==0)) ) { +# if USE_STATUS_LED==1 +# if _STATUS_LED_ON_WL_CONNECTED==1 + digitalWrite(_STATUS_LED_PIN, 0); +# endif +# endif + // We try every SSID in wpa array until success for (int j=wpa_index; (j< (sizeof(wpa)/sizeof(wpa[0]))) && (WiFi.status() != WL_CONNECTED ); j++) { @@ -263,6 +269,12 @@ int WlanConnect(int maxTry) { // -1 = No SSID or other cause int stat = WlanStatus(); if ( stat == 1) { +# if USE_STATUS_LED==1 +# if _STATUS_LED_ON_WL_CONNECTED==1 + digitalWrite(_STATUS_LED_PIN, 1); +# endif +# endif + writeGwayCfg(CONFIGFILE, &gwayConfig ); // Write configuration to SPIFFS return(1); } diff --git a/ESP-sc-gway/configGway.h b/ESP-sc-gway/configGway.h index 8410365..287d6d0 100644 --- a/ESP-sc-gway/configGway.h +++ b/ESP-sc-gway/configGway.h @@ -308,3 +308,7 @@ #define _TTNPORT 1700 // Standard port for TTN +// Use led for status notification +#define USE_STATUS_LED 1 +#define _STATUS_LED_PIN BUILTIN_LED +#define _STATUS_LED_ON_WL_CONNECTED 1 \ No newline at end of file From aa25469c0a499ceb762313d5aea79f0ac9e04473 Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 26 Jan 2020 16:53:32 +0100 Subject: [PATCH 5/6] Added a status blink on sending pull_data message to server --- ESP-sc-gway/_udpSemtech.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ESP-sc-gway/_udpSemtech.ino b/ESP-sc-gway/_udpSemtech.ino index 5cf6f7b..4c7e223 100644 --- a/ESP-sc-gway/_udpSemtech.ino +++ b/ESP-sc-gway/_udpSemtech.ino @@ -456,6 +456,10 @@ void pullData() { sendUdp(thingServer, _THINGPORT, pullDataReq, pullIndex); #endif +#if USE_STATUS_LED==1 + blink_led(500, 4); +#endif + #if _DUSB>=1 if (( debug>=2 ) && ( pdebug & P_MAIN )) { yield(); From 36c4e476a5682bde7e8e22de7cd0d849e93f7b04 Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 26 Jan 2020 17:09:38 +0100 Subject: [PATCH 6/6] Fix error - missing # for else in _GATEWAYMGT in udpSemtech --- ESP-sc-gway/_udpSemtech.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ESP-sc-gway/_udpSemtech.ino b/ESP-sc-gway/_udpSemtech.ino index 4c7e223..61c7f83 100644 --- a/ESP-sc-gway/_udpSemtech.ino +++ b/ESP-sc-gway/_udpSemtech.ino @@ -307,7 +307,7 @@ int readUdp(int packetSize) # if _GATEWAYMGT==1 // For simplicity, we send the first 4 bytes too gateway_mgt(packetSize, buff_down); - else +# else # endif # if _MONITOR>=1