From 4e2989b02b4c74e1536e748be635cf4ba9f0a4ec Mon Sep 17 00:00:00 2001 From: nitko12 Date: Tue, 18 Aug 2020 12:28:46 +0200 Subject: [PATCH] Stability fix 2.0. --- .../5-Inkplate_svg_designer.ino | 9 ---- .../Network.cpp | 51 ++++++++++++++----- .../Network.cpp | 25 +++++++-- .../3-Crypto_tracker_example.ino | 46 ++++++++--------- .../3-Crypto_tracker_example/Network.cpp | 21 +++++++- .../4-Google_calendar_example/Network.cpp | 26 ++++++++-- 6 files changed, 124 insertions(+), 54 deletions(-) delete mode 100644 examples/1. Basic Inkplate Functionality/5-Inkplate_svg_designer/5-Inkplate_svg_designer.ino diff --git a/examples/1. Basic Inkplate Functionality/5-Inkplate_svg_designer/5-Inkplate_svg_designer.ino b/examples/1. Basic Inkplate Functionality/5-Inkplate_svg_designer/5-Inkplate_svg_designer.ino deleted file mode 100644 index e80ea15..0000000 --- a/examples/1. Basic Inkplate Functionality/5-Inkplate_svg_designer/5-Inkplate_svg_designer.ino +++ /dev/null @@ -1,9 +0,0 @@ -#include "Inkplate.h" - -void setup() { - -} - -void loop() { - -} \ No newline at end of file diff --git a/examples/3. Projects/1-Daily_weather_station_example/Network.cpp b/examples/3. Projects/1-Daily_weather_station_example/Network.cpp index d628b1d..49f2700 100644 --- a/examples/3. Projects/1-Daily_weather_station_example/Network.cpp +++ b/examples/3. Projects/1-Daily_weather_station_example/Network.cpp @@ -11,7 +11,7 @@ StaticJsonDocument<6000> doc; // Declared week days -char weekDays[8][8] ={ +char weekDays[8][8] = { "Mon", "Tue", "Wed", @@ -27,19 +27,22 @@ void Network::begin(char *city) WiFi.mode(WIFI_STA); WiFi.begin(ssid, pass); - if (WiFi.status() != WL_CONNECTED) { - WiFi.reconnect(); + int cnt = 0; + Serial.print(F("Waiting for WiFi to connect...")); + while ((WiFi.status() != WL_CONNECTED)) + { + Serial.print(F(".")); + delay(1000); + ++cnt; - delay(5000); - - Serial.println(F("Waiting for WiFi to reconnect...")); - while ((WiFi.status() != WL_CONNECTED)) + if (cnt == 20) { - // Prints a dot every second that wifi isn't connected - Serial.print(F(".")); - delay(1000); + Serial.println("Can't connect to WIFI, restarting"); + delay(100); + ESP.restart(); } } + Serial.println(F(" connected")); // Find internet time setTime(); @@ -84,20 +87,30 @@ void formatWind(char *str, float wind) dtostrf(wind, 2, 0, str); } -void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *temp4, char *currentTemp, char *currentWind, char *currentTime, char *currentWeather, char *currentWeatherAbbr, char* abbr1, char* abbr2, char* abbr3, char* abbr4) +void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *temp4, char *currentTemp, char *currentWind, char *currentTime, char *currentWeather, char *currentWeatherAbbr, char *abbr1, char *abbr2, char *abbr3, char *abbr4) { - // Reconnect if wifi isn't connected - if (WiFi.status() != WL_CONNECTED) { + // If not connected to wifi reconnect wifi + if (WiFi.status() != WL_CONNECTED) + { WiFi.reconnect(); delay(5000); + int cnt = 0; Serial.println(F("Waiting for WiFi to reconnect...")); while ((WiFi.status() != WL_CONNECTED)) { // Prints a dot every second that wifi isn't connected Serial.print(F(".")); delay(1000); + ++cnt; + + if (cnt == 7) + { + Serial.println("Can't connect to WIFI, restart initiated."); + delay(100); + ESP.restart(); + } } } @@ -215,17 +228,27 @@ void Network::getDays(char *day, char *day1, char *day2, char *day3) void Network::findCity(char *city) { // If not connected to wifi reconnect wifi - if (WiFi.status() != WL_CONNECTED) { + if (WiFi.status() != WL_CONNECTED) + { WiFi.reconnect(); delay(5000); + int cnt = 0; Serial.println(F("Waiting for WiFi to reconnect...")); while ((WiFi.status() != WL_CONNECTED)) { // Prints a dot every second that wifi isn't connected Serial.print(F(".")); delay(1000); + ++cnt; + + if (cnt == 7) + { + Serial.println("Can't connect to WIFI, restart initiated."); + delay(100); + ESP.restart(); + } } } diff --git a/examples/3. Projects/2-Hourly_weather_station_example/Network.cpp b/examples/3. Projects/2-Hourly_weather_station_example/Network.cpp index 74ead23..4c80cda 100644 --- a/examples/3. Projects/2-Hourly_weather_station_example/Network.cpp +++ b/examples/3. Projects/2-Hourly_weather_station_example/Network.cpp @@ -17,12 +17,20 @@ void Network::begin(char *city) WiFi.mode(WIFI_STA); WiFi.begin(ssid, pass); + int cnt = 0; Serial.print(F("Waiting for WiFi to connect...")); while ((WiFi.status() != WL_CONNECTED)) { - //Printing a dot to Serial monitor every second while waiting to connect Serial.print(F(".")); delay(1000); + ++cnt; + + if (cnt == 20) + { + Serial.println("Can't connect to WIFI, restarting"); + delay(100); + ESP.restart(); + } } Serial.println(F(" connected")); @@ -73,17 +81,27 @@ bool Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t { bool f = 0; // If not connected to wifi reconnect wifi - if (WiFi.status() != WL_CONNECTED) { + if (WiFi.status() != WL_CONNECTED) + { WiFi.reconnect(); delay(5000); + int cnt = 0; Serial.println(F("Waiting for WiFi to reconnect...")); while ((WiFi.status() != WL_CONNECTED)) { // Prints a dot every second that wifi isn't connected Serial.print(F(".")); delay(1000); + ++cnt; + + if (cnt == 7) + { + Serial.println("Can't connect to WIFI, restart initiated."); + delay(100); + ESP.restart(); + } } } @@ -152,7 +170,8 @@ bool Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t f = 0; } } - else if (httpCode == 401) { + else if (httpCode == 401) + { display.setCursor(50, 290); display.setTextSize(3); display.print(F("Network error, probably wrong api key")); diff --git a/examples/3. Projects/3-Crypto_tracker_example/3-Crypto_tracker_example.ino b/examples/3. Projects/3-Crypto_tracker_example/3-Crypto_tracker_example.ino index f244d9f..b767e30 100644 --- a/examples/3. Projects/3-Crypto_tracker_example/3-Crypto_tracker_example.ino +++ b/examples/3. Projects/3-Crypto_tracker_example/3-Crypto_tracker_example.ino @@ -92,7 +92,7 @@ char minimum[16]; char maximum[16]; //All months in a year, for finding current date -char *months[] ={ +char *months[] = { "Jan" "Feb", "Mar", @@ -108,27 +108,27 @@ char *months[] ={ }; //Out UI elements data -textElement elements[] ={ - { 50, 130, &Roboto_Light_160, currencyAbbr, 0 }, - { 390, 80, &Roboto_Light_40, date, 0 }, - { 190, 185, &Roboto_Light_40, fromToDate, 0 }, - { 570, 140, &Roboto_Light_40, "Current price:", 0 }, - { 790, 190, &Roboto_Light_40, current, 1 }, - { 630, 275, &Roboto_Light_40, "Minimum:", 0 }, - { 790, 320, &Roboto_Light_40, minimum, 1 }, - { 625, 420, &Roboto_Light_40, "Maximum:", 0 }, - { 790, 466, &Roboto_Light_40, maximum, 1 }, +textElement elements[] = { + {50, 130, &Roboto_Light_160, currencyAbbr, 0}, + {390, 80, &Roboto_Light_40, date, 0}, + {190, 185, &Roboto_Light_40, fromToDate, 0}, + {570, 140, &Roboto_Light_40, "Current price:", 0}, + {790, 190, &Roboto_Light_40, current, 1}, + {630, 275, &Roboto_Light_40, "Minimum:", 0}, + {790, 320, &Roboto_Light_40, minimum, 1}, + {625, 420, &Roboto_Light_40, "Maximum:", 0}, + {790, 466, &Roboto_Light_40, maximum, 1}, - { 18, 570, &Roboto_Light_36, dates, 0 }, - { 122, 570, &Roboto_Light_36, dates + 8, 0 }, - { 227, 570, &Roboto_Light_36, dates + 16, 0 }, - { 342, 570, &Roboto_Light_36, dates + 24, 0 }, - { 466, 570, &Roboto_Light_36, dates + 32, 0 }, + {18, 570, &Roboto_Light_36, dates, 0}, + {122, 570, &Roboto_Light_36, dates + 8, 0}, + {227, 570, &Roboto_Light_36, dates + 16, 0}, + {342, 570, &Roboto_Light_36, dates + 24, 0}, + {466, 570, &Roboto_Light_36, dates + 32, 0}, - { 450, 240, &Roboto_Light_36, prices, 0 }, - { 450, 322, &Roboto_Light_36, prices + 16, 0 }, - { 450, 401, &Roboto_Light_36, prices + 32, 0 }, - { 450, 483, &Roboto_Light_36, prices + 48, 0 }, + {450, 240, &Roboto_Light_36, prices, 0}, + {450, 322, &Roboto_Light_36, prices + 16, 0}, + {450, 401, &Roboto_Light_36, prices + 32, 0}, + {450, 483, &Roboto_Light_36, prices + 48, 0}, }; // Our functions declared below setup and loop @@ -270,9 +270,9 @@ void drawGraph() //Draw a gradient line from every pixel to bottom line in graph line for (int j = 0; j < (x2 - x1 - textMargin) / 31 + 1; ++j) display.drawGradientLine(prev_x + j, - (int)round((double)prev_y + dy * (double)j), - prev_x + j, - y1, 3, 7); + (int)round((double)prev_y + dy * (double)j), + prev_x + j, + y1, 3, 7); } //Set previous x and y diff --git a/examples/3. Projects/3-Crypto_tracker_example/Network.cpp b/examples/3. Projects/3-Crypto_tracker_example/Network.cpp index 51b3508..acaf6e2 100644 --- a/examples/3. Projects/3-Crypto_tracker_example/Network.cpp +++ b/examples/3. Projects/3-Crypto_tracker_example/Network.cpp @@ -26,11 +26,20 @@ void Network::begin() WiFi.mode(WIFI_STA); WiFi.begin(ssid, pass); + int cnt = 0; Serial.print(F("Waiting for WiFi to connect...")); while ((WiFi.status() != WL_CONNECTED)) { Serial.print(F(".")); delay(1000); + ++cnt; + + if (cnt == 20) + { + Serial.println("Can't connect to WIFI, restarting"); + delay(100); + ESP.restart(); + } } Serial.println(F(" connected")); @@ -67,17 +76,27 @@ bool Network::getData(double *data) bool f = 0; // If not connected to wifi reconnect wifi - if (WiFi.status() != WL_CONNECTED) { + if (WiFi.status() != WL_CONNECTED) + { WiFi.reconnect(); delay(5000); + int cnt = 0; Serial.println(F("Waiting for WiFi to reconnect...")); while ((WiFi.status() != WL_CONNECTED)) { // Prints a dot every second that wifi isn't connected Serial.print(F(".")); delay(1000); + ++cnt; + + if (cnt == 7) + { + Serial.println("Can't connect to WIFI, restart initiated."); + delay(100); + ESP.restart(); + } } } diff --git a/examples/3. Projects/4-Google_calendar_example/Network.cpp b/examples/3. Projects/4-Google_calendar_example/Network.cpp index 3edef49..0b7b364 100644 --- a/examples/3. Projects/4-Google_calendar_example/Network.cpp +++ b/examples/3. Projects/4-Google_calendar_example/Network.cpp @@ -4,19 +4,26 @@ #include #include - void Network::begin() { // Initiating wifi, like in BasicHttpClient example WiFi.mode(WIFI_STA); WiFi.begin(ssid, pass); + int cnt = 0; Serial.print(F("Waiting for WiFi to connect...")); while ((WiFi.status() != WL_CONNECTED)) { - // Prints a dot every second that wifi isn't connected Serial.print(F(".")); delay(1000); + ++cnt; + + if (cnt == 20) + { + Serial.println("Can't connect to WIFI, restarting"); + delay(100); + ESP.restart(); + } } Serial.println(F(" connected")); @@ -43,18 +50,29 @@ bool Network::getData(char *data) { // Variable to store fail bool f = 0; + // If not connected to wifi reconnect wifi - if (WiFi.status() != WL_CONNECTED) { + if (WiFi.status() != WL_CONNECTED) + { WiFi.reconnect(); delay(5000); + int cnt = 0; Serial.println(F("Waiting for WiFi to reconnect...")); while ((WiFi.status() != WL_CONNECTED)) { // Prints a dot every second that wifi isn't connected Serial.print(F(".")); delay(1000); + ++cnt; + + if (cnt == 7) + { + Serial.println("Can't connect to WIFI, restart initiated."); + delay(100); + ESP.restart(); + } } } @@ -77,7 +95,7 @@ bool Network::getData(char *data) long n = 0; while (http.getStream().available()) data[n++] = http.getStream().read(); - data[n++]= 0; + data[n++] = 0; } else {