diff --git a/index.html b/index.html
new file mode 100644
index 0000000..b2d19ed
--- /dev/null
+++ b/index.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+ Welcome file
+
+
+
+
+ Состояние ардуины отображается в браузере:
+
ответ на “hello”
+
Пришел ответ:
+
Состояние ардуины равно
+
Пришел ответ:
+
+
+
+
diff --git a/index.js b/index.js
index c3c2af3..1d4eac0 100644
--- a/index.js
+++ b/index.js
@@ -11,8 +11,10 @@
const { SerialPort } = require('serialport')
const { ReadlineParser } = require('@serialport/parser-readline')
const http = require('node:http');
+const fs = require('fs');
const port = new SerialPort({ path: 'COM9', baudRate: 9600 })
+
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
var value_arduino = "";
@@ -25,16 +27,30 @@ parser.on('data', (data => {
}));
const server = http.createServer((req, res) => {
- res.writeHead(200, { 'Content-Type': 'application/json' });
+
+
console.log( req.url);
if (req.url == "/hello") {
res.end("/hello");
+ }else
+ {
+ if (req.url == "/") {
+
+ fs.readFile('D:/medvedevis/index.html', 'utf8', (err, data) => {
+ if (err) {
+ console.error(err);
+ return;
+ }
+ res.writeHead(200,{ 'Content-Type': 'text/html' });
+ res.end(data);
+ });
}
else {
+ res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(value_arduino);
console.log( req.url);
- }
+ }}
});