Hello,
I use NodeMCU 1.0 and Blynk webhook widget to get data from openweathermap.org, trying to display weather condition (such as temp, hum, press, weather condition, sunrise, sunset, etc) to my 16X2 LCD. I also do Json parse since the coming data is in Json format.
When I try to serial print the result for each weather condition, values come out correctly and get updated when the there is some changes based on the data coming from openweathermap.org.
But, when I try to display those value in my 16X2 LCD also, suddenly, the data displayed both on serial print and LCD, did not updated. Even the Json responses is always same since beginning.
Really appreciate for any help here.
Btw, here is my sketch:
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how to fetch data using WebHook GET method
App project setup:
WebHook widget on V0, method: GET, url: /pin/
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
// Allow for receiving messages up to 512 bytes long
#define BLYNK_MAX_READBYTES 1024
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "mytokenhere";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "mywifihere";
char pass[] = "mypasswordhere";
String webhookdata;
int counter = 10;
String description = "";
float temperature;
int pressure;
int humidity;
float windspeed;
int winddeg;
String country;
String sunrise;
String sunset;
String city = "";
BlynkTimer timer;
BLYNK_WRITE(V0) {
webhookdata = param.asStr();
}
void getNewData() {
if (counter == 10) {
Serial.println("counter 10");
counter = 0;
Blynk.virtualWrite(V0, "http://api.openweathermap.org/data/2.5/weather?id=1860243&APPID="myAPIhere");
Serial.println(webhookdata);
}
else {
counter++;
}
}
void splitJson() {
const size_t bufferSize = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + JSON_OBJECT_SIZE(12) + 400;
DynamicJsonBuffer jsonBuffer(bufferSize);
String wJson = webhookdata;
JsonObject& root = jsonBuffer.parseObject(wJson);
float Longitude = root["coord"]["lon"]; // 136.63
float Latitude = root["coord"]["lat"]; // 36.59
JsonObject& weather0 = root["weather"][0];
int weatherID = weather0["id"]; // 801
String Main = weather0["main"]; // "Clouds"
String Description = weather0["description"]; // "few clouds"
String Icon = weather0["icon"]; // "02d"
String base = root["base"]; // "stations"
JsonObject& main = root["main"];
float Temperature = main["temp"]; // 18.48
int Pressure = main["pressure"]; // 1020
int Humidity = main["humidity"]; // 55
int TempMin = main["temp_min"]; // 18
int TempMax = main["temp_max"]; // 19
int Visibility = root["visibility"]; // 10000
float WindSpeed = root["wind"]["speed"]; // 5.1
int WindDeg = root["wind"]["deg"]; // 10
int CloudsAll = root["clouds"]["all"]; // 20
long dt = root["dt"]; // 1508997600
JsonObject& sys = root["sys"];
int SysType = sys["type"]; // 1
int SysID = sys["id"]; // 7567
float SysMessage = sys["message"]; // 0.0046
String Country = sys["country"]; // "JP"
String Sunrise = sys["sunrise"]; // 1508965858
String Sunset = sys["sunset"]; // 1509005000
long id = root["id"]; // 1860243
String City = root["name"]; // "Kanazawa-shi"
int cod = root["cod"]; // 200
Serial.println(City);
Serial.println(Country);
Serial.println(Description);
Serial.println(Temperature);
Serial.println(Pressure);
Serial.println(Humidity);
Serial.println(WindSpeed);
Serial.println(WindDeg);
Serial.println(Sunrise);
Serial.println(Sunset);
city = City;
country = Country;
description = Description;
temperature = Temperature;
pressure = Pressure;
humidity = Humidity;
windspeed = WindSpeed;
winddeg = WindDeg;
sunrise = Sunrise;
sunset = Sunset;
}
void showLCD() {
lcd.backlight();
lcd.clear();
lcd.home();
lcd.setCursor(0, 0);
lcd.print(" OpenWeatherMap");
lcd.setCursor(0, 1);
lcd.print(" Today Forecast");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(city);
lcd.print(", ");
lcd.print(country);
lcd.setCursor(0,1);
lcd.print(description);
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.print(temperature);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(8, 0);
lcd.print(" H:");
lcd.print(humidity);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("P:");
lcd.print(pressure);
lcd.print(" hPa");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Wind:");
lcd.print(windspeed);
lcd.print(" m/s");
lcd.setCursor(0,1);
lcd.print("Direction:");
lcd.print(winddeg);
lcd.print((char)223);
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Today Sunrise");
lcd.setCursor(0, 1);
lcd.print(sunrise);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Today Sunset");
lcd.setCursor(0, 1);
lcd.print(sunset);
delay(2000);
}
void setup()
{
// Debug console
Serial.begin(9600);
lcd.begin(0,2); // sda=0 | D3, scl=2 | D4
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
//Blynk.virtualWrite(V0, "https://raw.githubusercontent.com/blynkkk/blynk-library/master/extras/logo.txt");
// You can perform HTTPS requests even if your hardware alone can't handle SSL
// Blynk can also fetch much bigger messages,
// if hardware has enough RAM (set BLYNK_MAX_READBYTES to 4096)
timer.setInterval(10000L, getNewData);
timer.setInterval(11000L, splitJson);
timer.setInterval(15000L, showLCD);
}
void loop()
{
Blynk.run();
timer.run();
}
Thanks in advance,
Imron