From 096f60baa0a7cbf811b748a312eb20e0c169d242 Mon Sep 17 00:00:00 2001 From: Serditova Sofya Date: Thu, 11 May 2023 18:55:17 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B8=20?= =?UTF-8?q?=D1=82=D0=B0=D0=BA,=20=D1=87=D1=82=D0=BE=20=D0=B5=D1=81=D0=BB?= =?UTF-8?q?=D0=B8=20=D1=8E=D1=80=D0=BB=20=D0=BD=D0=B5=20=D0=BF=D0=B8=D0=BD?= =?UTF-8?q?=20-=20=D1=82=D0=BE=20=D1=84=D0=B0=D0=B9=D0=BB,=20=D0=B5=D1=81?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=BF=D0=B8=D0=BD=20-=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B8=D0=BD=D0=B0,=20?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D1=87=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 16 ++++++++++++++++ index.js | 28 ++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..156faea --- /dev/null +++ b/index.html @@ -0,0 +1,16 @@ + + + + + + + Welcome file + + + + +

Значение ножки сейчас -

+
+ + + diff --git a/index.js b/index.js index a4e328a..2b95aaa 100644 --- a/index.js +++ b/index.js @@ -13,12 +13,12 @@ // port.on('data', function (data) { // 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({ path: '/com16', baudRate: 9600 }) +const port = new SerialPort({ path: '/com9', baudRate: 9600 }) var str = ""; @@ -33,8 +33,28 @@ 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' }); - res.end(str); + console.log(req.url); +if(req.url=='/'){ + 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); \ No newline at end of file