-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_weather.cpp
More file actions
43 lines (39 loc) · 2.55 KB
/
Copy pathget_weather.cpp
File metadata and controls
43 lines (39 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* ********************************************************************************************** */
/* */
/* Smart Watch Firmware ::::::::: ::: */
/* get_weather.cpp :+: :+: :+: :+: */
/* +:+ +:+ +:+ +:+ */
/* By: Roman Alexandrov <r.aleksandroff@gmail.com> +#++:++#: +#++:++#++: */
/* +#+ +#+ +#+ +#+ */
/* Created: 2023/06/28 14:49:16 #+# #+# #+# #+# */
/* Updated: 2023/11/12 13:48:41 ### ### ### ### */
/* */
/* */
/* This sketch retrieves weather values from the OpenWeather server and adapts them for */
/* further use. */
/* */
/* ********************************************************************************************** */
#include "header.h"
void ft_get_weather(void)
{
HTTPClient http;
String line;
StaticJsonDocument<300> doc;
float temperature;
DEBUG_PRINT("ft_get_weather function BEGIN");
http.begin(client, (String(F("http://api.openweathermap.org/data/2.5/weather?lat="))
+ String(lat,2) + "&lon=" + String(lon,2)
+ String(F("&APPID=")) + api_key + String(F("&lang=en"))));
http.addHeader(F("Content-Type"), F("text/plain"));
auto httpCode = http.GET();
line = http.getString(); // get the response payload
DEBUG_PRINT("Weather server response: ");
DEBUG_PRINT(line);
line.replace('[', ' ');
line.replace(']', ' ');
deserializeJson(doc, line);
rtcValues.weather_id = doc[F("weather")][F("id")].as<int>();
temperature = doc[F("main")][F("temp")].as<float>();
rtcValues.temp = (ceil(temperature)) - 273; // Kelvin to Celcius
DEBUG_PRINT("ft_get_weather function FINISHED");
}