Znach_Nozhki
This commit is contained in:
parent
e38cf48126
commit
add34d944a
18
index.html
Normal file
18
index.html
Normal file
@ -0,0 +1,18 @@
|
||||
<!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="значение-ножки">Значение ножки</h1>
|
||||
<p>Парам-пам-пам</p>
|
||||
<pre><code></code></pre>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
40
index.js
40
index.js
@ -13,16 +13,25 @@
|
||||
// port.on('data', function (data) {
|
||||
// console.log('Data:', data.toString('UTF8'))
|
||||
// })
|
||||
|
||||
const { SerialPort } = require('serialport')
|
||||
const { ReadlineParser } = require('@serialport/parser-readline')
|
||||
const {
|
||||
SerialPort
|
||||
} = require('serialport')
|
||||
const {
|
||||
ReadlineParser
|
||||
} = require('@serialport/parser-readline')
|
||||
const http = require('node:http');
|
||||
|
||||
const port = new SerialPort({ path: 'COM7', baudRate: 9600 })
|
||||
const fs = require('fs');
|
||||
const port = new SerialPort({
|
||||
path: 'COM9',
|
||||
baudRate: 9600
|
||||
})
|
||||
|
||||
var value_arduino = "";
|
||||
|
||||
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
|
||||
const parser = port.pipe(new ReadlineParser({
|
||||
delimiter: '\r\n'
|
||||
}))
|
||||
parser.on('data', (data => {
|
||||
if (value_arduino != data) {
|
||||
console.log(data);
|
||||
@ -32,7 +41,26 @@ parser.on('data', (data=> {
|
||||
|
||||
// Create a local server to receive data from
|
||||
const server = http.createServer((req, res) => {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
|
||||
if (req.url == "/") {
|
||||
fs.readFile('index.html', 'utf-8', (err, data) => {
|
||||
console.log(data);
|
||||
if (err) {
|
||||
res.writeHead(404, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/html'
|
||||
});
|
||||
res.end(data);
|
||||
})
|
||||
} else if (req.url == "/pin") {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
res.end(value_arduino);
|
||||
}
|
||||
})
|
||||
server.listen(2048);
|
||||
|
Loading…
Reference in New Issue
Block a user