diff --git a/index.js b/index.js index 514b59e..c3c2af3 100644 --- a/index.js +++ b/index.js @@ -7,9 +7,36 @@ // path: '/dev/tty-usbserial1', // baudRate: 57600, // }) + const { SerialPort } = require('serialport') const { ReadlineParser } = require('@serialport/parser-readline') +const http = require('node:http'); const port = new SerialPort({ path: 'COM9', baudRate: 9600 }) const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' })) -parser.on('data', console.log) \ No newline at end of file + +var value_arduino = ""; + +parser.on('data', (data => { + if (value_arduino != data) { + console.log(data); + } + value_arduino = 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 { + res.end(value_arduino); + console.log( req.url); + } + + +}); + +server.listen(3070); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0831f89..f8211d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 641b680..6277dc6 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "author": "", "license": "ISC", "dependencies": { + "http": "^0.0.1-security", + "serial": "^0.0.9", "serialport": "^11.0.0" } } diff --git a/sketch_may10a/sketch_may10a.ino b/sketch_may10a/sketch_may10a.ino index e4575d7..bf9f951 100644 --- a/sketch_may10a/sketch_may10a.ino +++ b/sketch_may10a/sketch_may10a.ino @@ -1,10 +1,15 @@ -void setup() { - // put your setup code here, to run once: -Serial.begin(9600); +#define PIN_INPUT 7 + +void setup () { + Serial.begin(9600); + pinMode(PIN_INPUT, INPUT); } -void loop() { - // put your main code here, to run repeatedly: -Serial.println("Все будет хорошо!"); -delay(100); +void loop () { + if(digitalRead(PIN_INPUT) == HIGH) { + Serial.println("1"); + } + else { + Serial.println("0"); + } }