Read data from the web with Webhook

Perhaps I should rephrase that. Say X number of fields to be available from each API. So all fields technically being available but a limitation on how many can be used within Blynk at any one time. As you will know some API’s have hundreds of fields and it wouldn’t be practical to be working on all of them within Blynk.

I parse all fields, so I can use anything which it returns. You can choose wether to use it or not, but everything is there, yes :slight_smile:

Well, I was thinking on how your code could be simplified with Blynk. Because when I look in @Costas parsing code I feel pain :slight_smile:.

1 Like

@Dmitriy yes painful to a real coder. Please note my parsing is for api.wunderground.com not api.sunrise-sunset.org and wunderground has lots more stuff in addition to the astronomy api.

This is not because of your code, this parsing in general is complex and I believe it is impossible task for most of Blynkers.

You would be in agony then if you saw what we do when we parse Blynk’s “project” api.

1 Like

Well, how far do you want to go? It may be enough to write a basic parser for “known” API’s or basic XML feeds.

I have very simple idea in case you need only 1 field. But I don’t know how to deal with many fields. For example in case you need only 1 field from above response you could specify in widget :

results.sunrise

and Blynk will return you only 1 string 5:43:55 AM

1 Like

It would be even more pretty if it returned a time variable … :wink:

But that would be a nice basic idea. It may be nice for the user if they can choose how to get the data back, e.g. int, string, time

@Dmitriy a return String as you have indicated would be pretty useless for Blynkers. Needs to reflect the type of variable e.g. time.

But this is just 1 field… You may need dozens.

Possibly yes, haha. Am I hurting your brain al ready too much? :wink:

1 Like

https://github.com/bblanchon/ArduinoJson this could be the answer …

2 Likes

@Lichtsignaal it’s an excellent library that I use on a regular basis and by far the most popular Json parser there is. I wouldn’t normally recommend “manual” parsing.

@naamah75 in case you missed latest update. Now this feature is implemented. However getting exactly what you need may be not so easy.

1 Like

I’ve been out for work! I will try it ASAP. :thumbsup:

1 Like

I made some test with webhook, in my project I have a webhook widget as follow…

… and this is my sketch …

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <WiFi.h>
#include <BlynkSimpleWifi.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "802d623481724fedaabf96aa31e3a174";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "FRITZ!Box Fon WLAN 7390";
char pass[] = "4506523768287213";
char server_ip[] = "192.168.1.110";
int port = 8442;

void setup() {
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass, server_ip, port);
}

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

BLYNK_CONNECTED() {
  Serial.println("BLYNK_CONNECTED()");
  Blynk.virtualWrite(V0, "");
}

BLYNK_WRITE(V0) {   
  Serial.println("BLYNK_WRITE(V0)");
  String value = param.asStr(); 
  Serial.println(value);  
}

BLYNK_WRITE(V1) {
  Serial.println("BLYNK_WRITE(V1)");
  int value = param.asInt(); 
  Serial.println(value);
  if (value == 1) Blynk.virtualWrite(V0, "");
}

Unfortunately I’ve no data back from web… what’s wrong?

Please look in docs - http://docs.blynk.cc/#widgets-other-webhook it could be big content.

Also you need to send at least 1 char.

1 Like

YESSS!!! it works!
:hugging: