HTTP response size (Esp8266)

Hello!
I've been at this for a couple of days and I'm having trouble understanding a solution. I'm doing an http request on my esp8266 expecting a json file that i'll parse for later use. But the problem I'm encountering is that the "http.getString()" returns only a sliver of the json file. I'm having a hard time finding documentation regarding size of the return and I'm at my wits end.

Here is the relevant parts of the code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char *ssid     = "xxx";
const char *password = "xxx";
const char* serverName = "http://............";

WiFiClient wifiClient;

.
.
.
.

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

  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }
  Serial.println("Wifi Connected");
}

void loop() {
  int urgency;
  String jsonFile;

  HTTPClient http;  
  http.begin(wifiClient, serverName);	

  int httpResponseCode = http.GET();
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    jsonFile = http.getString();
    Serial.println(jsonFile);
  }
  delay(10000); 
}

The usual length of a response I'm expecting could be roughly 12000 chars but I'm usually only getting < 10%

Is there another way to get the data, maybe as a bytestream or anything else. As long as i can get the full message.

I think you can treat the client as a stream:

    while (http.available())
      Serial.print(http.read();

When the time comes to deserialize your JSON, you can do that directly into a JSON document:

StaticJsonDocument<999> doc;

DeserializationError error = deserializeJson(doc, http);

if (error) {
  Serial.print("deserializeJson() failed: ");
  Serial.println(error.c_str());
  return;
}

Given an example of the JSON, the ArduinoJson 'Assistant' can write the code for you:

Unfortunantly it seems like the http library im using for the Esp8266 (<ESP8266HTTPClient.h>) doesnt have a http.available (or any similar function as to what i can see). I've tried using the <ArduinoHttpClient.h> library as well but it is not behaving well (or at all).

But thanks for the deserialization that might come in handy if i manage to fix my first problem

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.