diff --git a/index.html b/index.html
new file mode 100644
index 0000000..824584c
--- /dev/null
+++ b/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ Welcome file
+
+
+
+
+ Значение ножки
+
Парам-пам-пам
+
+
+
+
+
diff --git a/index.js b/index.js
index e90583e..d92c5a0 100644
--- a/index.js
+++ b/index.js
@@ -8,31 +8,59 @@
// port.on('readable', function () {
// console.log('Data:', port.read())
// })
-
+
// // Switches the port into "flowing mode"
// 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' }))
-parser.on('data', (data=> {
- if (value_arduino != data) {
- console.log(data);
- }
- value_arduino=data;
+const parser = port.pipe(new ReadlineParser({
+ delimiter: '\r\n'
+}))
+parser.on('data', (data => {
+ if (value_arduino != data) {
+ console.log(data);
+ }
+ value_arduino = data;
}));
// Create a local server to receive data from
const server = http.createServer((req, res) => {
- res.writeHead(200, { 'Content-Type': 'application/json' });
- res.end(value_arduino);
+
+ 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);