Cov txheej txheem:

TextPlayBulb: REST Enabled PlayBulb Siv Raspberry Pi 3, BLE thiab Telegram: 3 Kauj Ruam
TextPlayBulb: REST Enabled PlayBulb Siv Raspberry Pi 3, BLE thiab Telegram: 3 Kauj Ruam

Video: TextPlayBulb: REST Enabled PlayBulb Siv Raspberry Pi 3, BLE thiab Telegram: 3 Kauj Ruam

Video: TextPlayBulb: REST Enabled PlayBulb Siv Raspberry Pi 3, BLE thiab Telegram: 3 Kauj Ruam
Video: Candles Get Colorful and Interactive with PLAYBULB 2024, Kaum ib hlis
Anonim
TextPlayBulb: REST Enabled PlayBulb Siv Raspberry Pi 3, BLE thiab Telegram
TextPlayBulb: REST Enabled PlayBulb Siv Raspberry Pi 3, BLE thiab Telegram

Cov lus qhia no qhia yuav ua li cas txuas mus rau PlayBulb Xim bluetooth LED teeb siv Python, Raspberry Pi 3 thiab Bluetooth lub tsev qiv ntawv thiab txuas ntxiv kev tswj hwm ntawm REST API rau IoT qhov xwm txheej, thiab raws li pob, txoj haujlwm tseem qhia tau tias yuav txuas ntxiv li cas REST API los tswj koj li PlayBulb hla IM cov ntawv thov piv txwv Telegram, xws li tham nrog koj lub tsev tsis siv neeg ntawm cov ntawv.

Txoj haujlwm no tsim los ntawm 3 tus qauv:

  1. pyBulbDriver: Txuas rau PlayBulb ntawm BLE gatttool thiab nab hab sej.
  2. pyBulbServer: Siv lub pyBulbDriver los nthuav tawm lub playbulb tswj ntawm REST API.
  3. pyBulbMessenger: Txuas rau tus xov tooj bot xa thiab tau txais lus txib ntawm tus neeg siv xov tooj cua tau teeb tsa ntawm txhua lub xov tooj ntse, thiab siv REST API los tshaj tawm cov lus txib rau PlayBulb.

Koj tuaj yeem tsim qhov project ntawm git repository:

Lub Hom Phiaj ntawm Txoj Haujlwm:

Txhawm rau tsim lub hauv paus cov cuab yeej rau kev cuam tshuam nrog koj lub teeb ntawm cov qauv sib txawv xws li kev xa xov rau tam sim no, cov xwm txheej yav tom ntej tuaj yeem cuam tshuam kev hais lus hais lus, taw tes rau lub teeb … thiab lwm yam.

Lwm cov peev txheej siv los tsim cov lus qhia no:

  • PlayBulb Xim Bluetooth Txheej Txheem:
  • Txuas Python rau Playbulb ntawm Bluetooth:
  • Teeb tsa tus lej xov tooj:

Kev koom tes

pyBulbDriver tau txuas ntxiv kom hloov pauv tau yooj yim thiab ntsuas kom yooj yim ntawm kev txuas ntxiv mus yav tom ntej, tsim cov xwm txheej kom tso cai rau koj fiddle nrog kev xa xov ntawm koj lub teeb. Yooj yim interface rau kev sim thiab fiddling ncig.

Txwv

Tus tsav tsheb tau sau rau PlayBulb Xim, rau lwm hom PlayBulb xws li Thawj lossis tswm ciab, tus lej bluetooth hauv pyBulbDriver xav tau hloov pauv raws li cov lus tau hais tseg.

Koj yuav tsum sau npe tus lej xov tooj, thiab tau txais tus yuam sij api, uas koj ntxiv rau hauv pyBulbMessenger.py, ua raws li teeb tsa tus lej xov tooj bot hauv O ther cov peev txheej.

Kauj Ruam 1: Teeb Txoj Haujlwm

1. Tau txais koj tus lej API los ntawm Telegram

> Ua raws cov lus qhia tam sim no kom tau txais koj tus lej API

> Ntxiv koj tus lej api rau qhov sib txawv api hauv pyBulbMessenger.py

2. Teeb koj Lub Npe PlayBulb hauv pyBulbDriver

> Rau lub gatttool kom pom cov cuab yeej sau, teeb tsa koj lub cuab yeej lub npe kom raug siv siv pyBulbDriver.scanForBulb ("PLAYBULB COLOR"). Piv txwv tuaj yeem pom hauv pyBulbServer.py teeb tsa koj li REST Server

3. Txhawm rau pib txoj haujlwm

> Koj yuav tsum pib pyBulbServer.py ua ntej, tom qab ntawd ua los ntawm pyBulbMessenger.py rau kev xa ntawv. Koj tuaj yeem sim cov pyBulbServer cov lus txib siv CURL.

4. Cov Khoom Xav Tau:

> Raspberry Pi 3 thiab PlayBulb Xim lossis PlayBulb Tswmciab

> Txhim Kho Telegram rau Android lossis iOS

5. Kev teeb tsa Rasberry Pi 3 LE Bluetooth:

www.elinux.org/RPi_Bluetooth_LE

Kauj Ruam 2: Taug Kev Los Ntawm Txoj Cai

pyBulbDriver.py

pyBulbDriver muaj cov chav kawm tsav tsheb rau txuas rau PlayBulb ntawm BLE

pyBulbDriver tuaj yeem siv tau rau lwm qhov haujlwm zoo ib yam, vim nws tsuas muaj cov lej txhawm rau tshuaj xyuas thiab teeb tsa kev sib txuas playBulb.

Lub ntsiab APIs rau Tus Neeg Siv Daim Ntawv Thov interface:

  • scanForBulb (devicename: String)> Txhawm rau luam theej duab rau PlayBulb lossis PlayBulbs ntawm lawv lub npe ntaus ntawv
  • setBulbColor (s: int, r: int, g: int, b: int)> Txhawm rau txheeb xyuas qhov ci ci thiab RGB xim (0 txog 255) qhov tseem ceeb
  • setBulbEffect (s: int, r: int, g: int, b: int, hom: int, onbeat: int, offbeat: int)> Zoo ib yam li setBulbColor, tab sis suav nrog hom kev cuam tshuam thiab nrawm. Txhawm rau paub ntau ntxiv txheeb xyuas cov txheej txheem xim Cov teebmeem

Hauv chav kawm no koj tseem yuav pom lwm txoj hauv kev pab txhais rau cov ntaub ntawv txheeb xyuas qhov tseeb thiab tsis yog rau cov neeg siv cuam tshuam

  • hloov RGBToHexaCmd (s, r, g, b)
  • convertIntToHex (tus lej)
  • checkModeAndSpeed (hom, offbeat, onbeat)
  • tshev RGBInBounds (s, r, g, b)

pyBulbServer.py

pyBulbServer nthuav tawm Tus Neeg Siv Khoom sib cuam tshuam rau RESTful hyperlinks siv PUT thiab JSON xa thiab txais cov ntaub ntawv rau pyBulbDriver. Tsis tas li qhov kev tshuaj xyuas thiab pib ua haujlwm ntawm BLE kev sib txuas yog ua thaum lub server tau qhib.

pyBulbResource (Cov peev txheej) ua raws cov kev hu mus rau REST Server siv cov xim thiab cov txiaj ntsig txhawm rau txheeb xyuas lub teeb hais kom ua.

Piv txwv rau kev hais kom ua cov nyhuv:

127.0.0.1/bulb/effect

JSON POST> {data ':' {"s": 0, "r": 255, "g": 255, "b": 255, "m": 1, "on": 15, "tawm": 15 } '}

pyBulbMessenger.py

Thaum kawg pyBulbMessenger yog lub luag haujlwm cuam tshuam rau Telegram bot txuas nrog koj cov neeg siv xov tooj ntawm tes. Yog xav paub ntau ntxiv txog yuav teeb tsa thiab txuas mus rau tus lej xov tooj bot txheeb xyuas

cmdHandler (bot, hloov tshiab) yog qhov uas cov lus txib tau hais tseg thiab txuas nrog PlayBulb ntawm RESTful API.

Tam sim no txoj haujlwm tsuas muaj cov ntawv xwb, lwm lub hom phiaj tseem yuav xa cov lus kaw suab uas yuav xa mus rau tus neeg lees paub hais lus kom qhib lwm cov lus txib (Tsis Tau Ua Tiav).

Kauj Ruam 3: Xaus

Kev tsim qauv vaj tsev tam sim no tau hais ntau ntxiv txog kev yooj yim dua li kev ua kom loj dua. Tseem tsis muaj pab pawg sib txuas, tseem muaj ntau daim ntawv thov hais txog kev xa xov rau lub teeb rau ncaj qha hais kom ua lossis cuam tshuam nrog kev sib tham tseem tab tom tshawb fawb.

Los ntawm kev tso npe rau git repo lossis ua raws hauv qab no, cov ncauj lus kom ntxaws yuav los ntawm cov kev hloov tshiab no. Qhov laj thawj rau qhov phiaj xwm no yog txhawm rau cuam tshuam nrog playBulb thiab tsim RESTful interface kom yooj yim ntawm kev txhim kho hauv IoT (internet ntawm yam xwm txheej) tab sis kuj tseem qhib lub sijhawm los siv ntau yam sib txawv ntawm IM Client xov tooj xws li duab, suab thiab ntawv los cuam tshuam nrog cov cuab yeej siv los ntawm kev tshawb fawb pom.

Pom zoo: