Respected all,
i am trying to make a code using ESP32 where i can connect it to a network and send data(String) from a web, addressed by the ip address of the ESP32. Till now i am able to send the string from the web and i was able to see the data received in the serial monitor.
And wanted to convert that string to Char[] (array) so that i can scroll that characters in a 8x48 led matrix.
But the problem i am facing is that i am not able to get that message received out and manipulate it to fit my requirement. I would be very grateful to any help.
the code is attached below.
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#else
#include <WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
AsyncWebServer server(80);
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "TECNO Camon I";
const char* password = "12345678";
const char* PARAM_INPUT = "ANNOUNCEMENT";
// HTML web page to handle input fields
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
<title>FINAL YEAR PROJECT</title>
<meta name="viewport" content="width=device-width, initial-scale=2">
</head><body>
<form action="/https/forum.arduino.cc/get">
ANNOUNCEMENT: <input type="text" name="ANNOUNCEMENT">
<input type="submit" value="Submit">
</form>
<form action="/https/forum.arduino.cc/get">
</body></html>)rawliteral";
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed!");
return;
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Send web page with input fields to client
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send_P(200, "text/html", index_html);
});
// Send a GET request to <ESP_IP>/get?input1=<inputMessage>
server.on("/get", HTTP_GET, [] (AsyncWebServerRequest * request) {
String inputMessage;
String inputParam;
// GET input1 value on <ESP_IP>/get?input1=<inputMessage>
if (request->hasParam(PARAM_INPUT)
) {
inputMessage = request->getParam(PARAM_INPUT)->value();
inputParam = PARAM_INPUT;
}
else {
inputMessage = "No message sent";
}
Serial.println(inputMessage);
request->send(200, "text/html", "HTTP GET request sent to your ESP on input field ("
+ inputParam + ") with value: " + inputMessage +
"
<a href=\"/\">Return to Home Page</a>");
});
server.onNotFound(notFound);
server.begin();
}
void loop() {
}