Cov txheej txheem:

Tsev Kawm Ntawv Tswb rau Cov Tub Ntxhais Kawm Nyob Ze: 6 Kauj Ruam
Tsev Kawm Ntawv Tswb rau Cov Tub Ntxhais Kawm Nyob Ze: 6 Kauj Ruam

Video: Tsev Kawm Ntawv Tswb rau Cov Tub Ntxhais Kawm Nyob Ze: 6 Kauj Ruam

Video: Tsev Kawm Ntawv Tswb rau Cov Tub Ntxhais Kawm Nyob Ze: 6 Kauj Ruam
Video: Quas Koj Ntxhais Rau Kuv Tub - Cai Hawj Feat. Maiv Xis Vaj「Official MV」 2024, Kaum ib hlis
Anonim
Tsev Kawm Ntawv Tswb rau Cov Tub Ntxhais Kawm Nyob Hauv
Tsev Kawm Ntawv Tswb rau Cov Tub Ntxhais Kawm Nyob Hauv

Nrog rau COVID-19 muaj thoob qhov txhia chaw, ntau tus menyuam lub tsev kawm ntawv tau mus deb. Lub tswb tsev kawm ntawv hauv tsev no yog txoj hauv kev lom zem kom nyob raws sijhawm uas siv Raspberry Pi thiab tus hais lus USB. Koj tuaj yeem ua nrog koj tus menyuam thiab lawv tuaj yeem kawm paub txog kev ua haujlwm thiab tuaj yeem "tswb lub tswb". Kuv ua qhov no rau kuv tus ntxhais uas tab tom kawm qib 7 (tam sim no ntawm kev xa khoom deb), thiab nws ua haujlwm tau zoo kom peb nyob raws sijhawm.

Khoom siv

Rau qhov haujlwm no, koj yuav xav tau:

  • Raspberry Pi lub computer - Nws ua haujlwm zoo tshaj yog tias koj muaj WiFi, Kuv siv RPi 3B los ntawm Kano cov khoom siv
  • Tus Hais Lus - Kuv siv tus hais lus USB

Txoj cai tuaj yeem siv tau yooj yim ntawm koj tus menyuam lub computer linux lossis txawm tias lub microcontroller khiav micropython, tsuav yog lub microcontroller muaj qee qhov txheej txheem kom tau txais hnub/sijhawm tam sim no. Kuj tseem muaj cov hais lus nthuav dav, lossis txawm tias txias dua lub suab sib txuas / sib piv, tuaj yeem siv tau.

Kauj Ruam 1: Teeb Koj Raspberry Pi

Teeb Koj Raspberry Pi
Teeb Koj Raspberry Pi

Muaj ntau qhov peev txheej los teeb tsa Raspberry Pi lub computer, yog li kuv xa koj mus rau ib qho uas Google pom. Qhov tseem ceeb yog koj lub khoos phis tawj muaj txoj hauv kev kom tau txais hnub thiab sijhawm raug. Feem ntau WiFi-siv Raspberry Pi cov khoos phis tawj niaj hnub siv NTP cov txheej txheem los teeb lub sijhawm los ntawm is taws nem, uas yog txoj hauv kev uas kuv tau txais lub sijhawm raug. Kuv teeb kuv RPi kom "tsis muaj taub hau", txhais tau tias nws tsis muaj keyboard lossis saib, tab sis tuaj yeem nkag tau los ntawm lub plhaub ruaj ntseg (SSH) hauv is taws nem. Yog tias koj ua tau zoo nrog RPi, koj tuaj yeem ua qhov teeb tsa no yam tsis muaj keyboard / yees duab / nas, tab sis nws yooj yim dua tsuas yog teeb tsa pi nrog cov khoom siv ntawd.

Nco ntsoov tias kuv tsis tas yuav siv lub graphical interface, yog li kuv tsuas yog rub tawm "Raspberry Pi OS (32-ntsis) Lite", uas yog me dua thiab nrawm dua rau rub tawm thiab khau raj sai dua.

Kho dua Raspberry Pi lub network thiab cuam tshuam kev xaiv

$ sudo raspi-teeb tsa

Hauv kev teeb tsa, ua cov hauv qab no:

  • Hloov tus password - ua qhov no ua ntej, vam tias ua ntej mus online!
  • Hauv "Network Options",

    • Hloov lub hostname. Kuv siv lub hostname: "schoolbell".
    • Txuas rau koj Wireless LAN (yog tias koj tsis tau ua qhov teeb tsa)
  • Hauv qab "Kev Xaiv Ua Ntej", qhib rau SSH nkag
  • Nws ib txwm zoo los khiav qhov "Hloov Kho" kev xaiv

Thaum koj tau ua qhov no thiab rov pib dua, koj yuav tsum muaj peev xwm txuas rau Raspberry Pi los ntawm lwm lub khoos phis tawj ntawm tib lub network hauv ib cheeb tsam los ntawm kev siv SSH tus thov kev pab. Txuas nrog nws los ntawm kev siv cov ntawv pov thawj hauv qab no:

hostname: schoolbell.local

neeg siv: pi lo lus zais: whateveryousetitas

Los ntawm lub thawv linux, qhov no yooj yim li ntaus kab lus hais kom ua ntawm $ sai:

$ ssh [email protected]

… Sau tus password thaum hais tam sim

Qhov ntawd yuav nkag mus rau koj thiab koj tuaj yeem tshawb xyuas tias lub sijhawm ntawm Raspberry Pi yog qhov raug. Ntawm kab hais kom ua, ntaus hnub hais kom ua thiab tshawb xyuas cov lus teb:

pi@schoolbell: ~ $ hnub tim

Thu 3 Sep 20:44:34 AKDT 2020

Vam tias qhov no yog lub sijhawm tam sim no. Yog tias nws tsis raug, google txog teeb tsa NTP ntawm Raspberry Pi.

Kauj Ruam 2: Tau Txais Koj Lub Suab Ua Haujlwm

Ua Kom Koj Lub Suab Ua Haujlwm
Ua Kom Koj Lub Suab Ua Haujlwm

Peb tab tom yuav ua MP3 cov ntaub ntawv rau lub tswb, yog li peb yuav tsum rub tawm software los txiav txim cov ntaub ntawv audio no. Kuv tau txais pob mpg321 los ntawm kev ntaus cov lus txib no:

pi@schoolbell: ~ $ sudo apt-tau nruab mpg321

Ua raws li cov lus qhia rau nruab qhov software no.

Kuv siv tus neeg hais lus USB qub, uas muaj tus tsav tsheb coj txawv txawv thiab tsis tau pib kho qhov qub raws li daim npav lub suab qub, yog li kuv pom tias kuv tuaj yeem "hack" tus hais lus los ua haujlwm los ntawm kev siv nws qhov chaw nyob kho vajtse. Tom qab ntsaws tus hais lus, Kuv siv qhov hais kom ua 'aplay -l' los teev cov khoom siv suab:

pi@schoolbell: ~ $ aplay -l

**** List of PLAYBACK Hardware Devices **** card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones] Subevices: subdevice #0: subdevice #0 subdevice #1: subdevice #1 subdevice #2: subdevice #2 subdevice #3: subdevice #3 subdevice #4: subdevice #4 subdevice #5: subdevice #5 subdevice #5: subdevice #6 subdevice #7: subdevice #7 card 1: CODEC [USB Audio CODEC], ntaus ntawv 0: USB Audio [USB Audio] Cov pab pawg me me: sub faib #0: subdevice #0

Cov cuab yeej kuv xav tau yog qis dua, daim npav 1, ntaus ntawv 0.

Kuv sim tus neeg hais lus nrog "hais lus-ntsuas", siv lub cuab yeej "hw: 1, 0", lub ntsiab lus kho vajtse daim npav 1, ntaus ntawv 0

pi@schoolbell: ~ $ tus neeg hais lus -xeem -D hw: 1,0

Qhov program no tso suab nrov los ntawm tus hais lus. Txaus siab rau lub suab nrov ces ntaus tswj -C thaum koj npau taws. Yog tias koj tsis hnov suab nrov, sim google.

Tam sim no koj muaj suab!

Kauj Ruam 3: Kuaj Kev Ua Si ntawm Tswb Suab thiab/lossis Ua Lub Suab Tshiab

Kuaj Kev Ua Si ntawm Tswb Suab Thiab/lossis Ua Lub Suab Tshiab
Kuaj Kev Ua Si ntawm Tswb Suab Thiab/lossis Ua Lub Suab Tshiab

Txog kuv lub tswb, Kuv rub lub suab "bing-bong" los ntawm "freesound.org". Ua tsaug rau Benboncan rau ua lub suab no muaj:

freesound.org/people/Benboncan/sounds/93646/

Koj tuaj yeem ua suab ncaj qha. Kuv tuaj yeem rub ncaj qha rub tawm qhov mp3 version ntawm cov ntawv no los ntawm kev ntaus cov lus txib no ntawm Raspberry Pi lub computer (piv txwv tias nws nyob ntawm WiFi):

pi@schoolbell: ~ $ wget

Kuv mam li hloov npe cov ntawv no:

pi@schoolbell: ~ $ mv 93646_634166-hq.mp3 bing-bong-chime-hq.mp3

Kuv tom qab ntawv sim tias kuv tuaj yeem hu lub tswb nrog cov lus txib no (qhia tawm):

pi@schoolbell: ~ $ mpg321 -a hw: 1, 0 bing-bong-chime-hq.mp3

Kev Ua Tau Zoo MPEG 1.0/2.0/2.5 Audio Player rau Txheej 1, 2, thiab 3. Version 0.3.2-1 (2012/03/25). Sau thiab luam cov cai los ntawm Joe Drew, tam sim no tswj los ntawm Nanakos Chrysostomos thiab lwm tus. Siv cov cai los ntawm ntau tus neeg. Saib 'README' kom paub ntau ntxiv! Qhov software no los nrog qhov tsis muaj kev lees paub kiag li! Siv ntawm koj tus kheej RISK! Ua si MPEG kwj los ntawm bing-bong-chime-hq.mp3… MPEG 1.0 txheej III, 128 kbit/s, 44100 Hz mono [0:02] Txiav txim siab ntawm bing-bong-chime-hq.mp3 tiav.

Nrog koj zoo siab! Koj muaj suab.

Siv lub suab kho qhov chaws "ua siab loj" ntawm kuv lub laptop, kuv faib cov ntawv ua "bing" thiab "bong" kom lom zem dua. Koj tuaj yeem siv ib qho mp3 lossis tej zaum lwm hom ntawv (Kuv tsis tau sim lwm tus) cov ntaub ntawv suab.

Kauj Ruam 4: Txhim Kho Txoj Cai thiab Teeb Koj Lub Sijhawm

Nruab qhov Code thiab Teeb Koj Lub Sijhawm
Nruab qhov Code thiab Teeb Koj Lub Sijhawm

Cov cai yog tsab ntawv nab nab uas tau txais hnub/sijhawm tam sim no thiab yog hnub tim yog hnub ua haujlwm thiab tsis yog hnub so, nws kuaj xyuas seb lub sijhawm puas zoo li lub tswb nrov, chiming yog tias nws yuav tsum.

Ua ntej koj yuav ua kom nws ua haujlwm, tom qab ntawd koj yuav siv nws kom ua haujlwm txhua feeb.

Rub tawm cov cai los ntawm Github:

gist.github.com/BillSimpson/d7a1a531995c8b63492bb47ef8872618

Kuv pom nws yooj yim los ua qhov no los ntawm kev khaws cov ntaub ntawv ntawm lub khoos phis tawj hauv zos tom qab ntawd siv daim ntawv ruaj ntseg (scp) tso rau hauv Raspberry pi.

Ntawm koj lub tshuab hauv ib cheeb tsam, theej cov lej los ntawm koj tus browser, tom qab ntawd muab tshuaj txhuam rau hauv cov ntawv thiab khaws nws nrog lub npe "schoolbell.py". Tom qab ntawd scp cov ntaub ntawv hla:

tshuab hauv zos: ~ $ scp schoolbell.py [email protected]: ~/

Koj yuav tau txais kev ceeb toom kom nkag mus rau tus lej nkag mus rau tus neeg siv pi ntawm schoolbell.local - nkag tus password, thiab cov ntaub ntawv tau theej zoo. Cov lus txib no yuav tsum tau khiav hauv tib phau ntawv uas cov ntawv nab nab tau raug cawm, thiab luam nws mus rau phau ntawv qhia tsev ntawm tus neeg siv pi. Koj tuaj yeem ssh hla mus rau schoolbell.local thiab cov cai yuav tsum nyob ntawd:

tshuab hauv zos: ~ $ ssh [email protected]

Tom qab ntawv ntawm schoolbell.local, sau cov ntaub ntawv (koj tuaj yeem pom ntau cov ntaub ntawv):

pi@schoolbell: ~ $ ls

bing-bong-chime-hq.mp3 schoolbell.py

Tam sim no kho qhov chaws kom nws muaj koj lub tswb lub sijhawm los ntawm kev siv tus kho xws li pico:

pi@schoolbell: ~ $ pico schoolbell.py

Txoj cai muaj peb "phau ntawv txhais lus" uas txhais lub suab nrov nrov ua si, lub sijhawm los ua si rau lawv, thiab cov hnub so kom zam, Tswb nyob rau hnub so yuav tau hla mus.

Piv txwv li, phau ntawv txhais lus tswb nrov yog:

Lub suab nrov = {

'ceeb toom': 'bing-bong-chime-hq.mp3', 'pib': 'bing-bong-chime-hq.mp3', 'kawg': 'bing-bong-chime-hq.mp3'}

Qhov no txhais peb hom tswb, ceeb toom tswb, pib chav kawm, thiab xaus. Vim tias peb tsuas muaj ib lub suab nrov nrov, lawv txhua tus taw tes rau tib cov ntawv, tab sis yog tias koj ua lub suab sib txawv, koj tuaj yeem hloov lawv. Koj tseem tuaj yeem ntxiv lwm hom tswb nrov. Kuv kuj tau ua si nrog siv lub suab sib tham los hais lub tswb nrov, tab sis qhov ntawd tsis tau pom los ntawm lwm tus hauv tsev.

Lub tswb phau ntawv txhais lus zoo ib yam, tab sis "tus yuam sij" tam sim no yog lub sijhawm rau tswb. koj yuav tsum tau siv hom ntawv HH: MM nrog tus lej zeros thiab 24-teev sijhawm (sijhawm ua tub rog).

tswb tswb = {

'09: 00 ':' pib ', #' Tsheb npav 'tswb kom npaj txhij '09: 28': 'ceeb toom', ….. '13: 58 ':' ceeb toom ', # rau lub sijhawm 4 '14: 00 ':' pib ',' 15:00 ':' kawg '}

Tus nqi hauv tus yuam sij no: tus lej tus nqi yog hom ntawm lub tswb nrov los siv thiab xav tau kom phim ib qho ntawm lub tswb nrov txhais los saum no.

Thaum kawg, phau ntawv txhais lus hnub so teev cov hnub so. Cov hom ntawv yog YYYY-mm-dd, nrog rau ua zeros raws li qhia.

hnub so = {

'2020-09-07', …. '2021-03-11', '2021-03-12' }

Thaum koj ua tiav kev kho, khaws cov ntaub ntawv los ntawm kev tawm koj tus editor, ntaus ctrl-X yog tias koj siv pico.

Ua tus nab npawb nab npawb ua los ntawm:

pi@schoolbell: ~ $ chmod a+x schoolbell.py

Qhov no cia txhua tus neeg siv ua txoj cai, "a" rau txhua tus, "+" rau kev tso cai ntxiv, thiab "x" rau kev ua.

Tam sim no sim khiav cov cai thiab soj ntsuam cov zis. Nco tseg tias koj tuaj yeem khiav cov ntawv los ntawm kev ntaus lub npe tab sis yuav tsum qhia meej tias nws nyob hauv phau ntawv teev npe tam sim no los ntawm kev ntaus tus "./" ua ntej lub npe:

pi@schoolbell: ~ $./schoolbell.py

Nws yog sijhawm kawm ntawv, kuaj lub sijhawm 21:35

Txoj cai yuav qhia koj yog tias nws yog hnub so (piv txwv li tsis yog hnub so lossis hnub so) thiab pom yog tias lub sijhawm zoo li lub tswb nrov. Hauv qhov no, nws tsis yog lub tswb nrov, yog li nws tsuas yog tawm huv si. Yog tias nws tshwm sim los rau lub sijhawm tswb, nws yuav muaj suab nrov.

Txhawm rau sim tias koj cov cai tuaj yeem ua suab nrov, siv cov kab hais kom ua xaiv ntawm cov ntawv ua si. Peb yuav siv peb cov ntaub ntawv bing-bong:

pi@schoolbell: ~/schoolbell $./schoolbell.py bing-bong-chime-hq.mp3

Nws yog schoolday, tshawb xyuas lub sijhawm 21:38 Kev Ua Tau Zoo MPEG 1.0/2.0/2.5 Audio Player rau Txheej 1, 2, thiab 3. Version 0.3.2-1 (2012/03/25). Sau thiab luam cov cai los ntawm Joe Drew, tam sim no tswj los ntawm Nanakos Chrysostomos thiab lwm tus. …. ntau tshaj tawm….

Koj yuav tsum tau hnov lub tswb nrov.

Tam sim no sim cov cai nrog siv sijhawm raws li kev sib cav. Nco ntsoov nkag mus rau lub sijhawm nrog tus lej zeros. Piv txwv, los sim kuv lub tswb "tsheb npav hauv tsev kawm ntawv" thaum 9 teev sawv ntxov, Kuv ntaus:

pi@schoolbell: ~ $./schoolbell.py 09:00

Qhov no yuav tsum ua rau koj lub tswb nrov! Koj tseem tuaj yeem sim tias nws tsis nrov ntawm lub sijhawm tsis tswb.

Kauj Ruam 5: Automate Kev Ua Haujlwm Nrog Crond

Automate Kev Ua Haujlwm Nrog Crond
Automate Kev Ua Haujlwm Nrog Crond

Cron 'daemon' yog lub sijhawm teem uas ua haujlwm rov ua haujlwm ntawm Linux system. Nws tshuaj xyuas seb hnub/sijhawm zoo li tus qauv hauv cron table (crontab) thiab tom qab ntawd sau cov cai yog tias nws ua. Koj tuaj yeem kho nws siv "crontab -e" hais kom ua:

pi@schoolbell: ~ $ crontab -e

Qhov no yuav qhib cov ntawv hloov kho, thiab hauv qab ntawm cov ntawv no, koj yuav ntxiv kab hauv qab no:

* * * * * python3 /home/pi/schoolbell.py

Cov lus txib no qhia rau cron kom khiav nab hab sej 3 ua tiav koj cov ntawv hauv cov tsev qub (/home/pi). Tsib tus *hais tias qhov no yuav tsum khiav txhua feeb (thawj *), txhua teev (tom ntej *…), txhua hnub ntawm lub hli, txhua lub hlis, thiab txhua hnub ntawm lub lim tiam.

Tam sim no, txhua feeb cov ntawv schoolbell.py yuav khiav. Nyob rau feem ntau feeb, txoj cai yuav khiav thiab pom nws yuav tsum tsuas yog tso tseg yam tsis muaj chiming, tab sis yog tias nws tig los tsoo lub tswb, nws yuav nrov.

Nco ntsoov tias vim cron tsuas yog sau txhua feeb, koj tsis tuaj yeem ua lub tswb nrov ntau dua li ib feeb. Kuv xav tias nws yog qhov kev xav tau yog tias koj lub kaw lus raug teeb meem, cron yuav tsis ua haujlwm li ob peb feeb tom qab feeb kawg, ua lub tswb nrov lig. Yog tias qee qhov cron tsis ua haujlwm rau feeb tag nrho, lub tswb yuav tsis nco.

Tswv yim: Rau ncua hnub so (piv txwv li lub caij ntuj sov), koj tuaj yeem ntxiv cov hashtag (#) rau thawj tus cim ntawm kab no, uas hloov nws mus rau hauv cov lus pom thiab yog li tsis quav ntsej txog nws. Thaum tsev kawm ntawv rov los sib kho, tsuas yog tshem tawm # thiab nws yuav pib rov pib dua.

Kauj Ruam 6: Kho kom haum thiab txaus siab

Tam sim no, koj yuav tsum muaj lub tswb nrov hauv tsev ua haujlwm thiab koj tus menyuam yuav tsum tsis txhob tuaj lig rau chav kawm.

Koj tuaj yeem hloov kho txoj haujlwm no los ntawm kev hloov lub tswb nrov.

  • Koj tuaj yeem ua nws nrov nrov Big Ben, nrog lub suab nrov ib nrab teev thiab nrov nrov.
  • Koj tuaj yeem ua piv txwv koj nyiam rapper txoj kev ywj pheej.
  • Koj tuaj yeem ua cov lus subliminal kom mob siab rau kev kawm.

Nyob nyab xeeb nyob rau lub sijhawm COVID no.

Duab
Duab
Duab
Duab

Khiav Hauv Qhov "Tsis tuaj yeem kov Qhov no" Kev Sib Tw Tsev Neeg

Pom zoo: