Many fixes.
This commit is contained in:
parent
f012be658b
commit
d5826251bf
|
@ -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();
|
||||||
|
|
|
@ -3,15 +3,10 @@
|
||||||
#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;
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -111,8 +111,6 @@ void setup()
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
network.begin();
|
network.begin();
|
||||||
//Our begin function
|
|
||||||
network.begin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue