Stability fix 2.0.
This commit is contained in:
parent
7709a4e863
commit
4e2989b02b
|
@ -1,9 +0,0 @@
|
||||||
#include "Inkplate.h"
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,7 +11,7 @@
|
||||||
StaticJsonDocument<6000> doc;
|
StaticJsonDocument<6000> doc;
|
||||||
|
|
||||||
// Declared week days
|
// Declared week days
|
||||||
char weekDays[8][8] ={
|
char weekDays[8][8] = {
|
||||||
"Mon",
|
"Mon",
|
||||||
"Tue",
|
"Tue",
|
||||||
"Wed",
|
"Wed",
|
||||||
|
@ -27,19 +27,22 @@ void Network::begin(char *city)
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, pass);
|
WiFi.begin(ssid, pass);
|
||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
int cnt = 0;
|
||||||
WiFi.reconnect();
|
Serial.print(F("Waiting for WiFi to connect..."));
|
||||||
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
|
{
|
||||||
|
Serial.print(F("."));
|
||||||
|
delay(1000);
|
||||||
|
++cnt;
|
||||||
|
|
||||||
delay(5000);
|
if (cnt == 20)
|
||||||
|
|
||||||
Serial.println(F("Waiting for WiFi to reconnect..."));
|
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
|
||||||
{
|
{
|
||||||
// Prints a dot every second that wifi isn't connected
|
Serial.println("Can't connect to WIFI, restarting");
|
||||||
Serial.print(F("."));
|
delay(100);
|
||||||
delay(1000);
|
ESP.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Serial.println(F(" connected"));
|
||||||
|
|
||||||
// Find internet time
|
// Find internet time
|
||||||
setTime();
|
setTime();
|
||||||
|
@ -84,20 +87,30 @@ void formatWind(char *str, float wind)
|
||||||
dtostrf(wind, 2, 0, str);
|
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 not connected to wifi reconnect wifi
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
WiFi.reconnect();
|
WiFi.reconnect();
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
Serial.println(F("Waiting for WiFi to reconnect..."));
|
Serial.println(F("Waiting for WiFi to reconnect..."));
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
{
|
{
|
||||||
// Prints a dot every second that wifi isn't connected
|
// Prints a dot every second that wifi isn't connected
|
||||||
Serial.print(F("."));
|
Serial.print(F("."));
|
||||||
delay(1000);
|
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)
|
void Network::findCity(char *city)
|
||||||
{
|
{
|
||||||
// If not connected to wifi reconnect wifi
|
// If not connected to wifi reconnect wifi
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
WiFi.reconnect();
|
WiFi.reconnect();
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
Serial.println(F("Waiting for WiFi to reconnect..."));
|
Serial.println(F("Waiting for WiFi to reconnect..."));
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
{
|
{
|
||||||
// Prints a dot every second that wifi isn't connected
|
// Prints a dot every second that wifi isn't connected
|
||||||
Serial.print(F("."));
|
Serial.print(F("."));
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
++cnt;
|
||||||
|
|
||||||
|
if (cnt == 7)
|
||||||
|
{
|
||||||
|
Serial.println("Can't connect to WIFI, restart initiated.");
|
||||||
|
delay(100);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,20 @@ void Network::begin(char *city)
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, pass);
|
WiFi.begin(ssid, pass);
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
Serial.print(F("Waiting for WiFi to connect..."));
|
Serial.print(F("Waiting for WiFi to connect..."));
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
{
|
{
|
||||||
//Printing a dot to Serial monitor every second while waiting to connect
|
|
||||||
Serial.print(F("."));
|
Serial.print(F("."));
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
++cnt;
|
||||||
|
|
||||||
|
if (cnt == 20)
|
||||||
|
{
|
||||||
|
Serial.println("Can't connect to WIFI, restarting");
|
||||||
|
delay(100);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Serial.println(F(" connected"));
|
Serial.println(F(" connected"));
|
||||||
|
|
||||||
|
@ -73,17 +81,27 @@ bool Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t
|
||||||
{
|
{
|
||||||
bool f = 0;
|
bool f = 0;
|
||||||
// If not connected to wifi reconnect wifi
|
// If not connected to wifi reconnect wifi
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
WiFi.reconnect();
|
WiFi.reconnect();
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
Serial.println(F("Waiting for WiFi to reconnect..."));
|
Serial.println(F("Waiting for WiFi to reconnect..."));
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
{
|
{
|
||||||
// Prints a dot every second that wifi isn't connected
|
// Prints a dot every second that wifi isn't connected
|
||||||
Serial.print(F("."));
|
Serial.print(F("."));
|
||||||
delay(1000);
|
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;
|
f = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (httpCode == 401) {
|
else if (httpCode == 401)
|
||||||
|
{
|
||||||
display.setCursor(50, 290);
|
display.setCursor(50, 290);
|
||||||
display.setTextSize(3);
|
display.setTextSize(3);
|
||||||
display.print(F("Network error, probably wrong api key"));
|
display.print(F("Network error, probably wrong api key"));
|
||||||
|
|
|
@ -92,7 +92,7 @@ char minimum[16];
|
||||||
char maximum[16];
|
char maximum[16];
|
||||||
|
|
||||||
//All months in a year, for finding current date
|
//All months in a year, for finding current date
|
||||||
char *months[] ={
|
char *months[] = {
|
||||||
"Jan"
|
"Jan"
|
||||||
"Feb",
|
"Feb",
|
||||||
"Mar",
|
"Mar",
|
||||||
|
@ -108,27 +108,27 @@ char *months[] ={
|
||||||
};
|
};
|
||||||
|
|
||||||
//Out UI elements data
|
//Out UI elements data
|
||||||
textElement elements[] ={
|
textElement elements[] = {
|
||||||
{ 50, 130, &Roboto_Light_160, currencyAbbr, 0 },
|
{50, 130, &Roboto_Light_160, currencyAbbr, 0},
|
||||||
{ 390, 80, &Roboto_Light_40, date, 0 },
|
{390, 80, &Roboto_Light_40, date, 0},
|
||||||
{ 190, 185, &Roboto_Light_40, fromToDate, 0 },
|
{190, 185, &Roboto_Light_40, fromToDate, 0},
|
||||||
{ 570, 140, &Roboto_Light_40, "Current price:", 0 },
|
{570, 140, &Roboto_Light_40, "Current price:", 0},
|
||||||
{ 790, 190, &Roboto_Light_40, current, 1 },
|
{790, 190, &Roboto_Light_40, current, 1},
|
||||||
{ 630, 275, &Roboto_Light_40, "Minimum:", 0 },
|
{630, 275, &Roboto_Light_40, "Minimum:", 0},
|
||||||
{ 790, 320, &Roboto_Light_40, minimum, 1 },
|
{790, 320, &Roboto_Light_40, minimum, 1},
|
||||||
{ 625, 420, &Roboto_Light_40, "Maximum:", 0 },
|
{625, 420, &Roboto_Light_40, "Maximum:", 0},
|
||||||
{ 790, 466, &Roboto_Light_40, maximum, 1 },
|
{790, 466, &Roboto_Light_40, maximum, 1},
|
||||||
|
|
||||||
{ 18, 570, &Roboto_Light_36, dates, 0 },
|
{18, 570, &Roboto_Light_36, dates, 0},
|
||||||
{ 122, 570, &Roboto_Light_36, dates + 8, 0 },
|
{122, 570, &Roboto_Light_36, dates + 8, 0},
|
||||||
{ 227, 570, &Roboto_Light_36, dates + 16, 0 },
|
{227, 570, &Roboto_Light_36, dates + 16, 0},
|
||||||
{ 342, 570, &Roboto_Light_36, dates + 24, 0 },
|
{342, 570, &Roboto_Light_36, dates + 24, 0},
|
||||||
{ 466, 570, &Roboto_Light_36, dates + 32, 0 },
|
{466, 570, &Roboto_Light_36, dates + 32, 0},
|
||||||
|
|
||||||
{ 450, 240, &Roboto_Light_36, prices, 0 },
|
{450, 240, &Roboto_Light_36, prices, 0},
|
||||||
{ 450, 322, &Roboto_Light_36, prices + 16, 0 },
|
{450, 322, &Roboto_Light_36, prices + 16, 0},
|
||||||
{ 450, 401, &Roboto_Light_36, prices + 32, 0 },
|
{450, 401, &Roboto_Light_36, prices + 32, 0},
|
||||||
{ 450, 483, &Roboto_Light_36, prices + 48, 0 },
|
{450, 483, &Roboto_Light_36, prices + 48, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Our functions declared below setup and loop
|
// 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
|
//Draw a gradient line from every pixel to bottom line in graph line
|
||||||
for (int j = 0; j < (x2 - x1 - textMargin) / 31 + 1; ++j)
|
for (int j = 0; j < (x2 - x1 - textMargin) / 31 + 1; ++j)
|
||||||
display.drawGradientLine(prev_x + j,
|
display.drawGradientLine(prev_x + j,
|
||||||
(int)round((double)prev_y + dy * (double)j),
|
(int)round((double)prev_y + dy * (double)j),
|
||||||
prev_x + j,
|
prev_x + j,
|
||||||
y1, 3, 7);
|
y1, 3, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set previous x and y
|
//Set previous x and y
|
||||||
|
|
|
@ -26,11 +26,20 @@ void Network::begin()
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, pass);
|
WiFi.begin(ssid, pass);
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
Serial.print(F("Waiting for WiFi to connect..."));
|
Serial.print(F("Waiting for WiFi to connect..."));
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
{
|
{
|
||||||
Serial.print(F("."));
|
Serial.print(F("."));
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
++cnt;
|
||||||
|
|
||||||
|
if (cnt == 20)
|
||||||
|
{
|
||||||
|
Serial.println("Can't connect to WIFI, restarting");
|
||||||
|
delay(100);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Serial.println(F(" connected"));
|
Serial.println(F(" connected"));
|
||||||
|
|
||||||
|
@ -67,17 +76,27 @@ bool Network::getData(double *data)
|
||||||
bool f = 0;
|
bool f = 0;
|
||||||
|
|
||||||
// If not connected to wifi reconnect wifi
|
// If not connected to wifi reconnect wifi
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
WiFi.reconnect();
|
WiFi.reconnect();
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
Serial.println(F("Waiting for WiFi to reconnect..."));
|
Serial.println(F("Waiting for WiFi to reconnect..."));
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
{
|
{
|
||||||
// Prints a dot every second that wifi isn't connected
|
// Prints a dot every second that wifi isn't connected
|
||||||
Serial.print(F("."));
|
Serial.print(F("."));
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
++cnt;
|
||||||
|
|
||||||
|
if (cnt == 7)
|
||||||
|
{
|
||||||
|
Serial.println("Can't connect to WIFI, restart initiated.");
|
||||||
|
delay(100);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,26 @@
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <WiFiClientSecure.h>
|
#include <WiFiClientSecure.h>
|
||||||
|
|
||||||
|
|
||||||
void Network::begin()
|
void Network::begin()
|
||||||
{
|
{
|
||||||
// Initiating wifi, like in BasicHttpClient example
|
// Initiating wifi, like in BasicHttpClient example
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, pass);
|
WiFi.begin(ssid, pass);
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
Serial.print(F("Waiting for WiFi to connect..."));
|
Serial.print(F("Waiting for WiFi to connect..."));
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
{
|
{
|
||||||
// Prints a dot every second that wifi isn't connected
|
|
||||||
Serial.print(F("."));
|
Serial.print(F("."));
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
++cnt;
|
||||||
|
|
||||||
|
if (cnt == 20)
|
||||||
|
{
|
||||||
|
Serial.println("Can't connect to WIFI, restarting");
|
||||||
|
delay(100);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Serial.println(F(" connected"));
|
Serial.println(F(" connected"));
|
||||||
|
|
||||||
|
@ -43,18 +50,29 @@ bool Network::getData(char *data)
|
||||||
{
|
{
|
||||||
// Variable to store fail
|
// Variable to store fail
|
||||||
bool f = 0;
|
bool f = 0;
|
||||||
|
|
||||||
// If not connected to wifi reconnect wifi
|
// If not connected to wifi reconnect wifi
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
WiFi.reconnect();
|
WiFi.reconnect();
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
Serial.println(F("Waiting for WiFi to reconnect..."));
|
Serial.println(F("Waiting for WiFi to reconnect..."));
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while ((WiFi.status() != WL_CONNECTED))
|
||||||
{
|
{
|
||||||
// Prints a dot every second that wifi isn't connected
|
// Prints a dot every second that wifi isn't connected
|
||||||
Serial.print(F("."));
|
Serial.print(F("."));
|
||||||
delay(1000);
|
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;
|
long n = 0;
|
||||||
while (http.getStream().available())
|
while (http.getStream().available())
|
||||||
data[n++] = http.getStream().read();
|
data[n++] = http.getStream().read();
|
||||||
data[n++]= 0;
|
data[n++] = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue