Skip to content

Commit

Permalink
Merge pull request #29 from JHershey69/upgrade
Browse files Browse the repository at this point in the history
Upgrade
  • Loading branch information
JHershey69 authored Mar 16, 2021
2 parents 938eba2 + bc55e8b commit 15a9ae8
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OpenWeatherOneCall v3.0.5 ![IMAGE OF LIGHTNING](https://github.com/JHershey69/OpenWeatherOneCall/blob/master/images/lightning.jpg)
# OpenWeatherOneCall v3.1.0 ![IMAGE OF LIGHTNING](https://github.com/JHershey69/OpenWeatherOneCall/blob/master/images/lightning.jpg)
## This is for ESP32 only

**OpenWeatherOneCall** library to gather weather information from OpenWeatherMap
Expand All @@ -22,3 +22,5 @@ v3.0.0 has a **Legacy Mode** to maintain ease of use for previous versions
<br>--added snowVolume and rainVolume, see variables sheet, returned in mm or in based on units
<br>v3.0.5
<br>--minor bug fix with language selection.
<br>v3.1.0
<br>--added Air Quality information (see addendum).
Binary file added docs/OPEN WEATHER ONE CALL ADDENDUM.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "OpenWeatherOneCall",
"version": "3.0.5",
"version": "3.1.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":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=OpenWeatherOneCall
version=3.0.5
version=3.1.0
author=JHershey69
maintainer=JHershey69 <[email protected]>
sentence=Current and Seven Day Weather Forecast Library for ESP32.
Expand Down
83 changes: 82 additions & 1 deletion src/OpenWeatherOneCall.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
OpenWeatherOneCall.cpp v3.0.5
OpenWeatherOneCall.cpp v3.1.0
copyright 2020 - Jessica Hershey
www.github.com/JHershey69
Expand All @@ -24,6 +24,14 @@ OpenWeatherOneCall::OpenWeatherOneCall()
char DS_URL2[100];
#define DS_URL3 "&appid="

// For Air Quality calls current *************
#define AQ_URL1 "https://api.openweathermap.org/data/2.5/air_pollution?lat="
#define AQ_URL2 "&lon="
#define AQ_URL3 "&appid="




// For Historical Weather Calls **********
#define TS_URL1 "https://api.openweathermap.org/data/2.5/onecall/timemachine"
#define TS_URL2 "&dt="
Expand Down Expand Up @@ -66,6 +74,13 @@ int OpenWeatherOneCall::parseWeather(void)
else
{
OpenWeatherOneCall::freeHistoryMem();

// TEST AIR QUALITY CALL *********************
OpenWeatherOneCall::createAQ(384);


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

int error_code = OpenWeatherOneCall::createCurrent(SIZE_CAPACITY);

}
Expand Down Expand Up @@ -641,6 +656,62 @@ int OpenWeatherOneCall::createHistory()
return 0;
}

int OpenWeatherOneCall::createAQ(int sizeCap)
{
char getURL[200] = {0};

sprintf(getURL,"%s%.6f%s%.6f%s%s",AQ_URL1,USER_PARAM.OPEN_WEATHER_LATITUDE,AQ_URL2,USER_PARAM.OPEN_WEATHER_LONGITUDE,AQ_URL3,USER_PARAM.OPEN_WEATHER_DKEY);
printf("%s\n",getURL);

HTTPClient http;
http.begin(getURL);
int httpCode = http.GET();

if (httpCode > 399)
{
if(httpCode == 401)
{
http.end();
return 22;
}

http.end();
return 21;

}

const size_t capacity = sizeCap;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, http.getString());
doc.shrinkToFit();

quality = (struct airQuality *)calloc(1,sizeof(struct airQuality));

float coord_lon = doc["coord"]["lon"]; // -74.1975
float coord_lat = doc["coord"]["lat"]; // 39.9533

JsonObject list_0 = doc["list"][0];

quality -> aqi = list_0["main"]["aqi"]; // 2

JsonObject list_0_components = list_0["components"];
quality -> co = list_0_components["co"]; // 230.31
quality -> no = list_0_components["no"]; // 0.43
quality -> no2 = list_0_components["no2"]; // 1.69
quality -> o3 = list_0_components["o3"]; // 100.14
quality -> so2 = list_0_components["so2"]; // 0.88
quality -> pm2_5 = list_0_components["pm2_5"]; // 0.76
quality -> pm10 = list_0_components["pm10"]; // 1.04
quality -> nh3 = list_0_components["nh3"]; // 0.43

quality -> dayTime = list_0["dt"]; // 1615838400

http.end();
return 0;


}

int OpenWeatherOneCall::createCurrent(int sizeCap)
{

Expand Down Expand Up @@ -1325,6 +1396,15 @@ void OpenWeatherOneCall::freeMinuteMem(void)
}
}

void OpenWeatherOneCall::freeQualityMem(void)
{
if(quality)
{
free(quality);
quality = NULL;
}
}

char* OpenWeatherOneCall::getErrorMsgs(int _errMsg)
{
if((_errMsg > SIZEOF(errorMsgs)) || (_errMsg < 1))
Expand All @@ -1343,6 +1423,7 @@ OpenWeatherOneCall::~OpenWeatherOneCall()
OpenWeatherOneCall::freeHourMem();
OpenWeatherOneCall::freeMinuteMem();
OpenWeatherOneCall::freeHistoryMem();
OpenWeatherOneCall::freeQualityMem();

}

Expand Down
19 changes: 18 additions & 1 deletion src/OpenWeatherOneCall.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
OpenWeatherOnecall.h
Upgrade v3.0.5
Upgrade v3.1.0
copyright 2020 - Jessica Hershey
www.github.com/jHershey69
Expand Down Expand Up @@ -94,6 +94,21 @@ class OpenWeatherOneCall
float LONGITUDE;
} location;

struct airQuality
{
long dayTime;
char readableDateTime;
int aqi;
float co; // :201.94053649902344,
float no; //:0.01877197064459324,
float no2; //:0.7711350917816162,
float o3; //:68.66455078125,
float so2; //:0.6407499313354492,
float pm2_5; //:0.5,
float pm10; //:0.540438711643219,
float nh3; //:0.12369127571582794
} *quality;

struct nowData
{
long dayTime; // 1582151288
Expand Down Expand Up @@ -254,13 +269,15 @@ class OpenWeatherOneCall
int createCurrent(int);
int setExcludes(int EXCL);
int getLocationInfo();
int createAQ(int);

void freeCurrentMem(void);
void freeForecastMem(void);
void freeAlertMem(void);
void freeHourMem(void);
void freeMinuteMem(void);
void freeHistoryMem(void);
void freeQualityMem(void);

//Variables
// For eventual struct calls
Expand Down

0 comments on commit 15a9ae8

Please sign in to comment.