Send array data from Esp32 to web page

Hi everybody

I have a scenario where I log data from an accelerometer to storage space on an Esp32 WeMos Lolin32. I log the data for about 5 seconds after the Esp32 powered up and I log the data in an array format on the Esp32 itself. I know it is not common practice to store data on your microprocessor, but I record data from the accelerometer at an extremely fast rate (much faster than will be possible to store it on an SD card or a any other external storage device). Anyway, I made sure that the Esp32 WeMos Lolin32 had enough internal storage space for the amount and size of data I am recording.

Now, after all the data has been logged I want to send the from my Arduino board to a web page by setting the Arduino board as soft-AP server. I found countless methods which send data live from a sensor to a web page, but in my case all the data has already been logged. I thus just need to send the logged data line for line to a web page so that I can get the data on my computer for further analysis.

Below is a code that I found use full for my scenario, but it only send a fixed text once to a web-page. I need to change the code so that I can send the data in the array, line for line via a loop to a web-page. Since I already logged all the data on my Arduino board the speed at which the data is send to my computer does not matter.

Please make suggestion and if not to much trouble please advice me on how exactly to change the code below to for fill my requirements. I am a bit of a beginner with Arduino micro-processing. But I guess it should quite easy.

#include <WiFi.h>
#include <WebServer.h>

// SSID & Password
const char* ssid = "SSID";  // Enter your SSID here
const char* password = "123456789";  //Enter your Password here

// IP Address details
IPAddress local_ip(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

WebServer server(80);  // Object of WebServer(HTTP port, 80 is defult)


void setup() {
  Serial.begin(115200);

  // Create SoftAP
  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);


  Serial.print("Connect to My access point: ");
  Serial.println(ssid);

  server.on("/", handle_root);

  server.begin();
  Serial.println("HTTP server started");
  delay(100);
}

void loop() {
  server.handleClient();
}

// HTML & CSS contents which display on web server
String HTML = "<!DOCTYPE html>\
<html>\
<body>\
<h1>My First Web Server with ESP32 - AP Mode &#128522;</h1>\
</body>\
</html>";

// Handle root url (/)
void handle_root() {
  server.send(200, "text/html", HTML);
}

Now, after all the data has been logged I want to send the from my Arduino board to a web page by setting the Arduino board as soft-AP server.

Excuse me that doesn't make sense. If the ESP is the access point, how should it be able to connect to an Internet server?

The code you posted doesn't send data to a web server but it provides a web server on the ESP32 so a local client can request the data. But it provides a HTML page and not measured data.

Please specify in more detail what you're trying to achieve and not how you think it should be achieved.

No the Esp32 is not suppose to connect to an internet server. It is suppose to log the data on a web page when a client request it. The example I provide is just a simple code that post text on a web page from the Esp32 when the client request it. But I thought it is a could starting point for what I am tying to achieve.

In simple word, measured data is already stored on the Esp32. When a client request the data the Esp32 should log the data line for line on the web page created by the Arduino. Hence a whole web page showing all the data that is stored on the Esp32 should be the end result.

So just adapt the handle_root() routine (pseudo code as you’re still hiding your code):

void handle_root() {
  server.setContentLength(CONTENT_LENGTH_UNKNOWN);
  server.send(200, "text/plain", "");
  int i;
  for (i = 0; i < array_length; i++) {
    server.sendContent(String(myarray[i]) + "\r\n");
  }
}

Hello,
I did create a server on my esp32 recently and i basically follow the example on this page (https://lastminuteengineers.com/creating-esp32-web-server-arduino-ide/) to understand how the concept works, i test the code with no change at all.
And then after i understood it, i change it to fulfill my needs, maybe it can help you too.

LivingOnTheEdge:
No the Esp32 is not suppose to connect to an internet server. It is suppose to log the data on a web page when a client request it. The example I provide is just a simple code that post text on a web page from the Esp32 when the client request it. But I thought it is a could starting point for what I am tying to achieve.

In simple word, measured data is already stored on the Esp32. When a client request the data the Esp32 should log the data line for line on the web page created by the Arduino. Hence a whole web page showing all the data that is stored on the Esp32 should be the end result.

Just an idea.

If the web site has a data base the ESP32 can send the data to a local PC or RPi running MQTT Broker. On the MQTT broker a running program can get the data from the MQTT Broker and forward it to your web site database.

Another way is to have the ESP32 send the data via a call to a web page, pass the data as input parameters to be stored in the websites database.