I got two bme680 environmental sensors and an ESP32 board and i have to make a web interface where i can see the recorded values. I'm using the ESP32 board as a webserver. I'm also trying to create a chart for data displaying. My problem is that i don't know how to push the data from the html page to a csv file so i can use the data stored into the csv file in ploting process.
Asked
Active
Viewed 359 times
0
-
First you need a csv writing logic server-sided and then you can send the data to the server via requests. – flx Aug 26 '21 at 07:18
-
I think you'll want the ESP32 to send the data independently of the "web page" it is serving, since the way you seem to want to do it, data would only be sent "somewhere" if you're viewing the web page - rethink the process – Bravo Aug 26 '21 at 07:19
1 Answers
-1
you can do it with javascript , also it is possible to read HTML table or whatever with javascript and convert it to an array, and let browser to process CSV file.
pure javascript short example: (because limitation of memory in boards)
notice: this code will not work here right now because of browser limits try it on your browser separately
<html>
<head>
<script>
const rows = [
["name1", "city1", "some other info"],
["name2", "city2", "more info"]
];
let csvContent = "data:text/csv;charset=utf-8,";
rows.forEach(function(rowArray) {
let row = rowArray.join(",");
csvContent += row + "\r\n";
});
var encodedUri = encodeURI(csvContent);
window.open(encodedUri);
</script>
</head>
</html>
if you don't like to reinvent the wheel and memorry space is doesn't matter to you is possible to use javascript library like Papaparse:
// Parse CSV string
var data = Papa.parse(csv);
// Convert back to CSV
var csv = Papa.unparse(data);
// Parse local CSV file
Papa.parse(file, {
complete: function(results) {
console.log("Finished:", results.data);
}
});
// Stream big file in worker thread
Papa.parse(bigFile, {
worker: true,
step: function(results) {
console.log("Row:", results.data);
}
});

Cyrus Raoufi
- 526
- 1
- 3
- 27
-
1That’s an incomplete implementation of a CSV generator that will fail if any of the data includes quotes or new lines. There are plenty of CSV generating libraries, don’t reinvent that wheel. – Quentin Aug 26 '21 at 07:41
-
yes of course you right! but i just give the idea! all developer should know there is many library for anythings!, i will edit my post and add some great library – Cyrus Raoufi Aug 26 '21 at 08:10
-
one more things! the microcontroller device memorry is limit! it's important in this cases – Cyrus Raoufi Aug 26 '21 at 08:14