Compare commits
	
		
			No commits in common. "c8c59e7e6284d7c9c6cb220ea8284777b7028096" and "8fc9524884095fed3f2ef5f891bac509fe70c42a" have entirely different histories.
		
	
	
		
			c8c59e7e62
			...
			8fc9524884
		
	
		
							
								
								
									
										36
									
								
								index.html
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								index.html
									
									
									
									
									
								
							| @ -1,36 +0,0 @@ | ||||
| <!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,52 +7,9 @@ | ||||
| //   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' })) | ||||
| 
 | ||||
| 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); | ||||
| parser.on('data', console.log) | ||||
							
								
								
									
										22
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										22
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -9,8 +9,6 @@ | ||||
|       "version": "1.0.0", | ||||
|       "license": "ISC", | ||||
|       "dependencies": { | ||||
|         "http": "^0.0.1-security", | ||||
|         "serial": "^0.0.9", | ||||
|         "serialport": "^11.0.0" | ||||
|       } | ||||
|     }, | ||||
| @ -219,11 +217,6 @@ | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|     "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", | ||||
| @ -244,11 +237,6 @@ | ||||
|         "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", | ||||
| @ -389,11 +377,6 @@ | ||||
|         "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", | ||||
| @ -409,11 +392,6 @@ | ||||
|       "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,8 +9,6 @@ | ||||
|   "author": "", | ||||
|   "license": "ISC", | ||||
|   "dependencies": { | ||||
|     "http": "^0.0.1-security", | ||||
|     "serial": "^0.0.9", | ||||
|     "serialport": "^11.0.0" | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -1,15 +1,10 @@ | ||||
| #define PIN_INPUT 7 | ||||
| 
 | ||||
| void setup() { | ||||
|   // put your setup code here, to run once:
 | ||||
| Serial.begin(9600); | ||||
|   pinMode(PIN_INPUT, INPUT); | ||||
| } | ||||
| 
 | ||||
| void loop() { | ||||
|   if(digitalRead(PIN_INPUT) == HIGH) { | ||||
|     Serial.println("1"); | ||||
|   } | ||||
|   else { | ||||
|     Serial.println("0"); | ||||
|   } | ||||
|   // put your main code here, to run repeatedly:
 | ||||
| Serial.println("Все будет хорошо!"); | ||||
| delay(100); | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user