Many fixes.

This commit is contained in:
nitko12 2020-08-06 14:43:47 +02:00
parent f012be658b
commit d5826251bf
11 changed files with 1412 additions and 1377 deletions

View File

@ -261,12 +261,12 @@ void Inkplate::drawBitmap3Bit(int16_t _x, int16_t _y, const unsigned char *_p, i
{ {
for (j = 0; j < xSize - 1; j++) for (j = 0; j < xSize - 1; j++)
{ {
drawPixel((j * 2) + _x, i + _y, (*(_p + xSize * (i) + j) >> 4) >> 1); drawPixel((j * 2) + _x, i + _y, (*(_p + xSize * (i)+j) >> 4) >> 1);
drawPixel((j * 2) + 1 + _x, i + _y, (*(_p + xSize * (i) + j) & 0xff) >> 1); drawPixel((j * 2) + 1 + _x, i + _y, (*(_p + xSize * (i)+j) & 0xff) >> 1);
} }
drawPixel((j * 2) + _x, i + _y, (*(_p + xSize * (i) + j) >> 4) >> 1); drawPixel((j * 2) + _x, i + _y, (*(_p + xSize * (i)+j) >> 4) >> 1);
if (_rem == 0) if (_rem == 0)
drawPixel((j * 2) + 1 + _x, i + _y, (*(_p + xSize * (i) + j) & 0xff) >> 1); drawPixel((j * 2) + 1 + _x, i + _y, (*(_p + xSize * (i)+j) & 0xff) >> 1);
} }
} }

View File

@ -160,19 +160,19 @@ public:
uint8_t *_partial; uint8_t *_partial;
uint8_t *D_memory4Bit; uint8_t *D_memory4Bit;
uint8_t *_pBuffer; uint8_t *_pBuffer;
const uint8_t LUT2[16] = {B10101010, B10101001, B10100110, B10100101, B10011010, B10011001, B10010110, B10010101, B01101010, B01101001, B01100110, B01100101, B01011010, B01011001, B01010110, B01010101}; const uint8_t LUT2[16] ={ B10101010, B10101001, B10100110, B10100101, B10011010, B10011001, B10010110, B10010101, B01101010, B01101001, B01100110, B01100101, B01011010, B01011001, B01010110, B01010101 };
const uint8_t LUTW[16] = {B11111111, B11111110, B11111011, B11111010, B11101111, B11101110, B11101011, B11101010, B10111111, B10111110, B10111011, B10111010, B10101111, B10101110, B10101011, B10101010}; const uint8_t LUTW[16] ={ B11111111, B11111110, B11111011, B11111010, B11101111, B11101110, B11101011, B11101010, B10111111, B10111110, B10111011, B10111010, B10101111, B10101110, B10101011, B10101010 };
const uint8_t LUTB[16] = {B11111111, B11111101, B11110111, B11110101, B11011111, B11011101, B11010111, B11010101, B01111111, B01111101, B01110111, B01110101, B01011111, B01011101, B01010111, B01010101}; const uint8_t LUTB[16] ={ B11111111, B11111101, B11110111, B11110101, B11011111, B11011101, B11010111, B11010101, B01111111, B01111101, B01110111, B01110101, B01011111, B01011101, B01010111, B01010101 };
const uint8_t pixelMaskLUT[8] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000}; const uint8_t pixelMaskLUT[8] ={ B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 };
const uint8_t pixelMaskGLUT[2] = {B00001111, B11110000}; const uint8_t pixelMaskGLUT[2] ={ B00001111, B11110000 };
const uint8_t discharge[16] = {B11111111, B11111100, B11110011, B11110000, B11001111, B11001100, B11000011, B11000000, B00111111, B00111100, B00110011, B00110000, B00001111, B00001100, B00000011, B00000000}; const uint8_t discharge[16] ={ B11111111, B11111100, B11110011, B11110000, B11001111, B11001100, B11000011, B11000000, B00111111, B00111100, B00110011, B00110000, B00001111, B00001100, B00000011, B00000000 };
//BLACK->WHITE //BLACK->WHITE
//THIS IS OKAYISH WAVEFORM FOR GRAYSCALE. IT CAN BE MUCH BETTER. //THIS IS OKAYISH WAVEFORM FOR GRAYSCALE. IT CAN BE MUCH BETTER.
const uint8_t waveform3Bit[8][7] = {{0, 0, 0, 0, 1, 1, 1}, {0, 0, 1, 1, 1, 2, 1}, {0, 1, 1, 2, 1, 2, 1}, {0, 0, 1, 1, 2, 1, 2}, {1, 1, 1, 2, 2, 1, 2}, {0, 0, 1, 1, 1, 2, 2}, {0, 1, 1, 2, 1, 2, 2}, {0, 0, 0, 0, 0, 0, 2}}; const uint8_t waveform3Bit[8][7] ={ { 0, 0, 0, 0, 1, 1, 1 }, { 0, 0, 1, 1, 1, 2, 1 }, { 0, 1, 1, 2, 1, 2, 1 }, { 0, 0, 1, 1, 2, 1, 2 }, { 1, 1, 1, 2, 2, 1, 2 }, { 0, 0, 1, 1, 1, 2, 2 }, { 0, 1, 1, 2, 1, 2, 2 }, { 0, 0, 0, 0, 0, 0, 2 } };
//const uint8_t waveform3Bit[8][12] = {{3,3,3,1,1,1,1,1,1,1,2,0}, {3,3,3,3,1,1,1,1,1,1,2,0}, {3,3,3,3,3,1,1,1,1,1,2,0}, {3,3,3,3,3,3,1,1,1,1,2,0}, {3,3,3,3,3,3,3,1,1,1,2,0}, {3,3,3,3,3,3,3,2,1,1,2,0}, {3,3,3,3,3,3,3,3,3,1,2,0}, {3,3,3,3,3,3,3,3,3,3,2,0}}; //const uint8_t waveform3Bit[8][12] = {{3,3,3,1,1,1,1,1,1,1,2,0}, {3,3,3,3,1,1,1,1,1,1,2,0}, {3,3,3,3,3,1,1,1,1,1,2,0}, {3,3,3,3,3,3,1,1,1,1,2,0}, {3,3,3,3,3,3,3,1,1,1,2,0}, {3,3,3,3,3,3,3,2,1,1,2,0}, {3,3,3,3,3,3,3,3,3,1,2,0}, {3,3,3,3,3,3,3,3,3,3,2,0}};
//const uint8_t waveform3Bit[16][12] = {{0,0,0,0,0,0,1,2,1,1,0,3},{0,0,1,1,1,2,2,2,1,1,0,3},{0,0,0,1,1,2,2,2,1,1,0,3}, {0,0,0,1,2,1,2,1,2,1,3}, {0,0,2,1,2,1,2,1,2,1,3}, {0,0,1,2,2,1,1,1,1,2,0,3}, {0,0,0,2,1,1,1,1,0,2,0,3}, {0,0,2,1,2,2,1,1,1,2,0,3}, {0,0,0,2,2,2,1,1,1,2,0,3}, {0,0,0,0,0,0,2,1,1,2,0,3}, {0,0,0,0,0,2,2,1,1,2,0,3}, {0,0,0,0,0,1,1,1,2,2,0,3}, {0,0,0,0,1,2,1,2,1,2,0,3}, {0,0,0,0,1,1,2,2,1,2,0,3},{0,0,0,0,1,1,1,2,2,2,0,3}, {0,0,0,0,0,0,0,0,0,2,0,3}}; //const uint8_t waveform3Bit[16][12] = {{0,0,0,0,0,0,1,2,1,1,0,3},{0,0,1,1,1,2,2,2,1,1,0,3},{0,0,0,1,1,2,2,2,1,1,0,3}, {0,0,0,1,2,1,2,1,2,1,3}, {0,0,2,1,2,1,2,1,2,1,3}, {0,0,1,2,2,1,1,1,1,2,0,3}, {0,0,0,2,1,1,1,1,0,2,0,3}, {0,0,2,1,2,2,1,1,1,2,0,3}, {0,0,0,2,2,2,1,1,1,2,0,3}, {0,0,0,0,0,0,2,1,1,2,0,3}, {0,0,0,0,0,2,2,1,1,2,0,3}, {0,0,0,0,0,1,1,1,2,2,0,3}, {0,0,0,0,1,2,1,2,1,2,0,3}, {0,0,0,0,1,1,2,2,1,2,0,3},{0,0,0,0,1,1,1,2,2,2,0,3}, {0,0,0,0,0,0,0,0,0,2,0,3}};
//PVI waveform for cleaning screen, not sure if it is correct, but it cleans screen properly. //PVI waveform for cleaning screen, not sure if it is correct, but it cleans screen properly.
const uint32_t waveform[50] = {0x00000008, 0x00000008, 0x00200408, 0x80281888, 0x60a81898, 0x60a8a8a8, 0x60a8a8a8, 0x6068a868, 0x6868a868, 0x6868a868, 0x68686868, 0x6a686868, 0x5a686868, 0x5a686868, 0x5a586a68, 0x5a5a6a68, 0x5a5a6a68, 0x55566a68, 0x55565a64, 0x55555654, 0x55555556, 0x55555556, 0x55555556, 0x55555516, 0x55555596, 0x15555595, 0x95955595, 0x95959595, 0x95949495, 0x94949495, 0x94949495, 0xa4949494, 0x9494a4a4, 0x84a49494, 0x84948484, 0x84848484, 0x84848484, 0x84848484, 0xa5a48484, 0xa9a4a4a8, 0xa9a8a8a8, 0xa5a9a9a4, 0xa5a5a5a4, 0xa1a5a5a1, 0xa9a9a9a9, 0xa9a9a9a9, 0xa9a9a9a9, 0xa9a9a9a9, 0x15151515, 0x11111111}; const uint32_t waveform[50] ={ 0x00000008, 0x00000008, 0x00200408, 0x80281888, 0x60a81898, 0x60a8a8a8, 0x60a8a8a8, 0x6068a868, 0x6868a868, 0x6868a868, 0x68686868, 0x6a686868, 0x5a686868, 0x5a686868, 0x5a586a68, 0x5a5a6a68, 0x5a5a6a68, 0x55566a68, 0x55565a64, 0x55555654, 0x55555556, 0x55555556, 0x55555556, 0x55555516, 0x55555596, 0x15555595, 0x95955595, 0x95959595, 0x95949495, 0x94949495, 0x94949495, 0xa4949494, 0x9494a4a4, 0x84a49494, 0x84948484, 0x84848484, 0x84848484, 0x84848484, 0xa5a48484, 0xa9a4a4a8, 0xa9a8a8a8, 0xa5a9a9a4, 0xa5a5a5a4, 0xa1a5a5a1, 0xa9a9a9a9, 0xa9a9a9a9, 0xa9a9a9a9, 0xa9a9a9a9, 0x15151515, 0x11111111 };
struct bitmapHeader struct bitmapHeader
{ {

View File

@ -55,11 +55,11 @@ Inkplate display(INKPLATE_1BIT);
Network network; Network network;
// Contants used for drawing icons // Contants used for drawing icons
char abbrs[32][16] = {"sn", "sl", "h", "t", "hr", "lr", "s", "hc", "lc", "c"}; char abbrs[32][16] ={ "sn", "sl", "h", "t", "hr", "lr", "s", "hc", "lc", "c" };
const uint8_t *logos[16] = {icon_sn, icon_sl, icon_h, icon_t, icon_hr, icon_lr, icon_s, icon_hc, icon_lc, icon_c}; const uint8_t *logos[16] ={ icon_sn, icon_sl, icon_h, icon_t, icon_hr, icon_lr, icon_s, icon_hc, icon_lc, icon_c };
// Variables for storing temperature // Variables for storing temperature
char temps[8][4] = { char temps[8][4] ={
"0F", "0F",
"0F", "0F",
"0F", "0F",
@ -67,7 +67,7 @@ char temps[8][4] = {
}; };
// Variables for storing days of the week // Variables for storing days of the week
char days[8][4] = { char days[8][4] ={
"", "",
"", "",
"", "",
@ -153,6 +153,8 @@ void loop()
else else
display.partialUpdate(); display.partialUpdate();
// Go to sleep before checking again // Go to sleep before checking again
esp_sleep_enable_timer_wakeup(1000L * DELAY_MS); esp_sleep_enable_timer_wakeup(1000L * DELAY_MS);
(void)esp_light_sleep_start(); (void)esp_light_sleep_start();

View File

@ -3,20 +3,15 @@
#include "Network.h" #include "Network.h"
#include <WiFi.h> #include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
// WiFiMulti object declaration
WiFiMulti WiFiMulti;
// Static Json from ArduinoJson library // Static Json from ArduinoJson library
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",
@ -30,25 +25,27 @@ void Network::begin(char *city)
{ {
// Initiating wifi, like in BasicHttpClient example // Initiating wifi, like in BasicHttpClient example
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, pass); WiFi.begin(ssid, pass);
Serial.print(F("Waiting for WiFi to connect...")); if (WiFi.status() != WL_CONNECTED) {
while ((WiFiMulti.run() != WL_CONNECTED)) WiFi.reconnect();
delay(5000);
Serial.println(F("Waiting for WiFi to reconnect..."));
while ((WiFi.status() != WL_CONNECTED))
{ {
// Printing a dot to Serial monitor every second while waiting to connect // Prints a dot every second that wifi isn't connected
Serial.print(F(".")); Serial.print(F("."));
delay(1000); delay(1000);
} }
Serial.println(F(" connected")); }
// Find internet time // Find internet time
setTime(); setTime();
// Search for given cities woeid // Search for given cities woeid
findCity(city); findCity(city);
// reduce power by making WiFi module sleep
WiFi.setSleep(1);
} }
// Gets time from ntp server // Gets time from ntp server
@ -89,9 +86,20 @@ 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) void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *temp4, char *currentTemp, char *currentWind, char *currentTime, char *currentWeather, char *currentWeatherAbbr)
{ {
// Return if wifi isn't connected // Reconnect if wifi isn't connected
if (WiFi.status() != WL_CONNECTED) if (WiFi.status() != WL_CONNECTED) {
return; WiFi.reconnect();
delay(5000);
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);
}
}
// Wake up if sleeping and save inital state // Wake up if sleeping and save inital state
bool sleep = WiFi.getSleep(); bool sleep = WiFi.getSleep();
@ -201,9 +209,20 @@ 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, return // If not connected to wifi reconnect wifi
if (WiFi.status() != WL_CONNECTED) if (WiFi.status() != WL_CONNECTED) {
return; WiFi.reconnect();
delay(5000);
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);
}
}
// Wake wifi module and save initial state // Wake wifi module and save initial state
bool sleep = WiFi.getSleep(); bool sleep = WiFi.getSleep();

View File

@ -63,8 +63,8 @@ Inkplate display(INKPLATE_1BIT);
Network network; Network network;
//Contants used for drawing icons //Contants used for drawing icons
char abbrs[32][32] = {"01d", "02d", "03d", "04d", "09d", "10d", "11d", "13d", "50d", "01n", "02n", "03n", "04n", "09n", "10n", "11n", "13n", "50n"}; char abbrs[32][32] ={ "01d", "02d", "03d", "04d", "09d", "10d", "11d", "13d", "50d", "01n", "02n", "03n", "04n", "09n", "10n", "11n", "13n", "50n" };
const uint8_t *logos[18] = { const uint8_t *logos[18] ={
icon_01d, icon_01d,
icon_02d, icon_02d,
icon_03d, icon_03d,
@ -85,7 +85,7 @@ const uint8_t *logos[18] = {
icon_50n, icon_50n,
}; };
const uint8_t *s_logos[18] = { const uint8_t *s_logos[18] ={
icon_s_01d, icon_s_01d,
icon_s_02d, icon_s_02d,
icon_s_03d, icon_s_03d,
@ -107,7 +107,7 @@ const uint8_t *s_logos[18] = {
}; };
//Variables for storing temperature //Variables for storing temperature
char temps[8][4] = { char temps[8][4] ={
"0F", "0F",
"0F", "0F",
"0F", "0F",
@ -115,7 +115,7 @@ char temps[8][4] = {
}; };
//Variables for storing hour strings //Variables for storing hour strings
char hours[8][4] = { char hours[8][4] ={
"", "",
"", "",
"", "",

View File

@ -3,15 +3,11 @@
#include "Network.h" #include "Network.h"
#include <WiFi.h> #include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
//WiFiMulti object declaration
WiFiMulti WiFiMulti;
//Static Json from ArduinoJson library //Static Json from ArduinoJson library
StaticJsonDocument<32000> doc; StaticJsonDocument<32000> doc;
@ -19,10 +15,10 @@ void Network::begin(char *city)
{ {
//Initiating wifi, like in BasicHttpClient example //Initiating wifi, like in BasicHttpClient example
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, pass); WiFi.begin(ssid, pass);
Serial.print(F("Waiting for WiFi to connect...")); Serial.print(F("Waiting for WiFi to connect..."));
while ((WiFiMulti.run() != WL_CONNECTED)) while ((WiFi.status() != WL_CONNECTED))
{ {
//Printing a dot to Serial monitor every second while waiting to connect //Printing a dot to Serial monitor every second while waiting to connect
Serial.print(F(".")); Serial.print(F("."));
@ -76,10 +72,20 @@ void formatWind(char *str, float wind)
bool 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) bool 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)
{ {
bool f = 0; bool f = 0;
// If not connected to wifi reconnect wifi
if (WiFi.status() != WL_CONNECTED) {
WiFi.reconnect();
//Return if wifi isn't connected delay(5000);
if (WiFi.status() != WL_CONNECTED)
return 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);
}
}
//Wake up if sleeping and save inital state //Wake up if sleeping and save inital state
bool sleep = WiFi.getSleep(); bool sleep = WiFi.getSleep();

View File

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

View File

@ -1,7 +1,6 @@
#include "Network.h" #include "Network.h"
#include <WiFi.h> #include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
@ -18,9 +17,6 @@ extern char *currency;
//Get our Inkplate object from main file to draw debug info on //Get our Inkplate object from main file to draw debug info on
extern Inkplate display; extern Inkplate display;
//WiFiMulti object declaration
WiFiMulti WiFiMulti;
//Static Json from ArduinoJson library //Static Json from ArduinoJson library
StaticJsonDocument<30000> doc; StaticJsonDocument<30000> doc;
@ -28,10 +24,10 @@ void Network::begin()
{ {
//Initiating wifi, like in BasicHttpClient example //Initiating wifi, like in BasicHttpClient example
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, pass); WiFi.begin(ssid, pass);
Serial.print(F("Waiting for WiFi to connect...")); Serial.print(F("Waiting for WiFi to connect..."));
while ((WiFiMulti.run() != WL_CONNECTED)) while ((WiFi.status() != WL_CONNECTED))
{ {
Serial.print(F(".")); Serial.print(F("."));
delay(1000); delay(1000);
@ -70,9 +66,20 @@ bool Network::getData(double *data)
{ {
bool f = 0; bool f = 0;
//Return if wifi isn't connected // If not connected to wifi reconnect wifi
if (WiFi.status() != WL_CONNECTED) if (WiFi.status() != WL_CONNECTED) {
return 0; WiFi.reconnect();
delay(5000);
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);
}
}
//Wake up if sleeping and save inital state //Wake up if sleeping and save inital state
bool sleep = WiFi.getSleep(); bool sleep = WiFi.getSleep();

View File

@ -111,8 +111,6 @@ void setup()
delay(5000); delay(5000);
network.begin(); network.begin();
//Our begin function
network.begin();
} }
void loop() void loop()
@ -238,7 +236,7 @@ void drawGrid()
void getToFrom(char *dst, char *from, char *to, int *day, int *timeStamp) void getToFrom(char *dst, char *from, char *to, int *day, int *timeStamp)
{ {
//ANSI C time struct //ANSI C time struct
struct tm ltm = {0}, ltm2 = {0}; struct tm ltm ={ 0 }, ltm2 ={ 0 };
char temp[128], temp2[128]; char temp[128], temp2[128];
strncpy(temp, from, 16); strncpy(temp, from, 16);
temp[16] = 0; temp[16] = 0;
@ -369,7 +367,7 @@ bool drawEvent(entry *event, int day, int beginY, int maxHeigth, int *heigthNeed
display.setCursor(x1 + 5, display.getCursorY()); display.setCursor(x1 + 5, display.getCursorY());
char line[128] = {0}; char line[128] ={ 0 };
for (int i = 0; i < strlen(event->location); ++i) for (int i = 0; i < strlen(event->location); ++i)
{ {
@ -470,9 +468,9 @@ void drawData()
cmp); cmp);
//Events displayed and overflown counters //Events displayed and overflown counters
int columns[3] = {0}; int columns[3] ={ 0 };
bool clogged[3] = {0}; bool clogged[3] ={ 0 };
int cloggedCount[3] = {0}; int cloggedCount[3] ={ 0 };
//Displaying events one by one //Displaying events one by one
for (int i = 0; i < entriesNum; ++i) for (int i = 0; i < entriesNum; ++i)

View File

@ -1,21 +1,18 @@
#include "Network.h" #include "Network.h"
#include <WiFi.h> #include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
// WiFiMulti object declaration
WiFiMulti WiFiMulti;
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);
WiFiMulti.addAP(ssid, pass); WiFi.begin(ssid, pass);
Serial.print(F("Waiting for WiFi to connect...")); Serial.print(F("Waiting for WiFi to connect..."));
while ((WiFiMulti.run() != 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("."));
@ -46,14 +43,20 @@ 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 (WiFi.status() != WL_CONNECTED) {
WiFi.reconnect();
// Return if wifi isn't connected delay(5000);
if (WiFi.status() != WL_CONNECTED)
return 0;
// Wake up if sleeping and save inital state Serial.println(F("Waiting for WiFi to reconnect..."));
bool sleep = WiFi.getSleep(); while ((WiFi.status() != WL_CONNECTED))
WiFi.setSleep(false); {
// Prints a dot every second that wifi isn't connected
Serial.print(F("."));
delay(1000);
}
}
// Http object used to make get request // Http object used to make get request
HTTPClient http; HTTPClient http;
@ -68,23 +71,23 @@ bool Network::getData(char *data)
// Actually do request // Actually do request
int httpCode = http.GET(); int httpCode = http.GET();
if (httpCode == 200) if (httpCode == 200)
{ {
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;
} }
else else
{ {
Serial.println(httpCode);
f = 1; f = 1;
} }
// end http // end http
http.end(); http.end();
// Return to initial state
WiFi.setSleep(sleep);
return !f; return !f;
} }