Go Down

Topic: problem using the string send from the web using the ip address of ESP32. (Read 92 times) previous topic - next topic

Anith17

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.

Code: [Select]
#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="/get">
    ANNOUNCEMENT: <input type="text" name="ANNOUNCEMENT">
    <input type="submit" value="Submit">
  </form><br>
  <form action="/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 +
                  "<br><a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);
  server.begin();

 
}

void loop() {

}

Anith17

Or if anyone could guide me any alternative ideas on how to receive data(string) sent from a host PC or any device that can be connected to a network and send data to the ESP32. Actually i wanted to connect it to the LAN network of my college and send data to the ESP32 and scroll that message in a 8x48 LED matrix.
I would still be grateful if someone could guide me.
Thank You!

rw950431

Welcome to the forum!

So you can see the page in your web browser and get the response printed out on the serial monitor?



I dont see any code that attempts to do anything else. What is not working?


If you are stuck on how to convert a String to a char array perhaps you might start with the getBytes() function.





 

Go Up