Compare commits

..

No commits in common. "3aef5c642d707d56281095685ff96320e5cc265e" and "a37c3ba7f911cac56654cf8b32265c89a83e27fb" have entirely different histories.

2 changed files with 13 additions and 72 deletions

View File

@ -1,28 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome file</title>
<link rel="stylesheet" href="https://stackedit.io/style.css" />
</head>
<body class="stackedit">
<div class="stackedit__html"><h1 id="значение-ножки-сейчас--">Значение ножки сейчас - <span id="wertyui"></span></h1>
</div>
<script>
setInterval(()=>
fetch('/pin')
.then((response) => {
return response.json();
})
.then((data) => {
document.getElementById("wertyui").innerHTML = data;
})
, 2000);
</script>
</body>
</html>

View File

@ -8,64 +8,33 @@
// port.on('readable', function () { // port.on('readable', function () {
// console.log('Data:', port.read()) // console.log('Data:', port.read())
// }) // })
// // Switches the port into "flowing mode" // // Switches the port into "flowing mode"
// port.on('data', function (data) { // port.on('data', function (data) {
// console.log('Data:', data.toString('UTF8')) // console.log('Data:', data.toString('UTF8'))
// }) // })
const fs = require('fs');
const http = require('node:http');
const {
SerialPort
} = require('serialport')
const {
ReadlineParser
} = require('@serialport/parser-readline')
const port = new SerialPort({ const http = require('node:http');
path: '/com9', const { SerialPort } = require('serialport')
baudRate: 9600 const { ReadlineParser } = require('@serialport/parser-readline')
})
const port = new SerialPort({ path: '/com16', baudRate: 9600 })
var str = ""; var str = "";
const parser = port.pipe(new ReadlineParser({ const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
delimiter: '\r\n'
}))
parser.on('data', (data) => { parser.on('data', (data) => {
if (str != data) { if (str != data) {
console.log(data); console.log(data);
} }
str = data; str = data;
}) })
// Create a local server to receive data from // Create a local server to receive data from
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
console.log(req.url); res.writeHead(200, { 'Content-Type': 'application/json' });
if (req.url == '/') { res.end(str);
fs.readFile('index.html', (err, data) => {
if (err) {
res.writeHead(404, "Not Found");
res.write("No file found")
res.end();
} else {
res.writeHead(200, {
'Content-Type': 'text/html'
})
res.write(data)
res.end();
}
})
} else if (req.url == '/pin') {
res.writeHead(200, {
'Content-Type': 'application/json'
});
res.end(str);
} else {
res.writeHead(404, "Not Found");
res.end();
}
}); });
server.listen(2048); server.listen(2048);