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

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

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

@ -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

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