I'm doing a project where my Arduino
uses an external ESP8266
wifi module (with AT
firmware) to send http requests and receive server response.
I'm trying to get an NBA scoreboard, and here's what my Arduino sends to ESP:
> AT+CIPSTART=0,"TCP","data.nba.net",80
0,CONNECT
OK
> AT+CIPSEND=0,103
SEND OK
> GET /data/10s/prod/v1/20190214/scoreboard.json HTTP/1.1
Host: data.nba.net
Connection: keep-alive
+IPD,0,1460:HTTP/1.1 200 OK..
.............................
...here comes the response...
.............................
Now the code works fine, and I'm able to get the json
file needed. The problem is that the response is sometimes too long and the file gets truncated, thus the response is incomplete. The file itself is sometimes pretty large, but I only need a few numbers from it (current teams + current score). So my questions are:
- I use
readString()
method (ofSoftwareSerial
object instance) to read the response. Is there a way to parse the response chunk by chunk without loading everything in my ESP memory? - Is there a way to limit the response?
- Are there any alternatives to the method I'm using? Maybe parsing the website (
nba.com
orespn.com/nba
) directly? If so, how can I do that? - Maybe there's a way to write a separate (free) online API to parse
json
, constraint the response and send the small version upon request?
PS. I tried doing the same without AT
firmware, flashing the module with a code that used HTTPClient
directly (with ESP8266WiFi.h
and ESP8266HTTPClient.h
libraries):
HTTPClient http;
http.begin(request);
if (http.GET() > 0) {
response = http.getString();
}
http.end();
That didn't help much. I'm still running out of memory since I'm directly loading the response to memory with getString()
.
PPS. Just in case it matters, I'm using ATmega2560
and a small ESP-01
module (similar to this).
large
... you'll need to be more specific thanlarge
> 10 KB
is what I would call large. I think above that it just ignores the rest of the response.