почти последняя пара
This commit is contained in:
parent
80e126a9f4
commit
78ee463f91
27
index.js
27
index.js
@ -23,18 +23,26 @@ const {
|
||||
} = require('@serialport/parser-readline')
|
||||
|
||||
const port = new SerialPort({
|
||||
path: '/com9',
|
||||
path: '/com11',
|
||||
baudRate: 9600
|
||||
})
|
||||
|
||||
var str = "";
|
||||
var obj;
|
||||
|
||||
const parser = port.pipe(new ReadlineParser({
|
||||
delimiter: '\r\n'
|
||||
}))
|
||||
parser.on('data', (data) => {
|
||||
if (str != data) {
|
||||
console.log(data);
|
||||
try {
|
||||
obj = JSON.parse(data);
|
||||
|
||||
console.log(obj);
|
||||
} catch {
|
||||
console.log("Ошибка");
|
||||
}
|
||||
|
||||
}
|
||||
str = data;
|
||||
})
|
||||
@ -42,6 +50,7 @@ parser.on('data', (data) => {
|
||||
|
||||
// Create a local server to receive data from
|
||||
const server = http.createServer((req, res) => {
|
||||
|
||||
console.log(req.url);
|
||||
if (req.url == '/') {
|
||||
fs.readFile('index.html', (err, data) => {
|
||||
@ -62,6 +71,20 @@ const server = http.createServer((req, res) => {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
res.end(str);
|
||||
} else if (req.url == '/potentiometer') {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
if (obj) {
|
||||
res.end(obj.valuePotentiometer.toString());
|
||||
}
|
||||
} else if (req.url == '/gpu') {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
if (obj) {
|
||||
res.end(obj.valueGPU.toString());
|
||||
}
|
||||
} else {
|
||||
res.writeHead(404, "Not Found");
|
||||
res.end();
|
||||
|
Loading…
Reference in New Issue
Block a user