Compare commits
5 Commits
8fc9524884
...
c8c59e7e62
Author | SHA1 | Date | |
---|---|---|---|
c8c59e7e62 | |||
334d02ebda | |||
6718016a4d | |||
01b5f88e31 | |||
adbf8b644d |
36
index.html
Normal file
36
index.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!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="состояние-ардуины-отображается-в-браузере"><em>Состояние ардуины отображается в браузере:</em></h1>
|
||||
<h2 id="ответ-на-hello">ответ на “hello”</h2>
|
||||
<p>Пришел ответ: <span id="answer1"></span> </p>
|
||||
|
||||
<h2 id="состояние-ардуины-равно">Состояние ардуины равно</h2>
|
||||
<p>Пришел ответ:<span id="answer2"></span></p>
|
||||
</div>
|
||||
<script>
|
||||
fetch('/hello').then((response) => response.text())
|
||||
.then((response) => {
|
||||
const elem = document.getElementById("answer1");
|
||||
elem.innerHTML = response;
|
||||
});
|
||||
setInterval(() => {
|
||||
fetch('/status').then((response) => response.text())
|
||||
.then((response) => {
|
||||
const elem = document.getElementById("answer2");
|
||||
elem.innerHTML = response;
|
||||
});
|
||||
}, 1000);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
45
index.js
45
index.js
@ -7,9 +7,52 @@
|
||||
// path: '/dev/tty-usbserial1',
|
||||
// baudRate: 57600,
|
||||
// })
|
||||
|
||||
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' }))
|
||||
parser.on('data', console.log)
|
||||
|
||||
var value_arduino = "";
|
||||
|
||||
parser.on('data', (data => {
|
||||
if (value_arduino != data) {
|
||||
console.log(data);
|
||||
}
|
||||
value_arduino = data;
|
||||
}));
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
|
||||
|
||||
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);
|
||||
}}
|
||||
|
||||
|
||||
});
|
||||
|
||||
server.listen(3070);
|
22
package-lock.json
generated
22
package-lock.json
generated
@ -9,6 +9,8 @@
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"http": "^0.0.1-security",
|
||||
"serial": "^0.0.9",
|
||||
"serialport": "^11.0.0"
|
||||
}
|
||||
},
|
||||
@ -217,6 +219,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/http": {
|
||||
"version": "0.0.1-security",
|
||||
"resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz",
|
||||
"integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g=="
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
@ -237,6 +244,11 @@
|
||||
"node-gyp-build-test": "build-test.js"
|
||||
}
|
||||
},
|
||||
"node_modules/serial": {
|
||||
"version": "0.0.9",
|
||||
"resolved": "https://registry.npmjs.org/serial/-/serial-0.0.9.tgz",
|
||||
"integrity": "sha512-VdFZU3cp9NPCQrwbmqXhMZnDetsmVKK/YBF2i+sq+iU96p3+qm0GZypB91/Gmp12Pe1DjVd7ObsVj22qWNk58w=="
|
||||
},
|
||||
"node_modules/serialport": {
|
||||
"version": "11.0.0",
|
||||
"resolved": "https://registry.npmjs.org/serialport/-/serialport-11.0.0.tgz",
|
||||
@ -377,6 +389,11 @@
|
||||
"ms": "2.1.2"
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"version": "0.0.1-security",
|
||||
"resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz",
|
||||
"integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g=="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
@ -392,6 +409,11 @@
|
||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.0.tgz",
|
||||
"integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ=="
|
||||
},
|
||||
"serial": {
|
||||
"version": "0.0.9",
|
||||
"resolved": "https://registry.npmjs.org/serial/-/serial-0.0.9.tgz",
|
||||
"integrity": "sha512-VdFZU3cp9NPCQrwbmqXhMZnDetsmVKK/YBF2i+sq+iU96p3+qm0GZypB91/Gmp12Pe1DjVd7ObsVj22qWNk58w=="
|
||||
},
|
||||
"serialport": {
|
||||
"version": "11.0.0",
|
||||
"resolved": "https://registry.npmjs.org/serialport/-/serialport-11.0.0.tgz",
|
||||
|
@ -9,6 +9,8 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"http": "^0.0.1-security",
|
||||
"serial": "^0.0.9",
|
||||
"serialport": "^11.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
#define PIN_INPUT 7
|
||||
|
||||
void setup () {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(9600);
|
||||
pinMode(PIN_INPUT, INPUT);
|
||||
}
|
||||
|
||||
void loop () {
|
||||
// put your main code here, to run repeatedly:
|
||||
Serial.println("Все будет хорошо!");
|
||||
delay(100);
|
||||
if(digitalRead(PIN_INPUT) == HIGH) {
|
||||
Serial.println("1");
|
||||
}
|
||||
else {
|
||||
Serial.println("0");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user