2
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
String url = "http://192.168.31.170/api/mode/qwertyui";
void setup() {
 USE_SERIAL.begin(9600);
 USE_SERIAL.println();
 USE_SERIAL.println();
 USE_SERIAL.println();
 for (uint8_t t = 4; t > 0; t--) {
 USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
 USE_SERIAL.flush();
 delay(1000);
 }
 WiFi.mode(WIFI_STA);
 WiFiMulti.addAP("Robotics Incubator", "XXXXXXX");
}
void loop() {
 // wait for WiFi connection
 if ((WiFiMulti.run() == WL_CONNECTED)) {
 HTTPClient http;
 http.begin(url); //HTTP
 int httpCode = http.GET();
 if (httpCode == 200) {
 // Parsing
 const size_t bufferSize = JSON_OBJECT_SIZE(1) + 50;
 DynamicJsonBuffer jsonBuffer(bufferSize); //This was not declared error.
 JsonObject& root = jsonBuffer.parseObject(http.getString());
 // Parameters
 int Mode = root["mode"]; // 1
 Serial.print("Name:");
 Serial.println(Mode);
 }
 http.end();
 }
 if (Serial.available()) {
 url = Serial.readString();
 }
 delay(100);
}

How can I solve this problem? I followed this tutorial - ESP8266: Parsing JSON

per1234
4,2782 gold badges23 silver badges43 bronze badges
asked Jul 11, 2018 at 22:05

2 Answers 2

5

This error is caused by using a 6.x.x version of the ArduinoJson library with code that was written for a pre-6.x.x version of the library.

You have two options to solve the problem:

A. Downgrade the library to a version that is compatible with your code

For now, this is probably the best option because the 6.x.x version of the ArduinoJson is still in beta so it makes sense to wait until the new API is stabilized before porting your code. This is even recommended by the ArduinoJson developers:

https://arduinojson.org/v5/faq/error-jsonbuffer-was-not-declared-in-this-scope/

  1. Sketch> Include Library> Manage Libraries...
  2. Wait for the download to finish.
  3. In the "Filter your search..." box, type: "arduinojson".
  4. Click on "ArduinoJson by Benoit Blanchon".
  5. From the "Select version" dropdown menu, select "Version 5.13.2".
  6. Click "Update". Wait for the update to finish.
  7. Click "Close".

Now your code will compile. If you have File> Preferences> Check for updates on startup enabled, you will continue to get updatable library notification for the ArduinoJson library but you need to refrain from updating back to a 6.x.x version or the error will come back.

B. Update your code to be compatible with the 6.x.x version of the ArduinoJson library

In this case you need to modify your deserialization code to use the new DynamicJsonDocument instead of the old DynamicJsonBuffer:

if (httpCode == 200) {
 // Parsing
 const size_t bufferSize = JSON_OBJECT_SIZE(1) + 50;
 DynamicJsonDocument jsonDocument(bufferSize);
 DeserializationError error = deserializeJson(jsonDocument, http.getString());
 if (error) {
 Serial.println("There was an error while deserializing");
 }
 else {
 JsonObject root = jsonDocument.as<JsonObject>();
 // Parameters
 int Mode = root["mode"]; // 1
 Serial.print("Name:");
 Serial.println(Mode);
 }
}

You can get more details about this here:

https://arduinojson.org/v6/doc/upgrade/

answered Jul 12, 2018 at 0:30
0

This answer needs to be updated for anyone who visits here. The 6.x.x is no longer in beta. Simply update to the latest version. At the time of writing this answer the version id is 6.15.2. Updating to this will resolve the error.

answered Jun 7, 2020 at 14:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.