Incompatible types in assignment

im trying to convert from “non asynchttp” to “ESPAsyncWebServer” for esp32. i need to collect some form data from the server and process it.

My original code “non async”

//  server.on("/", [] {if (server.hasArg("ssid") && server.hasArg("Password")) {
//server.arg("ssid").toCharArray(ssid, 15);
//  server.arg("Password").toCharArray(password, 15) ;
//
//  server.send(200, "text/html", "wifi set");
//  delay(1000);
//  ESP.restart();
//} });

this is what i have so far,

#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>

const char* st_ssid = "........";
const char* password = "........";

AsyncWebServer server(80);

char ssid [10];
void setup(void) {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(st_ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    if (request->hasParam("ssid") && request->hasParam("password")) {
      ssid = request->getParam("ssid")->value();
       password = request->getParam("passsword")->value();
      request->send(200, "text/html", "wifi set");
      delay(1000);
      ESP.restart();
    }
  });

//  server.on("/", [] {if (server.hasArg("ssid") && server.hasArg("Password")) {
//server.arg("ssid").toCharArray(ssid, 15);
//  server.arg("Password").toCharArray(password, 15) ;
//
//  server.send(200, "text/html", "wifi set");
//  delay(1000);
//  ESP.restart();
//} });









  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(200, "text/plain", "Hi! I am ESP32.");
  });




void loop(void) {


}

the compiler complains,

exit status 1
incompatible types in assignment of 'const String' to 'char [10]'

how am i suppose to process the form data for a char array?

      ssid = request->getParam("ssid")->value();

Please explain exactly what this line is doing

well i dont know anything about function pointers but i assume i was way off. this is what i ended up with,

request->getParam("ssid")->value().toCharArray(_EEPROM.sta_ssid, 15);

hopefully that is correct.

now i need to make this work. this is a little over my head,

bool loadFromSpiffs(String path) {
  String dataType = "text/plain";
  if (path.endsWith("/")) path += "index.htm";
  if (path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
  else if (path.endsWith(".html")) dataType = "text/html";
  else if (path.endsWith(".htm")) dataType = "text/html";
  else if (path.endsWith(".css")) dataType = "text/css";
  else if (path.endsWith(".js")) dataType = "application/javascript";
  else if (path.endsWith(".png")) dataType = "image/png";
  else if (path.endsWith(".gif")) dataType = "image/gif";
  else if (path.endsWith(".jpg")) dataType = "image/jpeg";
  else if (path.endsWith(".ico")) dataType = "image/x-icon";
  else if (path.endsWith(".xml")) dataType = "text/xml";
  else if (path.endsWith(".pdf")) dataType = "application/pdf";
  else if (path.endsWith(".zip")) dataType = "application/zip";
  //File dataFile = LittleFS.open(path.c_str(), "r");
  File dataFile = SPIFFS.open(path.c_str(), "r");
  if (server.hasArg("download")) dataType = "application/octet-stream";
  if (server.streamFile(dataFile, dataType) != dataFile.size()) {
  }
  dataFile.close();
  return true;
}

besides the function pointer i see argument ssid convert tochararry()

I’m trying to make that function comptible, this is hat i have now,

bool loadFromSpiffs(String path) {
  String dataType = "text/plain";
  if (path.endsWith("/")) path += "index.htm";
  if (path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
  else if (path.endsWith(".html")) dataType = "text/html";
  else if (path.endsWith(".htm")) dataType = "text/html";
  else if (path.endsWith(".css")) dataType = "text/css";
  else if (path.endsWith(".js")) dataType = "application/javascript";
  else if (path.endsWith(".png")) dataType = "image/png";
  else if (path.endsWith(".gif")) dataType = "image/gif";
  else if (path.endsWith(".jpg")) dataType = "image/jpeg";
  else if (path.endsWith(".ico")) dataType = "image/x-icon";
  else if (path.endsWith(".xml")) dataType = "text/xml";
  else if (path.endsWith(".pdf")) dataType = "application/pdf";
  else if (path.endsWith(".zip")) dataType = "application/zip";
  //File dataFile = LittleFS.open(path.c_str(), "r");
  File dataFile = SPIFFS.open(path.c_str(), "r");
   if (request->hasParam("download")) dataType = "application/octet-stream"; {
 // if (server.hasArg("download")) dataType = "application/octet-stream";
  if (server.streamFile(dataFile, dataType) != dataFile.size()) {
  }
  dataFile.close();
  return true;
}

im getting compiler error,

exit status 1
'request' was not declared in this scope
exit status 1
'class AsyncWebServer' has no member named 'streamFile'

can you please help show me how to make this function work

here is the whole program,

#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <SPIFFS.h>
const char* st_ssid = "........";
const char* password = "........";

AsyncWebServer server(80);

char ssid [10];
void setup(void) {
  Serial.begin(115200);
   SPIFFS.begin();
  WiFi.mode(WIFI_STA);
  WiFi.begin(st_ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    if (request->hasParam("ssid") && request->hasParam("password")) {
     request->getParam("ssid")->value().toCharArray(ssid, 9);
    // ssid = ssid0.toCharArray(ssid, 9);
     //  password = request->getParam("passsword")->value();
      request->send(200, "text/html", "wifi set");
      delay(1000);
      ESP.restart();
    }
  });

  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(200, "text/plain", "Hi! I am ESP32.");
  });

  AsyncElegantOTA.begin(&server);    // Start ElegantOTA
  server.begin();
  Serial.println("HTTP server started");
}
void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

bool loadFromSpiffs(String path) {
  String dataType = "text/plain";
  if (path.endsWith("/")) path += "index.htm";
  if (path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
  else if (path.endsWith(".html")) dataType = "text/html";
  else if (path.endsWith(".htm")) dataType = "text/html";
  else if (path.endsWith(".css")) dataType = "text/css";
  else if (path.endsWith(".js")) dataType = "application/javascript";
  else if (path.endsWith(".png")) dataType = "image/png";
  else if (path.endsWith(".gif")) dataType = "image/gif";
  else if (path.endsWith(".jpg")) dataType = "image/jpeg";
  else if (path.endsWith(".ico")) dataType = "image/x-icon";
  else if (path.endsWith(".xml")) dataType = "text/xml";
  else if (path.endsWith(".pdf")) dataType = "application/pdf";
  else if (path.endsWith(".zip")) dataType = "application/zip";
  //File dataFile = LittleFS.open(path.c_str(), "r");
  File dataFile = SPIFFS.open(path.c_str(), "r");
   if (request->hasParam("download")) 
dataType = "application/octet-stream"; {
 // if (server.hasArg("download")) dataType = "application/octet-stream";
  if (server.streamFile(dataFile, dataType) != dataFile.size()) {
  }
  dataFile.close();
  return true;
}
void loop(void) {

  AsyncElegantOTA.loop();
}

i simply need a function to load file from spiffs. i do not want to write function after function to load specific filenames 1 at a time. my previous function when presented with a known filetype will load it and the correct datatype and load it up into a response for the client.

I have read documentation but they all show use of specific file names only. I have provided an example of what the function needs to do.

THANKS!! your cocky little comment REALLY HELPED MY SITUATION!

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