Best way to read data from http web page or web server

So, I want the boron to read data from a web page to configure itself when it wakes up. I understand that normally variables or functions could be use for this, but in my configuration the boron is mostly sleeping. Having a particle.function or variable called when it wakes up to reconfigure a parameter is unreliable.

I would like the boron to actively read the page when it wakes up, rather than have something outside the boron tickle the function block. This seems like a simple thing, but there is nothing that I can find that fits the bill.

I did find someone who posted this code below, which I will try. But I would have thought particle would have a library function for doing this as it seems pretty basic. If someone has a recommendation please let me know. Thanks.

String host = "toptalkback.com";
const int serverPort = 80;

String DownloadJson(String url){
    String output;
    if(client.connect(host, serverPort)) {
        client.println("GET "+url+" HTTP/1.0");
        client.println("Host: " + host);
        client.printlnf("Content-Length: %d", 2);
        client.println("Content-Type: application/json");
        client.println();
        client.flush();
        delay(5000);
        while(client.available()) {
            char c = client.read();
            output = output + c;
        }  
    } 
    
    return output;
}

Thanks for any feedback or suggestions.

An alternative way to remote configure the device might be Device Notes in Particle Console.
These can be set in Console or via API and requested via a Particle.publish() / Particle.subscribe() combo.

Otherwise, you could also use HTTPClient and issue a GET request against any HTTP (not HTTPS) server and parse the response body.

1 Like

Thanks, this worked reasonably well.

1 Like