Read or GET data from a website

What is the best way for Arduino to read data from a text field from a website? I have looked at various libraries and can’t seem to find one that will accomplish this without a TON of extra overlap.

When the site is loaded, a single text field exists and is already populated with data (0 or a 1). I do not need to post it or anything, the text field is already populated with the data.

This is what the field looks like in HTML:

Is there an HTTP server/client or restful way of the arduino board (mkr1000) to just read that text value and store it in a variable?

Thanks so much for any advice. :slight_smile:

The WiFi101 documentation is worth a read if you haven't already.
And see in particular the web client example.

A full on HTML parser would be likely be unreasonable on a low RAM device, so instead you just read the returned HTML and look for a string of text that identifies the section of interest, eg. id="bState", read on for the value that immediately follows and then extract the value.
It might be easiest for you to read the input stream line by line and search each line for the interesting stuff.

See Robin2's excellent tutorial on serial input for advice.

Ok, so, I wrote an API that does the trick. however, my issue now is that I am unable to get the data I need with an HTTP GET request to the server.

The data I am trying to receive from mysite url at /api/boardState is in this form:

{"status":200,"status_message":"Board State Found","data":"2"}

This is my current client GET

if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /api/boardState?data HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}

When I get the sketch uploaded, I get the following:

Connected to network
My IP address is: 10.0.0.26
connecting...
connected
HTTP/1.1 404 Not Found
Date: Fri, 26 Oct 2018 23:20:01 GMT
Server: Apache
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Content-Length: 1699
Connection: close
Content-Type: text/html

If try the get request with as follows (change to HTTP /1.1):
client.println("GET /api/boardState?data HTTP/1.1");
I get the following message:

Connected to network
My IP address is: 10.0.0.26
connecting...
connected
HTTP/1.1 400 Bad Request
Date: Fri, 26 Oct 2018 23:33:26 GMT
Server: Apache
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Connection: close
Content-Type: text/html

Sticking with HTTP/1.1:

Since the server you are contacting will likely have multiple websites on it (all accessible through (maybe only) 1 IP address) you need to tell the server which website you are requesting to. You do that with a host header.

Read the HTTP/1.1 RFC page 37.