Closed N9SHazpnhYW closed 3 years ago
i figured it out! posting in here for the future in case anyone else has the same question:
//send the message buffer to http
httpd_resp_set_hdr(req, "Custom-Header-1", "Message");
httpd_resp_send(req, (char*)msgbuf, msglength);
/* After sending the HTTP response the old HTTP request
* headers are lost. Check if HTTP request headers can be read now. */
if (httpd_req_get_hdr_value_len(req, "Host") == 0) {
ESP_LOGI(TAG, "Request headers lost");
}
try {
let res = await fetch("data/");
res.body.getReader().read().then(function(value) {
console.log("Display data in id txtData in html");
console.log(value.value);
document.getElementById("txtData").innerHTML = value.value; //set the element id in html to data
});
} catch (e) {
console.info("error getting message");
}
Hi. I've started to use your awesome WIFI manager in a little project im working on. I got pretty far along with it, but am a bit confused on how I can send data from the ESP32 to display on the website. For example, sending temperature sensor data to the website.
I'm able to create a new req->uri statement which links to my new call, /getdata/
I am able to successfully see the http response come through in my web browser's console...but I dont see any of the data that I sent.
Am I sending the data correctly? If so, maybe I need to extract the data from the result differently? This is how I am doing it on the javascript side:
My end goal is to be able to unpack the data in the javascript variable "res", which contains my ESP32 sensor data...and display it on the website...most likely using a
<div id="">
to set the data in javascript.Thanks in advance!!!