Stability fix 2.0.

This commit is contained in:
nitko12 2020-08-18 12:28:46 +02:00
parent 7709a4e863
commit 4e2989b02b
6 changed files with 124 additions and 54 deletions

View File

@ -1,9 +0,0 @@
#include "Inkplate.h"
void setup() {
}
void loop() {
}

View File

@ -27,19 +27,22 @@ void Network::begin(char *city)
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
if (WiFi.status() != WL_CONNECTED) {
WiFi.reconnect();
delay(5000);
Serial.println(F("Waiting for WiFi to reconnect..."));
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"));
// Find internet time
setTime();
@ -86,18 +89,28 @@ void formatWind(char *str, float wind)
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();
}
}
}

View File

@ -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"));

View File

@ -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();
}
}
}

View File

@ -4,19 +4,26 @@
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
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();
}
}
}