added code from tutorial

This commit is contained in:
sam
2023-10-10 15:31:06 +02:00
parent cf43544909
commit f75e67fe99

View File

@@ -15,22 +15,35 @@ async function connect() {
// Read data
async function readLoop() {
let buffer = [];
// loop until reader.cancel() is called
while (true) {
// Wait for data
const { value, done } = await reader.read();
for (let iByte=0; iByte < value.length; iByte++){
let singleByte = value[iByte];
if (singleByte = 10)
buffer.push(singlebyte);
else {
let sensorString =
console.log(buffer);
buffer = [];
}
// Show the received data in the console
if (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);
}
// if (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);
// }
// Exit the loop when done
if (done) {
console.log('[readLoop] DONE', done);
@@ -38,8 +51,8 @@ async function readLoop() {
break;
}
}
}
}
// Close the port
async function disconnect() {
await reader.cancel();