Many fixes.
This commit is contained in:
parent
f012be658b
commit
d5826251bf
|
@ -153,6 +153,8 @@ void loop()
|
|||
else
|
||||
display.partialUpdate();
|
||||
|
||||
|
||||
|
||||
// Go to sleep before checking again
|
||||
esp_sleep_enable_timer_wakeup(1000L * DELAY_MS);
|
||||
(void)esp_light_sleep_start();
|
||||
|
|
|
@ -3,15 +3,10 @@
|
|||
#include "Network.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
// WiFiMulti object declaration
|
||||
WiFiMulti WiFiMulti;
|
||||
|
||||
// Static Json from ArduinoJson library
|
||||
StaticJsonDocument<6000> doc;
|
||||
|
||||
|
@ -30,25 +25,27 @@ void Network::begin(char *city)
|
|||
{
|
||||
// Initiating wifi, like in BasicHttpClient example
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFiMulti.addAP(ssid, pass);
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
Serial.print(F("Waiting for WiFi to connect..."));
|
||||
while ((WiFiMulti.run() != WL_CONNECTED))
|
||||
if (WiFi.status() != 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("."));
|
||||
delay(1000);
|
||||
}
|
||||
Serial.println(F(" connected"));
|
||||
}
|
||||
|
||||
// Find internet time
|
||||
setTime();
|
||||
|
||||
// Search for given cities woeid
|
||||
findCity(city);
|
||||
|
||||
// reduce power by making WiFi module sleep
|
||||
WiFi.setSleep(1);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Return if wifi isn't connected
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
return;
|
||||
// Reconnect if wifi isn't connected
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
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
|
||||
bool sleep = WiFi.getSleep();
|
||||
|
@ -201,9 +209,20 @@ void Network::getDays(char *day, char *day1, char *day2, char *day3)
|
|||
|
||||
void Network::findCity(char *city)
|
||||
{
|
||||
// If not connected to wifi, return
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
return;
|
||||
// If not connected to wifi reconnect wifi
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
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
|
||||
bool sleep = WiFi.getSleep();
|
||||
|
|
|
@ -3,15 +3,11 @@
|
|||
#include "Network.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
//WiFiMulti object declaration
|
||||
WiFiMulti WiFiMulti;
|
||||
|
||||
//Static Json from ArduinoJson library
|
||||
StaticJsonDocument<32000> doc;
|
||||
|
||||
|
@ -19,10 +15,10 @@ void Network::begin(char *city)
|
|||
{
|
||||
//Initiating wifi, like in BasicHttpClient example
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFiMulti.addAP(ssid, pass);
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
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
|
||||
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 f = 0;
|
||||
// If not connected to wifi reconnect wifi
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
WiFi.reconnect();
|
||||
|
||||
//Return if wifi isn't connected
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
return 0;
|
||||
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
|
||||
bool sleep = WiFi.getSleep();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "Network.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
|
||||
|
@ -18,9 +17,6 @@ extern char *currency;
|
|||
//Get our Inkplate object from main file to draw debug info on
|
||||
extern Inkplate display;
|
||||
|
||||
//WiFiMulti object declaration
|
||||
WiFiMulti WiFiMulti;
|
||||
|
||||
//Static Json from ArduinoJson library
|
||||
StaticJsonDocument<30000> doc;
|
||||
|
||||
|
@ -28,10 +24,10 @@ void Network::begin()
|
|||
{
|
||||
//Initiating wifi, like in BasicHttpClient example
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFiMulti.addAP(ssid, pass);
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
Serial.print(F("Waiting for WiFi to connect..."));
|
||||
while ((WiFiMulti.run() != WL_CONNECTED))
|
||||
while ((WiFi.status() != WL_CONNECTED))
|
||||
{
|
||||
Serial.print(F("."));
|
||||
delay(1000);
|
||||
|
@ -70,9 +66,20 @@ bool Network::getData(double *data)
|
|||
{
|
||||
bool f = 0;
|
||||
|
||||
//Return if wifi isn't connected
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
return 0;
|
||||
// If not connected to wifi reconnect wifi
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
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
|
||||
bool sleep = WiFi.getSleep();
|
||||
|
|
|
@ -111,8 +111,6 @@ void setup()
|
|||
|
||||
delay(5000);
|
||||
network.begin();
|
||||
//Our begin function
|
||||
network.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
#include "Network.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
|
||||
// WiFiMulti object declaration
|
||||
WiFiMulti WiFiMulti;
|
||||
|
||||
void Network::begin()
|
||||
{
|
||||
// Initiating wifi, like in BasicHttpClient example
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFiMulti.addAP(ssid, pass);
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
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
|
||||
Serial.print(F("."));
|
||||
|
@ -46,14 +43,20 @@ bool Network::getData(char *data)
|
|||
{
|
||||
// Variable to store fail
|
||||
bool f = 0;
|
||||
// If not connected to wifi reconnect wifi
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
WiFi.reconnect();
|
||||
|
||||
// Return if wifi isn't connected
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
return 0;
|
||||
delay(5000);
|
||||
|
||||
// Wake up if sleeping and save inital state
|
||||
bool sleep = WiFi.getSleep();
|
||||
WiFi.setSleep(false);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Http object used to make get request
|
||||
HTTPClient http;
|
||||
|
@ -68,23 +71,23 @@ bool Network::getData(char *data)
|
|||
|
||||
// Actually do request
|
||||
int httpCode = http.GET();
|
||||
|
||||
if (httpCode == 200)
|
||||
{
|
||||
long n = 0;
|
||||
while (http.getStream().available())
|
||||
data[n++] = http.getStream().read();
|
||||
data[n++]= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(httpCode);
|
||||
f = 1;
|
||||
}
|
||||
|
||||
// end http
|
||||
http.end();
|
||||
|
||||
// Return to initial state
|
||||
WiFi.setSleep(sleep);
|
||||
|
||||
return !f;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue