Skip to content

Commit

Permalink
Merge pull request #55 from JHershey69/Upgrade
Browse files Browse the repository at this point in the history
v4.0.0 Upgrade
  • Loading branch information
JHershey69 authored Aug 9, 2024
2 parents 258f720 + e7ba6b0 commit 3bd6893
Show file tree
Hide file tree
Showing 15 changed files with 1,264 additions and 942 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# OpenWeatherOneCall v3.3.3 ![IMAGE OF LIGHTNING](https://github.com/JHershey69/OpenWeatherOneCall/blob/master/images/lightning.jpg)
# OpenWeatherOneCall v4.0.0 ![IMAGE OF LIGHTNING](https://github.com/JHershey69/OpenWeatherOneCall/blob/master/images/lightning.jpg)
## This is for ESP32 only

##This is an upgrade for OpenWeatherMap API 3.0 and Air Pollution API 2.5

**Please be advised** OpenWeather has changed ONE CALL to a subscription service. Signing up is
**Please be advised** OpenWeather has changed ONE CALL to a subscription PAY BY CALL service. Signing up is
required to get your KEY, but you get 1000 calls a day for free (this is one call every 90 seconds and that is A LOT for free)
and you will continue to get all of the features of this library.

Expand Down Expand Up @@ -57,4 +57,6 @@ v3.0.0 has a **Legacy Mode** to maintain ease of use for previous versions
<br>--Minor fix to update API change for Air Quality.
<br>**v3.3.3**
<br>--Minor fix to update API change for Air Quality and Example scripts.
<br>**v4.0.0**
<br>--MAJOR REWRITE with addition options and variable SEE DOCUMENTATION. Some features deprecated no longer supported.

Binary file removed docs/OPEN WEATHER ONE CALL ADDENDUM.pdf
Binary file not shown.
Binary file removed docs/OpenWeatherOneCall Manual v3.0.4.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added docs/OpenWeatherOneCall_Manual_4.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**Documentation for v3.0.4 and above**
**Documentation for v4.0.0 and above**
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Open Weather One Call Library
v3.0.4
Copyright 2020 - Jessica Hershey
v4.0.0
Copyright 2020=2024 - Jessica Hershey
www.github.com/JHershey69
One Call API key at www.openweathermap.org
Expand All @@ -17,50 +17,86 @@
*/

// ===== Required libraries (Other required libraries are installed in header file)

#include <OpenWeatherOneCall.h>
#include <WiFi.h> //<-- Might be native to ESP32
// ===============================================================================

// ======= END REQUIRED LIBRARIES =======================================



// ========= Required only for TFT Display ==============
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
#include <TFT_eSPI.h> // Hardware-specific library

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
//========= End TFT Library =============================


#define HOMESSID "YOUR SSID HERE"
#define HOMEPW "YOUR SSID PW HERE"
#define ONECALLKEY "YOUR ONE CALL API KEY HERE"
char ONECALLKEY[] = "YOUR ONE CALL KEY HERE";

// Only needed if WiFiTri installed for Triangulation may have fee from Google
#define GOOGLEKEY "YOUR GOOGLE DEVELOPER API KEY""
// #define GOOGLEKEY "YOUR GOOGLE DEVELOPER API KEY""


// OpenWeatherOneCall API Options and Settings

//*************** LOCATION ************************

// OpenWeatherOneCall variables
int myTimeZone = -4; //<--------- GMT OFFSET

//For Latitude and Longitude Location setting if used
float myLATITUDE = 39.9537; //<-----This is Toms River, NJ
//Location MODES are used to tell the program how you are delivering your coordinates:
// 1 LAT/LON <----- Can be from GPS, manual as below, or whatever method gets you a latitude and longitude except IP location
// 2 CITYID <----- From OpenWeatherMap City ID list. Not very accurate.
// 3 IP ADDRESS [NOT REALLY SUGGESTED CAN BE WILDLY OFFSET LOCATION IF HOTSPOT]

int locationMode = 1;

//For Latitude and Longitude Location MODE 1 setting if used
float myLATITUDE = 39.9537; //<-----This is Toms River, NJ
float myLONGITUDE = -74.1979;

//For City ID Location setting if used
int myCITYID = 4504476; //<-----Toms River, NJ USA
//For City ID Location MODE setting if used
int myCITYID = 4504476; //<-----Toms River, NJ USA

//*************** END LOCATION **********************

//*************** FLAGS *****************************
int myCURRENT = 1; //<-----0 is CURRENT off, 1 is on
int myAIRQUALITY = 1; //<-----0 is Air Quality off, 1 is on
int myTIMESTAMP = 1; //<-----0 is TIMESTAMP off, 1 is TIMESTAMP on
char timestampDate[11] = "03/03/2023"; //<-----MM/DD/YYYY right here limit is 4 days in future, past is 01/01/1979
int myOVERVIEW = 1; //<-----0 is OVERVIEW off, 1 is OVERVIEW on
char overviewDate[9] = "TOMORROW"; //<-----"TODAY" or "TOMORROW"
//***************************************************

int myUNITS = IMPERIAL; //<-----METRIC, IMPERIAL, KELVIN (IMPERIAL is default)
//************** EXCLUDES ***************************
// Excludes are EXCL_D, EXCL_H, EXCL_M, EXCL_A
// Those are DAILY, HOURLY, MINUTELY, and ALERTS
// You set them like this: myEXCLUDES = EXCL_D+EXCL_H+EXCL_M+EXCL_A
// If you leave them set to 0 as below you get a JSON file with ALL CURRENT WEATHER measurements which is a huge file

//Can't get current and historical at the same time
int myHISTORY = NULL; //<-----Only required for historical data up to 5 days
int myEXCLUDES = 0; //<-----0 Excludes is default
//***************************************************

//See manual for excludes, only CURRENT Data allows 1,000,000 calls a month
int myEXCLUDES = EXCL_D+EXCL_H+EXCL_M; //<-----0 Excludes is default
//*************** UNITS OF MEASURMENT and DATE TIME FORMAT ***************

int myUNITS = IMPERIAL; //<-----METRIC, IMPERIAL, KELVIN (IMPERIAL is default)

//Date Time Format
int myDTF = 1; //1 M/D/Y 24H
// 2 D/M/Y 24H
// 3 M/D/Y 12H
// 4 D/M/Y 12H

//************************************************************************

//for debugging loop counting
int nextCall = 0;
//int callAttempt = 1;

OpenWeatherOneCall OWOC; // <------ Invoke Library like this
OpenWeatherOneCall OWOC; // <------ Invoke Library like this

// WiFi Connect function **********************************
void connectWifi() {
Expand All @@ -73,11 +109,12 @@ void connectWifi() {
TryNum++;
if (TryNum > 20) {
printf("\nUnable to connect to WiFi. Please check your parameters.\n");
for (;;);
for (;;)
;
}
}
printf("Connected to: % s\n\n", HOMESSID);
} //================== END WIFI CONNECT =======================
} //================== END WIFI CONNECT =======================



Expand All @@ -92,95 +129,102 @@ void setup() {
// WiFi Connection required *********************
while (WiFi.status() != WL_CONNECTED) {
connectWifi();
} //<----------------End WiFi Connection Check
/*
Getting the Weather
If you desire WiFi Triangulation to find your
Latitude and Longitude, please install the
WiFiTriangulation Library
Otherwise Latitude and Longitude can be from any
source such as a GPS or entered manually.
If you DO NOT set the Latitude and Longitude
the program will attempt to find your location
by IP Address (which could be grossly innacurate
if you are using a HOTSPOT on your phone)
*/
// First set your Key value
OWOC.setOpenWeatherKey(ONECALLKEY);
// Second set your position (can be CITY ID, IP ADDRESS, GPS, or Manual LATITUDE/LONGITUDE)
// Choose one of the following options
// Here we use the Lat and Lon for Pensacola, Florida (Using the predefined values)
OWOC.setLatLon(myLATITUDE, myLONGITUDE);
// If we are using CITY ID
//OWOC.setLatLon(myCITYID);
// If we want to use IP Address Geolocation use no arguments
//OWOC.setLatLon();
} //<----------------End WiFi Connection Check

// Third set any EXCLUDES if required (Here we are not using any
OWOC.setExcl(myEXCLUDES);
// Set History if you want historical weather other wise NULL
OWOC.setHistory(myHISTORY);
// Set UNITS of MEASURE otherwise default is IMPERIAL
OWOC.setUnits(myUNITS);

//Now call the weather. Please notice no arguments are required in this call
OWOC.parseWeather();

//Now display some information, note the pointer requirement for current and alert, this is NEW for v3.0.0
//Now display some information, note the pointer requirement for current and alert

// Location info is available for ALL modes (History/Current)
// Location info is available for ALL modes
printf("\nLocation: % s, % s % s\n", OWOC.location.CITY, OWOC.location.STATE, OWOC.location.COUNTRY);


//Verify all other values exist before using
if (myHISTORY) //Remember you can't get historical and current weather at the same time so we are checking here for NULL
{
if (OWOC.history)
{
printf("Mean Temp for % s : % .0f\n", OWOC.history[0].weekDayName, OWOC.history[0].temperature);
}
} else //If History was NULL we go to Current Weather. Air Quality is returned with Current Weather (Historical Air Quality COMING SOON!)

if (OWOC.current) //Check if data is in the struct for all variables before using them
{
if (OWOC.current) //Always check to see if data is in the struct for all variables before using them
{
printf("Current Temp : % .0f\n", OWOC.current->temperature);
printf("Current Humidity : % .0f\n", OWOC.current->humidity);
printf("\nCURRENT\n");
printf("Temp : % .0f\n", OWOC.current->temperature);
printf("Humidity : % .0f\n", OWOC.current->humidity);
} else printf("\nCURRENT IS OFF or EMPTY\n");

//Forecast is part of CURRENT and has info for the 8 days future weather. See variables PDF
// The JSON holds this info in the DAILY section and EXCL_D turns this off
if (OWOC.forecast) { //Check if data is in the struct for all variables before using them
printf("\nFORECAST - Up to 8 days future forecast\n");
for (int x = 0; x < 8; x++) {
printf("Date: %s High Temperature: % .0f\n", OWOC.forecast[x].readableDateTime, OWOC.forecast[x].temperatureHigh);
}
} else printf("\nFORECAST IS OFF or EMPTY\n");

if(OWOC.quality) //See Addendum for complete list of Air Quality Variables
{
printf("\nAir Quality : % d\n", OWOC.quality->aqi);
printf("Carbon : % .2f\n", OWOC.quality->co);
printf("Nitrogen : % .2f\n", OWOC.quality->no);
printf("Ozone : % .2f\n", OWOC.quality->o3);
}
//Hour is part of CURRENT and has info for 48 hours future weather. See variables PDF
// The JSON holds this info in the HOURLY section and EXCL_H turns this off
if (OWOC.hour) { //Check if data is in the struct for all variables before using them
printf("\nHOURLY - Up to 48 hours forecast\n");

if (OWOC.forecast)
{
printf("\nForecast Temp Tomorrow : % .0f\n", OWOC.forecast[1].temperatureHigh);
for (int x = 0; x < 6; x++) {
printf("%s Actual Temp: % .0f\n", OWOC.hour[x].readableTime, OWOC.hour[x].temperature);
printf("%s Feels Like Temp: % .0f\n", OWOC.hour[x].readableTime, OWOC.hour[x].apparentTemperature);
}
} else printf("\nHOURLY IS OFF or EMPTY\n");

if (OWOC.alert) //Only if ALERTS aren't excluded
{
printf("\nALERT *** ALERT *** ALERT\n");
printf("Sender : % s\n", OWOC.alert->senderName);
printf("Event : % s\n", OWOC.alert->event);
printf("ALERT : % s\n", OWOC.alert->summary);
} else {printf("\nNo Alerts For Area\n");
//MINUTELY is part of CURRENT and has info for 60 minutes future weather. See variables PDF
// The JSON holds this info in the MINUTELY section and EXCL_M turns this off
if (OWOC.minute) { //Check if data is in the struct for all variables before using them
printf("\nMINUTELY - Up to 60 minutes precipitation forecast\n");

for (int x = 0; x < 30; x++) {
printf("%s Precipitation: % .2f\n", OWOC.minute[x].readableTime, OWOC.minute[x].precipitation);
}
} else printf("\nHOURLY IS OFF or EMPTY\n");

//ALERTS is part of CURRENT and has info for alerts in your area. See variables PDF
// The JSON holds this info in the ALERTS section and EXCL_A turns this off
if (OWOC.alert) //Check if data is in the struct for all variables before using them
{
printf("\nALERT *** ALERT *** ALERT\n");
printf("Sender : % s\n", OWOC.alert->senderName);
printf("Event : % s\n", OWOC.alert->event);
printf("ALERT : % s\n", OWOC.alert->summary);
} else {
printf("\nNo Alerts For Area, Alerts are EXCLUDED, or Alerts struct is empty\n");
}

//The following sections are separate from CURRENT and are turned off and on with their own flags

if (OWOC.timestamp) { //Check if data is in the struct for all variables before using them
printf("\nTIMESTAMP - Single day weather for any date from 01-01-1979 to 4 days in future\n");
printf("% s - % s\nTemperature: % .0f\nFeels like: % .0f\nHumidity: % .0F%%\n", OWOC.timestamp[0].weekDayName, OWOC.timestamp[0].readableDateTime, OWOC.timestamp[0].temperature,OWOC.timestamp[0].apparentTemperature,OWOC.timestamp[0].humidity);
} else printf("\nTIMESTAMP IS OFF or EMPTY\n");

if (OWOC.overView) //Check if data is in the struct for all variables before using them
{
printf("\nOVERVIEW - Summary for TODAY or TOMORROW generated by AI\n");

// Print the struct values to verify
printf("Latitude: %.6f\n", OWOC.overView->lat); // %.6f for printing double with 6 decimal places
printf("Longitude: %.6f\n", OWOC.overView->lon);
printf("Timezone: %s\n", OWOC.overView->tz); // %s for const char* (string)
printf("Date: %s\n", OWOC.overView->date);
printf("Units: %s\n", OWOC.overView->units);
printf("Weather Overview: %s\n", OWOC.overView->weather_overview);

} else printf("\nOVERVIEW IS OFF or EMPTY\n");

if (OWOC.quality) //Check if data is in the struct for all variables before using them
{
printf("\nAir Quality and Pollution Numbers for today");
printf("\nAir Quality : % d\n", OWOC.quality->aqi);
printf("Carbon : % .2f\n", OWOC.quality->co);
printf("Nitrogen : % .2f\n", OWOC.quality->no);
printf("Ozone : % .2f\n", OWOC.quality->o3);
} else printf("\nAIR QUALITY IS OFF or EMPTY\n");



}

void loop() {
}
2 changes: 1 addition & 1 deletion examples/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ framework = arduino
upload_speed = 1500000
monitor_speed = 115200
lib_deps =
ArduinoJson @ 6.17.2
ArduinoJson @ 7

[env:esp32dev]
platform = espressif32
Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "OpenWeatherOneCall",
"version": "3.3.3",
"version": "4.0.0",
"keywords": "openweather, darksky, weather, esp32, arduino",
"description": "OpenWeatherMap Library to use One Call on the ESP32. This library allows the ESP32 to receive and parse the json from OpenWeatherMap",
"dependencies":
[
{
"owner": "bblanchon",
"name": "ArduinoJson",
"version": "^6.17.2"
"version": "^7.0.0"
}
],
"repository":
Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=OpenWeatherOneCall
version=3.3.3
version=4.0.0
author=JHershey69
maintainer=JHershey69 <jamiehershey2@gmail.com>
sentence=Current and Seven Day Weather Forecast Library for ESP32.
paragraph=This library depends on ArduinoJson v6+
sentence=Weather Forecast Library for ESP32.
paragraph=This library depends on ArduinoJson v7+
category=other
url=https://github.com/JHershey69/OpenWeatherOneCall
architectures=esp32
Expand Down
Loading

0 comments on commit 3bd6893

Please sign in to comment.