Cov txheej txheem:
- Kauj ruam 1: Nruab Node.js ntawm koj lub PC
- Kauj Ruam 2: Tshooj Arduino
- Kauj Ruam 3: Tau Telegram Bot Token
- Kauj Ruam 4: Tsim Node.js Project
- Kauj ruam 5: Coding
Video: Tswj Arduino Siv Telegram Bot Tsis Muaj Kev Kho Vajtse Ntxiv: 5 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:28
Muaj ntau yam uas koj tuaj yeem ua nrog Arduino, tab sis koj puas tau xav txog kev tswj hwm koj Arduino siv Telegram bot?
- Arduino UAS
- Node.js ntsia koj lub PC
- Qee lub cuab yeej tswj tau (Peb siv Arduino's on-board LED ntawm tus pin 13 ntawm no, tab sis xav tias dawb nug txog txhua yam koj xav ua hauv cov lus)
Kauj ruam 1: Nruab Node.js ntawm koj lub PC
Node.js yog JavaScript runtime, tab sis tsis txhob poob siab yog tias koj tsis muaj lub programming tom qab. Kuv tau npaj qhov koj xav tau thiab koj tuaj yeem rub tawm lawv. Hauv qhov haujlwm no, peb yuav siv Node.js rau:
- Tsim Telegram bot
- Tswj Arduino
INSTALL NODE. JS:
Mus rau nom Node.js nplooj ntawv rub tawm thiab rub tawm pob installer kawg raws li koj li OS.
*Nco ntsoov tus lej tshiab tshaj plaws raws li tau hais nyob rau sab saum toj ntawm nplooj ntawv rub tawm, peb yuav siv nws hauv qib tom ntej.
Tom qab rub tawm pob thiab teeb tsa nws, koj yuav tsum txheeb xyuas seb Node.js tau teeb tsa tag lossis tsis yog.
NCO NTSOOV YUAV TSUM YOG PACKAGE INSTALLED KAWG:
Yog tias koj nyob ntawm windows, qhib CMD thiab yog tias koj nyob ntawm macOS qhib lub davhlau ya nyob twg thiab ntaus:
node -v
Tam sim no koj yuav tsum pom cov ntawv uas koj tau mus ntsib ntawm Node.js nplooj ntawv rub tawm, luam tawm ntawm no.
Txwv tsis pub kuv muab qee cov lus qhia hauv qab no los sim dua:
- Qhov rai
- macOS os
Kauj Ruam 2: Tshooj Arduino
Hauv cov kauj ruam no tsuas yog qhov koj yuav tsum tau ua yog rub tawm ib qho tsim hauv Arduino IDE firmware ntawm koj Arduino Uno.
Tseem ceeb: Koj yuav tsum hloov kho koj li Arduino IDE mus rau qhov hloov tshiab tshaj plaws los ntawm Arduino.
Ntshuam firmata tsev qiv ntawv:
Cov ntawv qhia saum toj kawg nkaus >> Cov ntaub ntawv >> Piv txwv >> Firmata >> StandardFirmata
Txheeb xyuas thiab xa cov cai ntawm Arduino:
1. Cov ntawv qhia zaub mov saum toj kawg nkaus >> Kos duab >> Txheeb Xyuas/Sau
2. Ntawv qhia zaub mov saum toj kawg nkaus >> Sketch >> Upload
Txhua yam ua tiav.
Kauj Ruam 3: Tau Telegram Bot Token
Qhib Telegram thiab tshawb rau @BotFather lossis nyem qhov no los qhib lub bot ntawm xov tooj no.
- Ntaus /newbot thiab ntaus nkag
- Xaiv lub npe rau koj tus bot
- Xaiv lub npe siv rau koj tus bot. Nws yuav tsum xaus rau hauv 'bot'
- Tam sim no bot xa koj qee cov ntaub ntawv suav nrog koj li API nkag mus token. Sau nws, peb, yuav siv tus cim no hauv cov kauj ruam tom ntej
Kauj Ruam 4: Tsim Node.js Project
CREATE A NEW NODE. JS PROJECT
Rau tsim Node.js txoj haujlwm thiab teeb tsa cov qauv peb yuav tsum siv davhlau ya nyob twg, yog li yog koj nyob ntawm Windows, siv CMD thiab thaum siv macOS siv Terminal rau txhua qib hauv qab no.
1. Tsim daim nplaub tshev qhov chaw rau txoj haujlwm
2. CD (Hloov Cov Ntawv Teev Npe) rau cov ntawv uas nyuam qhuav tsim. Piv txwv li yog tias koj lub npe ntawv ntawd 'TelegramBot' thiab muab tso rau ntawm lub desktop, sau qhov no hauv lub davhlau ya nyob twg thiab ntaus nkag mus:
cd Desktop/TelegramBot
3. Rau tsim Node.js project sau cov lus txib hauv qab no:
npm pib
4. Teb qee cov lus nug suav nrog lub npe, lus piav qhia, daim ntawv tso cai thiab lwm yam yog tias koj tsis paub yuav teb dab tsi, tsuas yog ntaus nkag. Hauv qhov no lo lus nruab nrab ntawm kab lus yuav raug siv raws li tus nqi qub.
5. Tam sim no koj yuav tsum pom 'pob.json' cov ntaub ntawv tsim hauv koj daim nplaub tshev thiab qhov no txhais tau tias koj tau tsim Node.js txoj haujlwm tiav.
Kauj ruam 5: Coding
Peb xav tau sau qee cov lej ntawm no. Cia peb piav qhia qee lub tsev qiv ntawv siv:
- Node Telegram Bot API los lis telegram bot API thov.
- Johnny-Tsib Platform txhawm rau txuas rau Arduino.
Txhua yam koj xav paub txog cov tsev qiv ntawv no tuaj yeem pom hauv lawv cov vev xaib txuas. peb tsuas yog siv lawv hauv peb cov cai tab sis tag nrho cov ntaub ntawv ntawm lawv yog ntawm lawv cov blog.
Kuv siv Microsoft Visual Studio Code rau kev kho qhov chaws. tab sis koj tuaj yeem siv lwm yam uas koj nyiam. 1. Qhib cov cai kho software thiab tsim cov ntaub ntawv hu ua 'index.js' (lossis txhua yam koj tau nkag mus rau ntu nkag ntawm Node.js txoj haujlwm tsim theem) hauv cov npe ntsig txog.
2. Sau cov cai:
var tsib = xav tau ("johnny-five"); cia TelegramBot = xav tau ('node-telegram-bot-api'); const token = '############################################'; const bot = TelegramBot tshiab (token, {pov npav: tseeb}); var board = tshiab tsib. Board (); const answerCallbacks = {};
bot.on ("message", muaj nuj nqi (msg) {
hu rov qab = answerCallbacks [msg.chat.id]; yog (hu rov qab) {rho tawm callCallbacks [msg.chat.id]; rov hu rov qab (msg); }});
board.on ("npaj tau", muaj nuj nqi () {
var coj = tshiab tsib. Led (13);
bot.on ('lus', (msg) => {
const chatId = msg.chat.id; cov ntawv = lus.text; yog (ntawv == '/pib') {pib (chatId, coj); }}); });
muaj nuj nqi pib (chatId, coj) {
bot.sendMessage (chatId, "Arduino Control Panel", getKeyboardOptions ());
bot.on ("callback_query", (callbackQuery) => {
const lus = callbackQuery.message; bot.answerCallbackQuery (callbackQuery.id).then (() => {const data = callbackQuery.data; if (data == 'turnon') {led.on ();} else if (data == 'turnoff') {coj.off ();}})}); }
muaj nuj nqi getKeyboardOptions () {
const options = {"reply_markup": {resize_keyboard: true, "inline_keyboard":
rov qab xaiv;
}
3. Hloov cov khoom ntiag tug tus nqi nrog ib qho uas koj tau sau rau hauv bot tsim theem
4. Txuag cov cai
5. Qhib davhlau ya nyob twg thiab sau cov lus txib hauv qab no:
npm kuv-txuag johnny-tsib node-telegram-bot-api
6. Tom qab txhim kho cov qauv, thaum koj Arduino txuas nrog USB chaw nres nkoj, hauv lub davhlau ya nyob twg nkag mus rau cov lus txib hauv qab no:
node index.js
7. Koj yuav tsum pom qee yam xws li:
1534514872949 Muaj /dev/cu.usbmodem1411
1534514872957 Txuas nrog /dev/cu.usbmodem1411 1534514876660 Repl Initialized >>
8. Qhib xov tooj thiab tshawb rau koj tus bot lub npe siv (lossis qhib nws los ntawm BotFather) thiab sau cov lus txib no:
/pib
9. Koj yuav tsum pom lub tswj vaj huam sib luag uas tuaj yeem tswj hwm Arduino LED nrog 'Qhib' thiab 'Tua tawm' cov lus txib, yog tias koj muaj hmoo txaus;)
Pom zoo:
Arduino Neeg Hlau Nrog Kev Nyob, Kev Qhia thiab Qib Kev Sib Hloov (Sab Hnub Poob, Sab Hnub Poob, Sab Qaum Teb, Sab Qab Teb) Tswj los ntawm Lub Suab Siv Bluetooth Module thiab Kev Siv Tus Neeg Siv Hluav Taws Xob: 6 Kauj Ruam
Arduino Neeg Hlau Nrog Kev Nyob, Kev Qhia thiab Qib Kev Sib Hloov (Sab Hnub Poob, Sab Hnub Poob, Sab Qaum Teb, Sab Qab Teb) Tswj los ntawm Lub Suab Siv Bluetooth Module thiab Kev Siv Tus Neeg Siv Hluav Taws Xob: Cov lus qhia no piav qhia yuav ua li cas thiaj tsim tau Arduino Robot uas tuaj yeem txav mus raws qhov xav tau (Forward, Backward) , Sab laug, Txoj Cai, Sab Hnub Poob, Sab Hnub Poob, Sab Qaum Teb, Sab Qab Teb) xav tau Kev nrug deb hauv Centimeters siv lub suab hais kom ua. Neeg hlau kuj tseem tuaj yeem txav tau tus kheej
Retrofit BLE Kev Tswj kom Muaj Lub Hwj Huam Muaj Zog - Tsis Xav Tau Kev Txuas Ntxiv: 10 Kauj Ruam (nrog Duab)
Retrofit BLE Kev Tswj kom Muaj Lub Hwj Huam Muaj Zog - Tsis Xav Tau Cov Hluav Taws Xob Ntxiv: Hloov tshiab: Lub Xya Hli Tim 13, 2018 - ntxiv 3 -lub davhlau ya nyob twg tswj rau cov khoom siv hluav taws xob Cov lus qhia no suav nrog BLE (Bluetooth Tsawg Zog) tswj ntawm kev thauj khoom tam sim no hauv thaj tsam 10W rau > 1000W. Lub zog tau hloov pauv nyob deb ntawm koj li Android Txawb ntawm pfodApp. Tsis muaj
Ua Alexa Kev Txawj Ntse nrog Cloud9- Tsis muaj daim npav rho nyiaj lossis yuav tsum tau kho vajtse: 7 Kauj Ruam (nrog Duab)
Ua Alexa Kev Txawj Ntse nrog Cloud9- Tsis Muaj Credit Card lossis Kho Khoom Siv Yuav Tsum Tau: Nyob zoo, hnub no kuv yuav los qhia koj yuav tsim koj tus kheej li cas Amazon Alexa txuj ci siv Cloud9. Rau cov uas koj tsis paub, Cloud9 yog online IDE txhawb nqa ntau yam lus sib txawv thiab nws yog ib puas feem pua dawb - tsis muaj daim npav rho nyiaj xav tau
Headless Pi - Ua Kom Koj Raspberry Pi Pib Tsis Muaj Lwm Yam Kho Vajtse Ntxiv: 4 Kauj Ruam (nrog Duab)
Headless Pi - Ua Kom Koj Raspberry Pi Pib Tsis Muaj Lwm Yam Khoom Kho Vajtse Ntxiv: Hav muaj, Vim li cas koj thiaj tsaws ntawm no yog, Kuv twv, tias koj zoo li kuv! Koj tsis xav mus yooj yim ntawm koj Pi - ntsaws Pi rau hauv lub monitor, nqes tus keyboard thiab nas, thiab voila! &Hellip; Pfft, leej twg ua li ntawd?! Tom qab tag nrho, Pi yog &
Kev Siv Hluav Taws Xob Hluav Taws Xob Tsis Muaj Ntxiv Ib Qho Ntxiv: 4 Kauj Ruam
Kev Siv Hluav Taws Xob Hluav Taws Xob Tsis Muaj Ntxiv Ib Qho Ntxiv: Kuv tau ua qhov hluav taws kub nrawm rau kuv tus Logitech MX500 nas. Muaj ntau txoj hauv kev nyob ib puag ncig, kuv siv qhov no: www.instructables.com/id/Add_a_rapid_fire_button_to_your_mouse_using_a_555_/ Qhov txawv ntawm kuv txoj hauv kev yog: Kuv tau ua nws yam tsis muaj qhov ntxiv