Cov txheej txheem:
- Kauj ruam 1: Pushbutton rau Arduino
- Kauj Ruam 2: Arduino rau Raspberry
- Kauj ruam 3: Server-side Code
- Kauj ruam 4: Kho lub Vev Xaib
Video: Ntiv Lub Vev Xaib!: 4 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:28
Ntiv Lub Vev Xaib yog cuam tshuam rau cov vev xaib los ntawm qhov chaw/qhov chaw tiag.
Xav paub ntau ntxiv txog nws:
makker.hu/RingTheWeb/
Koj yuav tsum tau:
- 1 lub khawm
- 10 k resistor
- Arduino (txhua yam)
- cov kab
- lub computer me me, lub zog qis - qhov no yog RPi
- nkag mus rau server lossis khoos phis tawj nrog IP pej xeem nrog node.js
- lub vev xaib
Cov kauj ruam:
- Pushbutton rau arduino
- Arduino rau Raspberry
- Raspberry rau server
- Lub vev xaib rau server
Kauj ruam 1: Pushbutton rau Arduino
Ua ntej koj xav tau Arduino thiab lub laub khawm!
Txhua yam ntawm lawv tuaj yeem ua tau, nws nyob ntawm koj xaiv.
Txhawm rau txuas lawv, thov ua raws txoj cai khawm qhia ntawm Arduino.
Nov yog Arduino code:
// Arduino code rau nyeem tus lej digital thiab xa tus nqi mus rau qhov chaw nres nkoj
// Balázs Kovács, 2018. void setup () {Serial.begin (9600); // qhib qhov chaw nres nkoj serial pinMode (8, INPUT); // txuas khawm rau Pin 8} int counter = 0; // qee yam siv tom qab tsis muaj dab tsi voj () {yog (digitalRead (8) == 1) {// kos tus pin 8 xwm txheej Serial.write ("8"); } ncua (100); txee ++; yog (counter = 20) {// txhua 20x100 = 2000ms -> counter = 0; Serial.write ("0"); // xa ib qho "kuv twb muaj" cov lus rau server}} // Qhov ntawd yog txhua yam!
Kauj Ruam 2: Arduino rau Raspberry
Tam sim no peb tuaj yeem txuas Arduino rau lub khoos phis tawj. Hauv qhov no peb siv Raspberry, vim tias nws lub zog qis.
Txuas nws ntawm USB lossis ncaj qha nrog RX-TX pins, piav qhia ntawm no.
Tom qab ntawd teeb tsa node.js thiab npm raws li tau piav qhia ntawm no. Cov ntsiab lus tseem ceeb yog:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E tsoo -
thiab ces
sudo apt -tau nruab -y nodejs
Npm (Node.js tus thawj tswj hwm pob) xav tau socket.io-tus thov kev pabcuam thiab cov qauv txheej txheem, yog li nruab lawv:
npm nruab socket.io-client
npm nruab serialport
Qhib thiab khaws qee yam.js cov ntaub ntawv nrog cov cai hauv qab no:
// pib qhov socket.io kev txuas:
qhov socket; var io = xav tau ('socket.io-client'); qhov = io ("https://yourserver.com:port"); // yog tias kev txuas mus rau server tau ua tiav: socket.on ('txuas', ua haujlwm () {socket.send ("Kuv nyob ntawm no!"); console.log ("txuas nrog server");}; // pib qhov kev sib txuas lus chaw nres nkoj, NB /dev = ttyACM0 tuaj yeem hloov pauv: var SerialPort = xav tau ('serialport'); var serialPort = tshiab SerialPort ('/dev/ttyACM0', {baudRate: 9600}); // Yog tias qee yam los ntawm Arduino, xa cov lus sib txawv // mus rau tus neeg rau zaub mov raws li nws serialPort.on ('cov ntaub ntawv', ua haujlwm (cov ntaub ntawv) {console.log ('Cov ntaub ntawv:', data.toString ('ascii')); yog (data.indexOf ('8')! ==-1) {socket.send ('/RingTheBell 1');} yog (data.indexOf ('0')! ==-1) {socket. xa ('/client1 1');}}); // Nyeem cov ntaub ntawv uas muaj - kuv xav tias nws tsis tsim nyog serialPort.on ('nyeem tau', muaj nuj nqi () {console.log ('Cov ntaub ntawv:', port.read ());});
Tam sim no Koj yuav tsum teeb tsa lub server sab node.js code ib yam nkaus, kom txog thaum ntawd koj tuaj yeem pib thiab sim cov ntawv los ntawm
node./something.js
Yog tias muaj qee yam tsis raug, thov qhia rau kuv paub!
Kauj ruam 3: Server-side Code
Ntawm sab server, peb xav tau node.js nrog socket.io server.
Yog li ntxiv nws nrog:
npm nruab socket-io
Tom qab ntawd Koj yuav xav tau cov ntawv zoo sib xws rau cov cai ntawm qib 2, nrog qhov sib txawv, tias nws tos rau kev sib txuas, thiab yog tias lawv nyob tam sim no, nws yuav tshaj tawm cov lus xa los ntawm tus neeg siv khoom rau txhua tus neeg siv khoom, hauv qhov no rooj plaub, rau cov neeg siv lub vev xaib…
Yog li, qhib servercript.js nrog cov hauv qab no:
var http = xav tau ('http'), io = xav tau ('socket.io'); // qhib qhov tsawg kawg http server. socket.io xav tau nws. var server = http.createServer (muaj nuj nqi (req, res) {res.writeHead (200, {'Cov ntsiab lus-Hom': 'ntawv/html'}); res.end ('nyob zoo');}); // tig tcp lub qhov (socket) rau - teeb koj qhov chaw nres nkoj! server.listen (7004, ua haujlwm () {console.log ("TCP server khiav ntawm chaw nres nkoj 7004");}); // txheeb xyuas tcp lus var socket = io.listen (server); socket.on ('kev sib txuas', ua haujlwm (tus thov kev pabcuam, rinfo) {client.broadcast.emit ('system', 'qee leej txuas nrog …'); client.on ('message', function (event) {console.log (event); // tshaj tawm cov lus rau txhua tus siv txuas nrog! socket.emit ('lus', xwm txheej);}); client.on ('txhua tus', ua haujlwm (xwm txheej) {}); client.on ('disconnect', muaj nuj nqi () {socket.emit ('message', 'somebody disconneted …');});});
Sim sim los sim nrog
node./serverscript.js
Yog tias tus neeg siv khoom tau dhau mus, Koj yuav tsum pom lawv cov kev sib txuas lus ntawm ob lub consoles. Yam tsawg kawg no:
Cov ntaub ntawv: 0
-qhia cov txheej txheem ib ntus tias Arduino-> Raspberry-> server kev sib txuas lus ua haujlwm.
thiab
Cov ntaub ntawv: 8
- qhia tias khawm nyob.
Kauj ruam 4: Kho lub Vev Xaib
Tam sim no peb tau npaj nrog 75%!
Ua kom tiav txoj haujlwm nyuaj nrog suav nrog cov cai rau lub vev xaib.
Nws yooj yim.
ua ntej, suav nrog socket.io tus thov kev pab:
tom qab ntawd tsim cov lus-tshuaj ntsuam xyuas qhov system:
qhov socket;
qhov = io ("yourserver.com:port"); socket.on ('txuas', ua haujlwm () {socket.send ('tus neeg siv tsis qhia npe - tus neeg siv lub vev xaib - txuas nrog!'); socket.on ('lus', ua haujlwm (msg) {// yog tias koj xav pom txhua cov lus, tsuas yog tsis pom zoo nws: // console.log (msg); yog (msg == "/RingTheBell 1") // ntawm no los tus lej los siv rau kev hais tawm qhov kev tshwm sim khawm: {document.body.style.background = "#ccc"; setTimeout (muaj nuj nqi () {document.body.style.background = "#000";}, 1000);}; yog (msg == ""/client1 1 ") {// ntawm no koj tuaj yeem tso qee yam uas ua rau cov xwm txheej txuas nrog cov neeg siv khoom};});
Voilá!
npaj txhij
Pom zoo:
ESP32-CAM Tsim Koj Tus Kheej Lub Tsheb Nrog Lub Vev Xaib Live: 4 Kauj Ruam
ESP32-CAM Tsim Koj Tus Kheej Lub Tsheb Nrog Lub Vev Xaib Live: Lub tswv yim yog ua kom cov neeg hlau tsheb piav qhia ntawm no kom pheej yig li sai tau. Yog li ntawd kuv cia siab tias yuav ncav cuag pab pawg loj nrog kuv cov lus qhia ntxaws thiab cov khoom xaiv rau tus qauv pheej yig. Kuv xav qhia koj kuv lub tswv yim rau lub tsheb neeg hlau
$ 10 Lub Vev Xaib Lub Vev Xaib Kho: 5 Kauj Ruam (nrog Duab)
$ 10 Lub Vev Xaib Lub Vev Xaib Tsis Zoo: Zoo, kuv tau ua nws dua. Kuv tau tawg kuv qhov screen. Rau cov ntawm koj uas yuav nco tau, kuv tau ua qhov no tsuas yog ib xyoos dhau los thiab xav tau kev txhim kho ib ntus kom coj kuv mus txog thaum kuv tuaj yeem hloov pauv cov muab kev pabcuam thiab tau txais xov tooj tshiab. Nws tau ua haujlwm zoo, nws tau kav rau
Lub Vev Xaib Tswj Lub Vev Xaib Box: 4 Kauj Ruam
Lub Vev Xaib Tswj Lub Vev Xaib Box: Qhov no yog lub thawv xauv uas tuaj yeem qhib tau los ntawm kev qhia sai ntawm lub vev xaib. Qhov no txhais tau tias, koj tuaj yeem kaw cov khoom tam sim ntawd hauv lub thawv thiab tsuas yog nkag mus rau lawv thaum ib tus neeg nkag mus rau kab lus muab nkag rau ntawm lub vev xaib pej xeem. Vim li cas ib tus xav tau qhov no? Nov yog ib qho ex
Txhua Yam Txog Kev Tsim Lub Vev Xaib Lub Vev Xaib: 5 Kauj Ruam
Txhua Yam Txog Kev Tsim Lub Vev Xaib Lub Vev Xaib: Lub vev xaib pub dawb no yog daim ntawv uas koj siv los npaj phiaj xwm kev tsim kho cov ntsiab lus zoo ua kom pom tseeb cov ntsiab lus lub vev xaib. Daim qauv txheej txheem no tau tsim nrog kev yooj yim siv cov khoom siv hauv Microsoft Excel txawm hais tias muaj ntau yam software sib txawv
Lub hauv paus tseem ceeb ntawm Lub Vev Xaib-raws li Lub Vev Xaib: 7 Kauj Ruam
Cov Hauv Paus Ntawm Lub Vev Xaib-raws li Lub Vev Xaib: Cov lus qhia no yuav qhia koj cov hauv paus ntawm kev tsim lub vev xaib nrog divs li cas. Vim tias cov ntxhuav siv rau kev teeb tsa yog qhov phem!: PTo kom nkag siab cov lus qhia no, koj yuav tsum paub qhov yooj yim html thiab css. Yog tias koj tsis nkag siab qee yam, xav tias dawb rau