I got this error after upgrading Arduinojson to 6.21.3, what I am supposed to do? I kept changing the version for the Arduinojson but it ended with the same error, and before adding the Arduinojson part everything was working.
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <FirebaseESP8266.h>
#include "location.h"
//http
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>
//Deserialize the JSON string
#include <ArduinoJson.h>
// Firebase project configuration
#define FIREBASE_HOST ""
#define FIREBASE_AUTH ""
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
// Google API keys
String geolocationKey = "";
String geocodingKey = "";
// From http://www.mcc-mnc.com/
int MCC = 602; // Egypt Country Code
int MNC = 4; // Egypt Network Code
String carrier = "WE";
FirebaseData firebaseData;
FirebaseJson json;
Location myLocation;
// GPS Module RX pin to NodeMCU D1
// GPS Module TX pin to NodeMCU D2
const int RXPin = 4, TXPin = 5;
SoftwareSerial neo6m(RXPin, TXPin);
TinyGPSPlus gps;
// Relay pin
#define relayPin D8
// http variables
const char* serverAddress = "url";
const int serverPort = 443;
String scooter_code = "z1";
WiFiClientSecure client;
HTTPClient https;
float latitude , longitude;
//String lat_str , lng_str, speed_str;
String Speed="0";
String battery="0";
String endpoint = "/api/scooters/"+scooter_code+"/update-live-details";
String requestBody;
String payload;
void setup() {
Serial.begin(115200);
neo6m.begin(9600);
pinMode(relayPin, OUTPUT); // Set relay pin as an output
wifiConnect();
Serial.println("Connecting Firebase.....");
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
Serial.println("Firebase OK.");
myLocation.begin(geolocationKey, geocodingKey, MCC, MNC, carrier);
digitalWrite(relayPin, LOW); // Set the relay to LOW initially
// String scooterStatus="0";
}
void loop() {
smartdelay_gps(1000);
if (gps.location.isValid()) { // From GPS <=============================
latitude = gps.location.lat();
longitude = gps.location.lng();
Serial.print("latitude is: ");
Serial.println(latitude);
Serial.print("longitude is: ");
Serial.println(longitude);
if (gps.speed.isValid()){
int sped= gps.speed.kmph();
Speed = String(sped);
} else {
Speed= "Unable to get the speed!";
}
requestBody = "{"
"\"speed\": " +Speed+","
"\"current_latitude\": " +latitude+","
"\"current_longitude\": " +longitude+","
"\"battery_level\": " +battery+
"}";
Serial.println(requestBody);
// Disable certificate verification
client.setInsecure();
if (https.begin(client, serverAddress, serverPort, endpoint)) {
https.addHeader("Content-Type", "application/json");
https.addHeader("Accept", "application/json");
int httpResponseCode = https.POST(requestBody);
if (httpResponseCode == HTTP_CODE_OK) {
Serial.println(httpResponseCode);
} else {
Serial.print("POST request failed with error code: ");
Serial.println(httpResponseCode);
}
https.end();
} else {
Serial.println("Unable to connect to the server");
}
// This part to be removed ---------------------------------------------------------------------------------
if (Firebase.setFloat(firebaseData, "/GPS/f_latitude", latitude)) {
print_ok();
} else {
print_fail();
}
if (Firebase.setFloat(firebaseData, "/GPS/f_longitude", longitude)) {
print_ok();
} else {
print_fail();
}
// until her -----------------------------------------------------------------------------------------------
} else {
myLocation.getLocation(); // From Geo location <=============================
latitude = myLocation.latitude;
longitude = myLocation.longitude;
requestBody = "{"
"\"speed\": " +Speed+","
"\"current_latitude\": " +latitude+","
"\"current_longitude\": " +longitude+","
"\"battery_level\": " +battery+
"}";
// Disable certificate verification
client.setInsecure();
if (https.begin(client, serverAddress, serverPort, endpoint)) {
https.addHeader("Content-Type", "application/json");
https.addHeader("Accept", "application/json");
int httpResponseCode = https.POST(requestBody);
if (httpResponseCode == HTTP_CODE_OK) {
Serial.println(httpResponseCode);
payload = https.getString();
Serial.println("Here is the payload");
Serial.println("payload data: " + payload );
// String input;
StaticJsonDocument<192> doc;
DeserializationError error = deserializeJson(doc, payload);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
const char* status = doc["status"]; // "Data updated successfully"
const char* action_name = doc["action"]["name"]; // "set_speed_limit"
int action_value = doc["action"]["value"]; // 12
} else {
Serial.print("POST request failed with error code: ");
Serial.println(httpResponseCode);
}
https.end();
} else {
Serial.println("Unable to connect to the server");
}
// This part to be removed ---------------------------------------------------------------------------------
if (Firebase.setFloat(firebaseData, "/Geolocation/latitude", myLocation.latitude)) {
print_ok();
} else {
print_fail();
}
if (Firebase.setFloat(firebaseData, "/Geolocation/longitude", myLocation.longitude)) {
print_ok();
} else {
print_fail();
}
// until her -----------------------------------------------------------------------------------------------
}
Scooter_Relay();
delay(5000);
}
static void smartdelay_gps(unsigned long ms) {
unsigned long start = millis();
do {
while (neo6m.available())
gps.encode(neo6m.read());
} while (millis() - start < ms);
}
void wifiConnect() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
}
void print_ok() {
Serial.println("------------------------------------");
Serial.println("OK");
Serial.println("PATH: " + firebaseData.dataPath());
Serial.println("TYPE: " + firebaseData.dataType());
Serial.println("ETag: " + firebaseData.ETag());
Serial.println("------------------------------------");
Serial.println();
}
void print_fail() {
Serial.println("------------------------------------");
Serial.println("FAILED");
Serial.println("REASON: " + firebaseData.errorReason());
Serial.println("------------------------------------");
Serial.println();
}
void Scooter_Relay() {
String scooterStatus="0";
// Check and control the scooter status
if (Firebase.getString(firebaseData, "/Scooter/Status")) {
scooterStatus = firebaseData.stringData(); // Get the string data
} else {
print_fail();
}
if (!scooterStatus.isEmpty()) {
if (scooterStatus == "1") {
digitalWrite(relayPin, HIGH); // Set the relay to HIGH
} else if (scooterStatus == "0") {
digitalWrite(relayPin, LOW); // Set the relay to LOW
}
}
Serial.print("Scooter Status: ");
Serial.println(scooterStatus);
}
Here is the Error I got, some people says that the esp8266 is not compatible with the ArduinojSON version, if so what version of the lib should I use
C:\Users\haidi\OneDrive\Documents\Arduino\libraries\Location\location.cpp:37:1: error: 'DynamicJsonBuffer' does not name a type
37 | DynamicJsonBuffer jsonBuffer(320);
| ^~~~~~~~~~~~~~~~~
C:\Users\haidi\OneDrive\Documents\Arduino\libraries\Location\location.cpp: In member function 'void Location::geolocation()':
C:\Users\haidi\OneDrive\Documents\Arduino\libraries\Location\location.cpp:157:24: error: 'jsonBuffer' was not declared in this scope
157 | JsonObject& root = jsonBuffer.parseObject(response);
| ^~~~~~~~~~
C:\Users\haidi\OneDrive\Documents\Arduino\libraries\Location\location.cpp:158:13: error: 'ArduinoJson::JsonObject' {aka 'class ArduinoJson690_000::ObjectRef'} has no member named 'success'
158 | if(root.success()){
| ^~~~~~~
C:\Users\haidi\OneDrive\Documents\Arduino\libraries\Location\location.cpp: In member function 'void Location::geocoding()':
C:\Users\haidi\OneDrive\Documents\Arduino\libraries\Location\location.cpp:202:24: error: 'jsonBuffer' was not declared in this scope
202 | JsonObject& root = jsonBuffer.parseObject(response);
| ^~~~~~~~~~
C:\Users\haidi\OneDrive\Documents\Arduino\libraries\Location\location.cpp:203:13: error: 'ArduinoJson::JsonObject' {aka 'class ArduinoJson690_000::ObjectRef'} has no member named 'success'
203 | if(root.success()){
| ^~~~~~~
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).