Error compiling for board ESP32 Dev module.
Hello! I'm here seeking your assistance please. I have been working with arduino and esp32 module for posting some data to a dedicated platform. However, upon modifying the data to json supported format as shown below the error started to emerge.
//----------------------------------------GET HTTP Request
// Prepare POST request data
DynamicJsonDocument doc(1024);
doc["dht_sensor_API_KEY"] = apiKeyValue;
doc["temperature"] = temperature;
doc["humidity"] = humidity;
// Serialize data to JSON
serializeJson(doc, httpRequestData);
// Send POST request
httpResponseCode = http.POST(httpRequestData);
I'm working on a personal project that involves sending DHT sensor data toa dedicated hosted platform with telemetry data packaged in JSON format using DynamicJsonDocument
.as shown in my actual code snippet below
#include <ESP_WiFiManager.h>
#include <Arduino_JSON.h>
#include <ArduinoJson.h>
//----------------------------------------Support libraries and sensor parameters.
#ifdef ESP32
#include <WiFi.h>
#include <HTTPClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
// #include <analogWrite.h>
#else
// #include <ESP8266WiFi.h>
// #include <WiFiClient.h>
// #include <ESP8266HTTPClient.h>
// #include <ESP8266WebServer.h>
// #include <ESP8266mDNS.h>
#endif
#include <Arduino_JSON.h>
#define ON_Board_LED 2
#define DHT_PIN 27
#define DHT_SENSOR_TYPE DHT11
DHT dht_sensor(DHT_PIN, DHT_SENSOR_TYPE);
//----------------------------------------
/*
SEND DHT DATA TO THE SERVER BASED ON
PROJECT API_KEY
06-02-023
*/
//----------------------------------------Network credentials definition.
const char* ssid = ""; //--> Your wifi name or SSID.
const char* password = ""; //--> Your wifi PASSWORD.
String apiKeyValue = "";
//const char* server_url = "http://192.168.1.111/api/led_state_control";
const char* server_url = "";
//----------------------------------------
//----------------------------------------Control variables.
int temperature;
int humidity;
int humid_threshold;
int temp_threshold;
String payload;
WiFiClient client;
HTTPClient http;
String httpRequestData= "0";
int httpResponseCode= 0;
unsigned long lastTime = 0;
unsigned long timerDelay = 5000;
//----------------------------------------
void setup() {
Serial.begin(115200);
delay(10);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
pinMode(ON_Board_LED,OUTPUT); //--> On Board LED port Direction output
digitalWrite(ON_Board_LED, HIGH); //--> Turn off Led On Board
Serial.print("Connecting.");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
//----------------------------------------Make the On Board Flashing LED on the process of connecting to the wifi router.
digitalWrite(ON_Board_LED, LOW);
delay(250);
digitalWrite(ON_Board_LED, HIGH);
delay(250);
//----------------------------------------
}
//----------------------------------------
digitalWrite(ON_Board_LED, LOW); //--> Turn off the On Board LED when it is connected to the wifi router.
//----------------------------------------If successfully connected to the wifi router, the IP Address that will be visited is displayed in the serial monitor
Serial.println("");
Serial.print("Successfully connected to : ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
dht_sensor.begin(); // initialize the DHT sensor
//----------------------------------------
Serial.println("Server started");
Serial.println(WiFi.localIP());
Serial.println("");
delay(1000);
Serial.print("connecting...");
delay(2000);
}
void loop() {
// Initialize http protocol
http.begin(client, server_url);
// take sensor readings
humidity = dht_sensor.readHumidity();
temperature = dht_sensor.readTemperature();
// check whether the reading is successful or not
if ( isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// get server response from handler fn
String dht_data = httpGETRequest(server_url);
// decode response
JSONVar json_res_data = JSON.parse(dht_data);
// validate response type
if(JSON.typeof(json_res_data) == "undefined"){
Serial.println("Parsing input failed!");
return;
}
// decode actual dht data
humidity = (const int)(json_res_data["humidity"]);
temperature = (const int)(json_res_data["temperature"]);
humid_threshold = (const int)(json_res_data["humid_threshold"]);
temp_threshold = (const int)(json_res_data["temp_threshold"]);
Serial.println("");
Serial.println("Temp: " + String(temperature));
Serial.println("Humidity: " + String(humidity));
Serial.println("Temp threshold: " + String(temp_threshold));
Serial.println("Humid threshold: " + String(humid_threshold));
delay(60000);
}
// GET request function
String httpGETRequest(const char* serverName) {
//Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
//----------------------------------------GET HTTP Request
// Prepare POST request data
DynamicJsonDocument doc(1024);
doc["dht_sensor_API_KEY"] = apiKeyValue;
doc["temperature"] = temperature;
doc["humidity"] = humidity;
// Serialize data to JSON
serializeJson(doc, httpRequestData);
// Send POST request
httpResponseCode = http.POST(httpRequestData);
//----------------------------------------
//----------------------------------------GET HTTP Request
if (httpResponseCode == 200) { //initialize payload if GET data is available
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
Serial.println("");
Serial.print("Payload: ");
Serial.print(payload);
Serial.println("");
}
else { //error if no GET data
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
//----------------------------------------
}
Compiling this with all necessary connection details appended I get this error:
Exit status 1 Error compiling for board esp32 Dev Module