added code from tutorial
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user