Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some usefull features: Platformio + Static IP + LED Notification Status #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
31 changes: 31 additions & 0 deletions ESP-sc-gway/ESP-sc-gway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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<times; i++)
{
digitalWrite(_STATUS_LED_PIN, HIGH);
delay(delay_time);
digitalWrite(_STATUS_LED_PIN, LOW);
delay(delay_time);
}

#if _STATUS_LED_ON_WL_CONNECTED==1
if (WiFi.status() == WL_CONNECTED)
{
digitalWrite(_STATUS_LED_PIN, HIGH);
}
#endif
}
#endif



// ============================================================================
Expand All @@ -271,6 +298,10 @@ void setup() {
MAC_char[18] = 0;
char hostname[12]; // hostname space

# if USE_STATUS_LED==1
pinMode(_STATUS_LED_PIN, OUTPUT);
# endif

# if _DUSB>=1
Serial.begin(_BAUDRATE); // As fast as possible for bus
delay(500);
Expand Down
29 changes: 29 additions & 0 deletions ESP-sc-gway/_WiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++)
{
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
6 changes: 5 additions & 1 deletion ESP-sc-gway/_udpSemtech.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions ESP-sc-gway/configGway.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 13 additions & 1 deletion ESP-sc-gway/configNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -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