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/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 995f870..a29af37 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; @@ -208,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++) { @@ -237,6 +250,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); @@ -246,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/_udpSemtech.ino b/ESP-sc-gway/_udpSemtech.ino index 5cf6f7b..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 @@ -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(); 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 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) 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 +