BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Getting specific data using webhook

Hello,

I’m looking to build a greenhouse monitor. I have it working great with temperature and humidity monitoring, inside and out.

The whole thing is supposed to open a window, which I will need to close if the wind picks up. Thus, I would really like to be able to gather wind data as well. But the sensors to do this are out of my price range

I have found a website that has live wind data, recorded near me. I was hoping to be able to scrape this data from the website to the NodeMCU v1.0 that I am using. (https://wind.willyweather.co.uk/se/east-sussex/lewes.html)

I was looking to get these 2 data points into the app, I was hoping to do this through the Web Hook widget. However, i cant seem to find documentation on only getting a small part of a webpage. B

ut despite my best efforts I have been unsuccessful in my attempts so far.

Thank you in advance for any help you can provide :slight_smile:

You’d need to use their API, for which you’d need to set-up an account and obtain an API key. The details of how to do this, and the API documentation are here:
https://www.willyweather.co.uk/info/api.html

1 Like

Wind speed sensors like this:


aren’t expensive.

I’ve made a weather station using this type of sensor and it’s fairly easy to do. Each rotation of the anemometer produces a number of pulses from a reed switch (two pulses per revolution from memory). You just count the pulses using an external interrupt routine and calculate how many you’ve received over a given period of time.

Pete.

Thank you so much for the reply and the help!

I had no clue that that was a way it could be done, I was expecting to have to set up my own server in order to scrape data from the website.

After a little bit of searching I came across another weather website that offers a limited, but free API key: openweathermap.org

The result of the return looks a like this:
{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":300,"main":"Drizzle","description":"light intensity drizzle","icon":"09d"}],"base":"stations","main":{"temp":280.32,"pressure":1012,"humidity":81,"temp_min":279.15,"temp_max":281.15},"visibility":10000,"wind":{"speed":4.1,"deg":80},"clouds":{"all":90},"dt":1485789600,"sys":{"type":1,"id":5091,"message":0.0103,"country":"GB","sunrise":1485762037,"sunset":1485794875},"id":2643743,"name":"London","cod":200}

Which to me looks a little bit daunting. This is obviously in the .json format, but I was wondering how to get the “wind”:{“speed”:4.1, data without worrying about any of the other garble.

Sorry for the hassle, and thank you so much for the help.

Maybe take a look at this thread…

Pete.

1 Like

After reading this thread, I learnt about the json parsing library from arduinojson.org

I am trying to use this but I seem to be encountering some resistance.

#define BLYNK_MAX_READBYTES 1024

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ArduinoJson.h>


char auth[] = "7b98fef52cf04336a72410369668****";

char ssid[] = "**SSID**";
char pass[] = "**PSWD**";

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  StaticJsonBuffer<1024> jsonBuffer;

  Blynk.virtualWrite(V8, "http://api.openweathermap.org/data/2.5/weather?id=7290688&APPID=1f7238a8c0f08b401922637efe12****");
}

void loop()
{
  Blynk.run();
}


BLYNK_WRITE(V8)
{
  String json = param.asStr();
  Serial.println("WebHook data:");
  Serial.println(json);
  
  JsonObject& root = jsonBuffer.parseObject(json);

  int windSpeed = root["wind"][0];
  Serial.println(windSpeed);
}

Every time I try and compile it, I get errors:


WebHook_GET:74:22: error: 'jsonBuffer' was not declared in this scope

   JsonObject& root = jsonBuffer.parseObject(json);

                      ^

Multiple libraries were found for "ArduinoJson.h"
 Used: C:\Users\insti\Documents\Arduino\libraries\ArduinoJson
 Not used: C:\Users\insti\Documents\Arduino\libraries\ArduinoJson-6.x
exit status 1
'jsonBuffer' was not declared in this scope

I feel as though there is something obvious I’m missing, after an hour of contemplating I haven’t managed to figure it out.

Thanks yet again for your incite!

This means that you have more than one JSON library installed, and the one that it’s using is not the JSON v6 one that the examples you are using relate to.

The easiest solution is to move the files that live here:

to somewhere where the Arduino IDE can’t see them, or to delete them entirely.

Pete.

2 Likes

Thank you so much for the help!!!

I guess it makes sense to read error messages >.>

If anyone else is looking to do something similar this is my final code, with a WebHook widget in the app attached to V8.

#include <ArduinoJson.h>
#define BLYNK_PRINT Serial
#define BLYNK_MAX_READBYTES 1024

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>



char auth[] = "___AUTH TOKEN___";

char ssid[] = "___SSID___";
char pass[] = "___PSWD___";


void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  Blynk.virtualWrite(V8, "http://api.openweathermap.org/data/2.5/weather?id=7290688&APPID=1f7238a8c0f08b401922637efe12****");

}


void loop() {
  Blynk.run();
}

BLYNK_WRITE(V8)
{
  StaticJsonDocument<1024> doc;
  String json = param.asStr();
  Serial.println("WebHook data:");
  Serial.println(json);
  deserializeJson(doc, json);
  float windSpeed = doc["wind"]["speed"];
  Serial.println(windSpeed);
}

This will print the raw JSON and then the wind speed - the piece of data I was looking for.

[57] Connecting to SSID
[561] Connected to WiFi
[561] IP: 192.168.1.102
[561] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[635] Connecting to blynk-cloud.com:80
[1106] Ready (ping: 28ms).
WebHook data:
{"coord":{"lon":0.01,"lat":50.88},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":296.05,"pressure":1011,"humidity":60,"temp_min":292.59,"temp_max":299.26},"visibility":10000,"wind":{"speed":1.5},"clouds":{"all":0},"dt":1561845593,"sys":{"type":1,"id":1413,"message":0.0102,"country":"GB","sunrise":1561780133,"sunset":1561839453},"timezone":3600,"id":7290688,"name":"Lewes District","cod":200}
1.50

Thank you soo much for your help and time, I am blown away by how fast and inciteful you have been. <3

2 Likes

@Martin, very happy to help a fellow Blynker. It’s refreshing to just have to point you in the right direction and you do the rest.

Thanks for sharing your final code, it makes a big difference when people do this.

Pete.

@Martin Thanks for posting this code, it helped me figure out my project as well.

1 Like

No problem dude, glad I could help. Thanks for letting me know <3