Hello!
I did a project with Esp8266 and blynk.
But i also want to get weather data via a Widget, 'cause i couldnt use servers or something.
Via weather widget, allow us to change servers (openweathermap, accuweather, wunderground etc.)
And allow us to change api value, ability to get current State, country and such information from GPS.
Thanks.
Pavel
March 14, 2018, 6:07am
2
Nice idea!
One comment though, all these APIs are not free
https://developer.accuweather.com/pricing-and-data-packages
https://www.wunderground.com/weather/api/d/pricing.html
Would you pay a monthly fee to access to the data like that?
Thanks
Hello,
I use wunderground , with the “developer” free plan.
You can call the API up to 500 times a day then once every 3 minutes, which is great for weather data.
You can choose to have the data for a specific city but you can also choose from which precise “weather station” to have the data.
At the moment, I call them via node-red and then pass them to the blynk server to display them on the app.
Regards
Pavel
March 14, 2018, 1:07pm
4
That’s cool, but if we were to integrate it in the apps, we (Blynk) as a developer will quickly run out of 500 requests. There are hundreds of thousands people who use Blynk.
1 Like
AND
March 14, 2018, 1:18pm
5
Weather output in Serial! It is possible to deduce in Blynk.virtualWrite on parameters.
// парсинг погоды с http://api.openweathermap.org
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
// If you like this project, please add a star!
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
const char* ssid = "";
const char* password = "";
const char* host = "api.openweathermap.org";
String line;
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
jsonGet();
}
void loop() {
StaticJsonBuffer<2000> jsonBuffer; /// буфер на 2000 символов
JsonObject& root = jsonBuffer.parseObject(line); // скармиваем String
if (!root.success()) {
Serial.println("parseObject() failed"); // если ошибка, сообщаем об этом
jsonGet(); // пинаем сервер еще раз
return; // и запускаем заного
}
/// отправка в Serial
Serial.println();
String name = root["name"]; // достаем имя,
Serial.print("name:");
Serial.println(name);
float tempK = root["main"]["temp"]; // достаем температуру из структуры main
float tempC = tempK - 273.15; // переводим кельвины в цельси
Serial.print("temp: ");
Serial.print(tempC); // отправляем значение в сериал
Serial.println(" C");
float tempKmin = root["main"]["temp_min"]; // и так далее
float tempCmin = tempKmin - 273.15;
Serial.print("temp min: ");
Serial.print(tempCmin);
Serial.println(" C");
float tempKmax = root["main"]["temp_max"];
float tempCmax = tempKmax - 273.15;
Serial.print("temp max: ");
Serial.print(tempCmax);
Serial.println(" C");
int pressurehPa = root["main"]["pressure"];
float pressure = pressurehPa/1.333;
Serial.print("pressure: ");
Serial.print(pressure);
Serial.println(" mmHc");
int humidity = root["main"]["humidity"];
Serial.print("humidity: ");
Serial.print(humidity);
Serial.println(" %");
float windspeed = root["wind"]["speed"];
Serial.print("wind speed: ");
Serial.print(windspeed);
Serial.println(" m/s");
int winddeg = root["wind"]["deg"];
Serial.print("wind deg :");
Serial.println(winddeg);
Serial.println();
Serial.println();
delay(50000);
}
void jsonGet() {
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
client.println("GET /data/2.5/weather?id=(city)&appid=(api key) HTTP/1.1");
client.println("Host: api.openweathermap.org");
client.println("Connection: close");
client.println();
delay(1500);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
line = client.readStringUntil('\r');
}
Serial.print(line);
Serial.println();
Serial.println("closing connection");
}
1 Like
Costas
March 14, 2018, 1:29pm
6
@AND or just use Blynk’s Webhook widget with ArduinoJson.h.
1 Like