I have written this sketch, and I am trying to populate the array of wifi hotspots to set the value in html select using javascript dynamically.
#include <Arduino.h>
#include <Hash.h>
#include "ESP8266WiFi.h"
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
const char* ap_ssid = "ESP8266";
const char* ap_password = "0123456789";
// Create AsyncWebServer object on port 8080
AsyncWebServer ap_server(8080);
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html {
font-family: Arial;
display: inline-block;
margin: 0px auto;
text-align: center;
}
h2 { font-size: 3.0rem; }
p { font-size: 3.0rem; }
.units { font-size: 1.2rem; }
.dht-labels{
font-size: 1.5rem;
vertical-align:middle;
padding-bottom: 15px;
}
</style>
<script>
var select = document.getElementById("wifi");
hotspots = %wifi_networks%;
for(index in hotspots) {
select.options[select.options.length] = new Option(hotspots[index], index);
}
</head>
<body>
<h2>Connect to a Wifi Networks</h2>
<p>
<form action="#">
<label for="wifi">Choose a hotspot to connect:</label>
<select name="wifi" id="wifi">
<option value="volvo">None</option>
</select><br>
<label for="wifi">Enter password:</label>
<input type="text"></input>
<br><br>
<input type="rescan" value="Rescan">
<input type="submit" value="Connect">
</form>
</p>
</body>
</script>
</html>)rawliteral";
void setup() {
Serial.print("Setting AP (Access Point)…");
// Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ap_ssid, ap_password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
// Print ESP8266 Local IP Address
Serial.println(WiFi.localIP());
// Route for root / web page
ap_server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send_P(200, "text/html", index_html, getWifiHotspots());
});
// Start server
ap_server.begin();
}
void loop() {
// put your main code here, to run repeatedly:
}
But I am geting this error
/Arduino/libraries/ESPAsyncWebServer/src/ESPAsyncWebServer.h:243:10: error: initializing argument 4 of 'void AsyncWebServerRequest::send_P(int, const String&, const uint8_t*, size_t, AwsTemplateProcessor)' [-fpermissive]
void send_P(int code, const String& contentType, const uint8_t * content, size_t len,
AwsTemplateProcessor callback=nullptr);
^
exit status 1
invalid conversion from 'const char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
send_P(200, "text/html", (uint8_t *)index_html, getWifiHotspots());
. – JSC May 24 '20 at 21:05