Get data from web with the push of a button : )

Hello Blynkers,

Im trying to get the time the sun sets over the internet, so my lights turn on automatically when it gets dark.
I tried to do this, but for some reason i do not get any response. Can anyone help me?
I know this is not entirely Blynk related, but i am not really in another arduino programming community, so im just asking it over here :).

right now i have this. When i press the button connected to V5, the data should print to the terminal… atleast thats what i thought. What am i doing wrong?

``BLYNK_WRITE(V5)
{
if (client.connect(“api.sunrise-sunset.org/”, 80))
{
client.println(“GET /json?lat=53.1309000&lng=6.566667&date=today HTTP/1.0”);
client.println();
while (client.connected())
{
while (client.available())
{
Serial.write(client.read());
}
}
client.stop();
}
}````

Many thanks,

Bas Peter

Hello. First thing is - HTTP GET requests could be very slow. And BLYNK_WRITE should be executed as fast as possible. This means putting HTTP request within BLYNK_WRITE is not recommended. It would be better to do something like that (pseudo code) :

BLYNK_WRITE(V5)
{
    flag = true;
}
//below some logic in LOOP or better in TIMER method:
if (flag) {
    result = getTempWithHttp();
    flag = false;
}

Also make sure your code works without Blynk itself.
Also not sure but maybe “http://” is required for domain name. http://api.sunrise-sunset.org

1 Like

Also, please note that it depends on your hardware. Some devices can not process multiple connections in parallel!
Blynk maintains single connection over time.

Oh that could be the case. I am using an arguing UNO with an Ethernet shield. Is this a problem for my hardware?

Arduino* still loving autocorrect :wink:

How about using a LDR?