added so incoming data gets split into a array

This commit is contained in:
sam
2023-10-06 11:20:45 +02:00
parent ceb99d9a4d
commit 31d6317320

View File

@@ -1,11 +1,12 @@
// Define port and reader globally to be used in other functions
let port;
let reader
let reader;
let decoder = new TextDecoder("utf-8");
let counterElement = document.getElementById("counter");
let readibleoutput = 0;
// Request a port and open a connection.
async function connect() {
//vraag aan de browser om een serial port te selecteren
port = await navigator.serial.requestPort();
await port.open({ baudRate: 9600 });
reader = port.readable.getReader();
@@ -20,7 +21,15 @@ async function readLoop() {
const { value, done } = await reader.read();
// Show the received data in the console
if (value) {
console.log(decoder.decode(value));
readibleoutput = (decoder.decode(value));
var array = readibleoutput.split(','),
temp = array[0], humid = array[1], licht = array[2];
console.log(temp);
console.log(humid);
console.log(licht);
setTimeout(() => {
}, 400);
}
// Exit the loop when done
if (done) {