Cov txheej txheem:

IoT Tsev Kawm Ntawv Txoj Haujlwm Philips Hawj txawm: 19 Kauj Ruam
IoT Tsev Kawm Ntawv Txoj Haujlwm Philips Hawj txawm: 19 Kauj Ruam

Video: IoT Tsev Kawm Ntawv Txoj Haujlwm Philips Hawj txawm: 19 Kauj Ruam

Video: IoT Tsev Kawm Ntawv Txoj Haujlwm Philips Hawj txawm: 19 Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Kaum ib hlis
Anonim
IoT School Project Philips Hawj
IoT School Project Philips Hawj

Nov yog phau ntawv qhia kuv tau sau rau tsev kawm ntawv. Nws tsis tiav thiab kuv tsis paub tseeb tias koj tseem tuaj yeem siv nws. Kuv paub txog API's yog qhov tsawg kawg nkaus. Peb xav ua daim iav sib tham nrog teeb nyob sab nraub qaum uas tau ua rau huab cua, teeb pom kev sab nraud, thiab lwm yam.

Kuv saib yuav ua li cas kuv tuaj yeem teeb tsa Philips Hawj teeb nrog Arduino. Hauv qhov no, kuv piav qhia tag nrho kuv cov kauj ruam thiab kuv tuaj txog deb npaum cas. Kuv tsis tau ua tiav hauv kev sau Hue nrog Arduino tab sis kuv xav tias nws yog qhov pib zoo.

Kuv xav tau qhov no: Arduino lub hue teeb ib tus choj Philips Hawj tus tsim tawm nyiaj

Cov peev txheej: https://www.developers.meethue.com/documentation/g…https://github.com/bsalinas/ArduinoHuehttps://arduino-esp8266.readthedocs.io/en/latest/e…https:// www.makeuseof.com/tag/control-philips-hue-…

Kauj ruam 1: Pib

Ua ntej koj tuaj yeem nkag mus rau API cov ntaub ntawv, koj yuav tsum tau sau npe ua tus tsim tawm. Nws yog dawb, tab sis koj yuav tsum lees txais cov lus thiab cov xwm txheej. Koj tuaj yeem ua ib qho ntawm no>

Kauj ruam 2: Hue App

Rub tawm lub official Philips Hawj txawm App. Txuas koj lub xov tooj mus rau lub network koj xav kom Hue choj qhib.

Kauj Ruam 3: Txuas Tus Choj

Txuas koj tus choj nrog koj lub network thiab ua haujlwm tau zoo. Kuaj tias lub smartphone app tuaj yeem tswj lub teeb ntawm tib lub network. Nws yuav tsum yog tib lub Wi-nkaus network.

Kauj Ruam 4: IP Chaw Nyob

Tom qab ntawd koj yuav tsum tshawb pom tus IP chaw nyob ntawm tus choj ntawm koj lub network. Laub txuas txuas mus rau tus choj hauv app thiab sim tswj teeb.

Kauj ruam 5:

Yog tias txhua yam ua haujlwm ces mus rau cov ntawv qhia zaub mov teeb tsa hauv app. Txhawm rau mus rau "Kuv Tus Choj", mus rau "Network teeb tsa". Hloov qhov DHCP toggle thiab koj pom tus IP chaw nyob ntawm tus choj. Nco ntsoov tus IP chaw nyob, tom qab ntawd hloov DHCP rov qab.

Kauj ruam 6: Debug Koj Hawj txawm

Debug Koj Hawj
Debug Koj Hawj

Thaum koj sau qhov ntawd koj yuav tsum tau debug koj Hue. Koj xav tau IP-Chaw Nyob rau theem no. Koj yuav tsum tau mus ntsib tus xaib tom ntej.

/debug/clip.html

Lub interface yuav zoo li qhov no hauv daim duab. Qhov no yog lub hauv paus ntawm txhua lub vev xaib thiab ntawm cov xim RESTful interface.

Kuv tau txais cov ntaub ntawv no hais txog Restful interface ntawm Philips Hue site.

URL: qhov no yog qhov chaw nyob hauv ib cheeb tsam ntawm cov peev txheej tshwj xeeb (yam) hauv cov kab ke hue. Nws tuaj yeem yog lub teeb, pab pawg teeb lossis ntau yam ntxiv. Nov yog lub hom phiaj koj yuav cuam tshuam nrog hauv cov lus txib no.

Lub cev: qhov no yog ib feem ntawm cov lus uas piav qhia txog yam koj xav hloov thiab yuav ua li cas. Ntawm no koj nkag mus, hauv JSON hom ntawv, cov peev txheej lub npe thiab tus nqi koj xav hloov/ntxiv.

Ib txoj hauv kev: ntawm no koj muaj kev xaiv 4 HTTP txoj hauv kev hu xov tooj tuaj yeem siv.

GET: qhov no yog cov lus txib kom nqa tag nrho cov ntaub ntawv hais txog cov peev txheej hais daws

PUT: qhov no yog cov lus txib hloov kho qhov chaw nyob

POST: qhov no yog cov lus txib los tsim cov peev txheej tshiab hauv cov peev txheej hais daws

DELETE: qhov no yog cov lus txib kom tshem tawm cov peev txheej tau teb Cov lus teb: Hauv cheeb tsam no, koj yuav pom cov lus teb rau koj cov lus txib. Tsis tas li hauv JSON hom.

Kauj Ruam 7: Cia Peb Pib

Cia Peb Pib
Cia Peb Pib

Tam sim no peb xav tau lub npe tsim siv lub npe uas tus choj tsim rau koj. Koj yuav tau txais ib qho los ntawm kev sau qhov no.

Muab tso rau hauv qhov URL:

/api/

Muab tso rau hauv BODY:

thiab nias GET

Cov lus txib no yog hais hauv paus "thov tsim cov peev txheej tshiab sab hauv /api" (qhov twg cov npe neeg siv zaum) nrog cov khoom hauv qab no. Thaum xub thawj, koj yuav tau txais qhov yuam kev, thiab qhov ntawd yog vim nws yog qib ruaj ntseg ntawm Philips Hawj txawm. Los ntawm nias lub pob lawv ua pov thawj tias koj muaj lub cev nkag mus rau tus choj.

Kauj ruam 8:

Duab
Duab

Tam sim no Nias lub pob ntawm Choj thiab nyem POST dua.

Tam sim no koj yuav tau txais lub npe siv uas tus choj tau ua rau koj.

Kauj Ruam 9: Cia Peb Ua Dab Tsi Nrog Teeb

Cia Peb Ua Dab Tsi Nrog Teeb
Cia Peb Ua Dab Tsi Nrog Teeb

Luam koj lub npe siv thiab muab tso rau hauv kab hauv qab no.

Muab qhov no tso rau hauv koj qhov URL

/api//teeb

Nias GET

Koj yuav tsum tau txais JSON cov lus teb nrog txhua lub teeb hauv koj lub kaw lus thiab lawv cov npe.

Kauj ruam 10:

Duab
Duab

Kuv tau qiv qee qhov Hue Lights los ntawm tsev kawm ntawv, qhov kuv siv yog tus lej ID 3. Kuv xav tau cov ntaub ntawv tshwj xeeb txog lub teeb no.

Muab qhov no txuas rau qhov URL koj twb muaj:

/api//teeb/3

Nias GET

Tam sim no koj tau txais cov ntaub ntawv hais txog Led 3 (yog tias koj muaj lwm tus lej zoo li 1 koj yuav pom cov ntaub ntawv hais txog tus ntawd).

Kauj Ruam 11: Cia Tswj Lub Teeb

Cia Tswj Lub Teeb
Cia Tswj Lub Teeb

Koj pom hauv "xeev" uas kuv coj yog "nyob". Peb xav tswj lub teeb nyob rau hauv "xeev".

Muab qhov no txuas rau qhov URL koj twb muaj: https:/// api// lights/ 3/ state

Muab kab tom ntej hauv BODY

Nias TUS

Tam sim no koj lub teeb yuav raug tua! Hloov tus nqi hauv lub cev kom muaj tseeb thiab lub teeb yuav qhib dua.

Kauj ruam 12:

Tam sim no txhua yam ua haujlwm Kuv xav ua qhov no nrog kuv Arduino. Kuv saib ntawm qhov txuas Philips Hawj muab rau ua kom lub teeb hloov xim. Tab sis koj xav tau Python rau qhov no, Kuv tsis tau ua haujlwm nrog Python yog li kuv tau nrhiav lwm yam.

Yog tias koj nyiam saib tus lej no kuv muaj Github txuas ntawm no:

github.com/bsalinas/ArduinoHue

Kauj ruam 13:

Kuv saib yuav ua li cas kuv tuaj yeem tau txais cov ntaub ntawv los ntawm lub xaib tsim tawm no rau kuv arduino. Feem ntau kuv tsis nkag siab cov lus. Tab sis kuv pom qee tus lej ntawm lub vev xaib los ntawm James Bruce.

Nov yog qhov txuas rau lub vev xaib.

www.makeuseof.com/tag/control-philips-hue-lights-arduino-and-motion-sensor/

Kauj ruam 14:

Ua ntej kuv pom tias nws tau siv Ethernet cable. Kuv tsuas muaj Hue Teeb thiab Choj Arduino, thiab nkag siab me ntsis txog cov cai. Nws siv sijhawm me ntsis rau kuv kom nkag siab nws cov cai, tab sis kuv tseem tsis nkag siab tiag.

Kuv xub ntxiv lub tsev qiv ntawv no rau internet.

#suav nrog

Nov yog rau koj lub network (nws yuav tsum zoo ib yam li Hue Teeb)

const char* ssid = ""; // tso koj li Wi -nkaus network SSIDconst char* password = ""; // tso koj li Wi -nkaus network password

Cov no yog tus lej ntawm Koj Tus Choj thiab lub npe siv uas koj tus choj tau muab rau koj. (Kuv tsis paub qhov twg 80 sawv rau tab sis thaum kuv tau ua qee qhov kev tshawb fawb kuv pom tias nws tau siv rau kev sib txuas).

// Hue constants const char hueHubIP = ""; // Hue hub IP const char hueUsername = ""; // Hue username const int hueHubPort = 80;

// Hue variables bool hueOn; // rau/tawm int hueBri; // ci ntsa iab tus nqi ntev hueHue; // hue value Txoj hlua hueCmd; // Hawj hais kom ua

unsigned ntev tsis = 0; // tsis tau txais cov ntaub ntawv cia tsis kos npe ntev ntxiv;

Kauj ruam 15:

Rau qhov tsis muaj teeb tsa, kuv tau ua ntau tshaj rau kev txuas hauv is taws nem. Hauv txoj cai no, Arduino tab tom saib seb nws puas tuaj yeem txuas nrog lub network.

teeb tsa tsis muaj dab tsi () {Serial.begin (9600);

Serial.println ();

Serial.printf ("Txuas rau %s", ssid);

WiFi.begin (ssid, password);

thaum (WiFi.status ()! = WL_CONNECTED) {

ncua (500);

Serial.print ("."); }

Serial.println ("txuas nrog"); }

Kauj ruam 16:

Hauv lub voj ntawm James, Kuv pom tias nws muaj Yog thiab lwm nqe lus. Tab sis qhov ntawd yog rau ethernet cable, yog li kuv tau sim tawm qhov no tawm. Kuv kuj qee zaum tau sim kho nws, tab sis kuv tseem tsis tau paub nrog cov ntaub ntawv ntau. Qee yam hauv txoj cai kuv tau nkag siab, hauv txoj hlua yog cov ntaub ntawv uas muab rau Hawj teeb.

void voj () {

// Ib pawg ntawm plaub tus qauv hais kom ua, uas cov xim ploj ob lub teeb ntawm liab thiab liab. Nyeem rau ntawm Hue API // cov ntaub ntawv kom paub meej ntxiv ntawm cov lus txib kom siv, tab sis nco ntsoov tias cov cim cim yuav tsum tau khiav dim.

String command = "{" on / ": true, \" hue / ": 50100, \" sat / ": 255, \" bri / ": 255, \" transitiontime / ":"+String (random (15), 25))+"}"; setHue (1, hais kom ua);

command = "{" on / ": true, \" hue / ": 65280, \" sat / ": 255, \" bri / ": 255, \" transitiontime / ":"+String (random (15, 25))+"}"; setHue (2, hais kom ua);

command = "{" hue / ": 65280, \" sat / ": 255, \" bri / ": 255, \" transitiontime / ":"+String (random (15, 25))+"}"; setHue (1, hais kom ua);

command = "{" hue / ": 50100, \" sat / ": 255, \" bri / ": 255, \" transitiontime / ":"+String (random (15, 25))+"}"; setHue (2, hais kom ua);

}

Kauj ruam 17:

Cov cai tom ntej yog Boolean, tab sis hauv Arduino koj yuav tsum sau Bool. Thaum xub thawj, kuv tau txais ntau qhov yuam kev vim yog lo lus tus neeg siv khoom. Yog li kuv saib nws thiab pom tias qee qhov chaws siv kab "WifiClient tus thov kev pab;". Yog li kuv tau siv nws thiab nws ua haujlwm.

Hauv cov ntawv yog tias koj nquag pom cov neeg siv khoom. Yog tias koj saib mus rau hauv txoj cai, koj yuav pom tias qhov URL koj nkag mus ua ntej tau muab faib ua tej daim. Tam sim no sau koj tus kheej cov cai. Kuv yuav tsum xaiv kuv lub teeb LED thib 3.

/ * setHue () yog peb lub luag haujlwm tseem ceeb, uas yuav tsum tau dhau tus lej lej thiab * tsim kom raug cov kab lus hais kom ua hauv JSON hom (feem ntau yog Javascript style array array ntawm cov kev hloov pauv * thiab qhov muaj nqis. Tus Choj ntawm IP tau teev tseg thaum pib. */

bool setHue (int lightNum, Txoj hlua hais kom ua) {

WiFiClient tus thov kev pab;

yog (client.connect (hueHubIP, hueHubPort)) {

thaum (client.connected ()) {

client.print ("PUB /api /"); client.print (hueUsername); client.print ("/teeb/"); client.print (lightNum); // hueLight xoom raws, ntxiv 1 client.println ("3/xeev"); // ntawm no kuv hloov lub hue npe thiab stateclient.print ("Tus tswv:"); client.println (hueHubIP); client.print ("Cov ntsiab lus-Ntev:"); client.println (command.length ()); client.println ("Cov Ntsiab Lus-Hom: ntawv/tiaj; charset = UTF-8"); client.println (); cov. // kab dawb ua ntej lub cev client.println (hais kom ua); // Hawj hais kom ua

} client.stop (); rov muaj tseeb; // hais kom ua tiav}

lwm tus rov qab tsis tseeb; // hais kom ua tsis tiav}

Kauj ruam 18:

Ntawm Boolean thib ob, Kuv tau ua tib yam nrog hloov qee lo lus. Kuv upload nws mus saib yog nws ua haujlwm.

/* Tus pab cuam ua haujlwm yog tias koj lub tswv yim nyob ntawm qhov pom kev tam sim no. * Qhov no teeb tsa tus lej ntawm kev hloov pauv thoob ntiaj teb uas koj tuaj yeem tshawb xyuas seb puas muaj lub teeb pom kev tam sim no lossis tsis yog * thiab hue thiab lwm yam. Tsis xav tau tsuas yog xa tawm cov lus txib */

bool getHue (int lightNum) {

WiFiClient tus thov kev pab;

yog (client.connect (hueHubIP, hueHubPort)) {

client.print ("Tau txais /api /"); client.print (hueUsername); client.print ("/teeb/"); client.print (lightNum); client.println ("3/xeev"); client.print ("Tus tswv:"); client.println (hueHubIP); client.println ("Cov ntsiab lus-hom: thov/json"); client.println ("ua kom muaj sia nyob"); client.println (); cov.

thaum (client.connected ()) {yog (client.available ()) {client.findUntil ("\" ntawm / ":", "\ 0"); hueOn = (client.readStringUntil (',') == "tseeb"); // yog tias lub teeb pom kev, teeb tsa qhov sib txawv rau qhov tseeb client.findUntil ("\" bri / ":", "\ 0"); hueBri = client.readStringUntil (',').toInt (); // teeb tsa qhov sib txawv rau qhov ci ci tus nqi client.findUntil ("\" hue / ":", "0"); hueHue = client.readStringUntil (',').toInt (); // teeb tsa sib txawv rau hue tus nqi so; // tseem tsis tau txais lwm cov yam ntxwv tseem ceeb}} client.stop (); rov muaj tseeb; // ntes tau, bri, hue} lwm qhov rov qab tsis tseeb; // yuam kev nyeem ntawv, bri, hue}

Kauj ruam 19:

Duab
Duab

Kuv xav tias kuv tuaj yeem txuas nrog Philips Hawj txawm. Kuv tau txais cov ntaub ntawv tab sis nws tseem yuav tsum tau siv.

Hmoov tsis zoo, qhov no mus dhau qhov kuv tuaj yeem ua chaws. Yog tias koj paub cov lus teb, lossis yog tias muaj qhov yuam kev tiag tiag uas yuav tsum tau kho, Kuv xav hnov nws.:-)

Pom zoo: