I'm trying to send array by using wifi and I use this code: I depend on this code in link: here
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
const char* ssid = "ESP32-Access-Point";
const char* password = "***";
AsyncWebServer server(80);
unsigned char a[10] = {22, 23, 27, 18, 19, 20, 21, 25, 23, 22};
String json;
void setup(){
Serial.begin(115200);
Serial.println();
Serial.print("Setting AP (Access Point)…");
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
json = "{ \"temp\" : [" + (String)a[0];
for (int i=1; i < sizeof(a); i++) {
json += "," + (String)a[i];
}
json += "] }";
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "application/json",json);
});
bool status;
server.begin();
}
void loop(){}
How can I receive the values as value because I need to deal with this received array to do some processing before print it : This is the code for receiving array (I posted just the loop):
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
if(WiFi.status()== WL_CONNECTED ){
temperature = httpGETRequest(serverNameTemp); // Here I
// need to deal with the received values
Serial.println("Temperature: " + temperature );
Serial.println(temperature);
// save the last HTTP GET Request
previousMillis = currentMillis;
}
else {
Serial.println("WiFi Disconnected");
}
}
}
String httpGETRequest(const char* serverName) {
WiFiClient client;
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(client, serverName);
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "--";
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}
payload? use the ArduinoJson librarystrtokandatoi