Cov txheej txheem:

Txuas Koj Cov Magicbit rau Cov Khoom Siv: 3 Kauj Ruam
Txuas Koj Cov Magicbit rau Cov Khoom Siv: 3 Kauj Ruam

Video: Txuas Koj Cov Magicbit rau Cov Khoom Siv: 3 Kauj Ruam

Video: Txuas Koj Cov Magicbit rau Cov Khoom Siv: 3 Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Kaum ib hlis
Anonim
Txuas koj Magicbit rau Thingsboard
Txuas koj Magicbit rau Thingsboard

Hauv qhov haujlwm no peb yuav xa cov ntaub ntawv los ntawm cov ntsuas hluav taws xob txuas nrog rau magicbit uas peb tuaj yeem pom pom qhov muag ntawm cov khoom ntoo.

Khoom siv:

  • Magicbit
  • DHT11 Kub & Vaum Sensor (4 pins)

Kauj ruam 1: Zaj dab neeg

Dab neeg
Dab neeg
Dab neeg
Dab neeg
Dab neeg
Dab neeg
Dab neeg
Dab neeg

Taw qhia

ThingsBoard yog qhov qhib-qhov server-sab platform uas tso cai rau koj los saib xyuas thiab tswj IoT cov cuab yeej. Nws yog pub dawb rau kev siv tus kheej thiab kev lag luam thiab koj tuaj yeem siv nws nyob txhua qhov chaw. Yog tias qhov no yog koj thawj qhov kev paub nrog lub platform peb pom zoo los tshuaj xyuas nplooj ntawv dab tsi-yog-yam khoom thiab pib-pib qhia.

Daim ntawv thov ua piv txwv no yuav tso cai rau koj kom pom cov ntaub ntawv huab cua/ntsuas kub los ntawm DHT11 lub cim siv koj lub cuab yeej khawv koob thiab ThingsBoard web UI.

Daim ntawv thov uas tau khiav ntawm Magicbit ntaus ntawv tau sau siv ThingsBoard Arduino SDK uas yog qhov yooj yim heev thiab nkag siab yooj yim.

Thaum koj ua tiav qhov piv txwv no/qhia, koj yuav pom koj cov ntaub ntawv sensor ntawm cov dashboard hauv qab no.

Mus ntsib Thingsboard Demo official page thiab tau sau npe.

Tom qab kos npe rau ntawm Sab laug Sab Bar koj yuav pom Devices. Nyem pab kiag li lawm thiab ntxiv ib lub cuab yeej tshiab.

Ntawm daim ntawv pov thawj tab zuam Ntxiv daim ntawv pov thawj thiab xaiv Access Token los ntawm lub npov nco. Xijpeem koj tuaj yeem ntxiv koj tus kheej Access Token lossis tso qhov khoob rau nws pib tsim cov cim.

Teem lub cuab yeej rau magicbit hauv npe. Mus rau ntawm lub dashboard tab thiab import dashboard.

Ua raws cov theem hauv qab no hauv cov duab rau Ntshuam lub dashboard. Nrhiav qhov demo JSON cov ntaub ntawv hu ua "magicbit_temperature_humidity_demo_dashboard.json" hauv cov ntawv txuas.

Txuas koj cov khawv koob me ntsis nrog DHT11 tus qauv raws li hauv qab no rau tus pin 33.

Hauv Arduino IDE rub tawm cov tsev qiv ntawv saum toj no.

Cov hauv qab no yog Arduino code koj yuav siv.

Nco tseg Koj yuav tsum hloov kho qhov txuas hauv qab no thiab hloov pauv hauv daim duab:

  • WIFI_AP - lub npe ntawm koj qhov chaw nkag
  • WIFI_PASSWORD - nkag lo lus zais
  • TOKEN - $ ACCESS_TOKEN los ntawm Cov Txheej Txheem Txheej Txheem txheej txheem.
  • THINGSBOARD_SERVER - ThingsBoard HOST/IP chaw nyob uas nkag tau mus rau hauv koj lub network wifi. Qhia meej demo.thingsboard.io yog tias koj tab tom siv cov neeg ua haujlwm nyob demo.

Kauj ruam 2: Arduino Code

#suav nrog // DHT rau Lub Tsev Qiv Ntawv#suav nrog // WiFi tswj rau ESP32#suav nrog // ThingsBoard SDK#txhais DHTPIN 33 // dab tsi tus lej digital peb txuas nrog rau#txhais DHTTYPE DHT11 // DHT 11DHT dht (DHTPIN, DHTTYPE); // Helper macro los laij array loj#txhais COUNT_OF (x) ((sizeof (x)/ sizeof (0 [x]))/ ((size_t) (! (Sizeof (x) % sizeof (0 [x]))))) // WiFi nkag mus taw qhia#txhais WIFI_AP_NAME "4G" // "WIFI_AP" // WiFi lo lus zais#txhais WIFI_PASSWORD "yeej tsis muab" // "WIFI_PASSWORD" // Saib https://thingsboard.io/docs/getting- pib-qhia/helloworld /// kom nkag siab yuav ua li cas thiaj li nkag tau token#txhais TOKEN "XZjQ26r9XJcsNkWGuASY" // "TOKEN" // ThingsBoard server piv txwv.#txhais THINGSBOARD_SERVER "demo.thingsboard.io" // Baud tus nqi rau debug serial #define SERIAL_DEBUG_BAUD 115200 // Pib Pib Yam KhoomBoard clientWiFiClient espClient; // Pib pib ThingsBoard piv txwv liThingsBoard tb (espClient); // Lub xov tooj cua Wifi's statusint status = WL_IDLE_STATUS; // Lub sijhawm xa cov ntaub ntawv ntsuas kub/av noo.int xa_delay =; unsigned ntev millis_counter; tsis muaj dab tsi InitWiFi () {Serial.println ("Txuas rau AP …"); // sim txuas rau WiFi network WiFi.begin (WIFI_AP_NAME, WIFI_PASSWORD); thaum (WiFi.status ()! = WL_CONNECTED) {ncua (500); Serial.print ("."); } Serial.println ("Txuas rau AP");} tsis muaj qhov txuas rov qab () {// Loop kom txog thaum peb rov txuas dua xwm txheej = WiFi.status (); yog (xwm txheej! = WL_CONNECTED) {WiFi.begin (WIFI_AP_NAME, WIFI_PASSWORD); thaum (WiFi.status ()! = WL_CONNECTED) {ncua (500); Serial.print ("."); } Serial.println ("Txuas rau AP"); }} // Teeb tsa daim ntawv thov tsis muaj teeb tsa () {// Pib ua ntu zus rau kev debugging Serial.begin (SERIAL_DEBUG_BAUD); WiFi.begin (WIFI_AP_NAME, WIFI_PASSWORD); InitWiFi (); // Pib ntsuas qhov ntsuas kub dht.begin ();} // Daim ntawv thov tseem ceeb loopvoid loop () {// Txuas dua rau WiFi, yog xav tau yog (WiFi.status ()! = WL_CONNECTED) {rov txuas dua (); rov qab; } // Rov txuas rau ThingsBoard, yog xav tau yog (! Tb.connected ()) {// Txuas mus rau ThingsBoard Serial.print ("Txuas rau:"); Serial.print (THINGSBOARD_SERVER); Serial.print ("nrog token"); Serial.println (TOKEN); yog (! tb.connect (THINGSBOARD_SERVER, TOKEN)) {Serial.println ("Ua tsis tau txuas"); rov qab; }} // Txheeb xyuas seb nws yog lub sijhawm xa DHT11 qhov kub thiab txias yog (millis ()-millis_counter> xa_delay) {Serial.println ("Xa cov ntaub ntawv …"); // Uploads tshiab telemetry rau ThingsBoard siv MQTT. // Saib https://thingsboard.io/docs/reference/mqtt-api/#telemetry-upload-api // kom paub meej ntxiv ntab h = dht.readHumidity (); // Nyeem kub li Celsius (lub neej ntawd) ntab t = dht.readTemperature (); yog (isnan (h) || isnan (t)) {Serial.println ("Ua tsis tau tejyam nyeem los ntawm DHT sensor!"); } lwm {Serial.print ("Kub:"); Serial.print (t); Serial.print ("Vaum"); Serial.println (h); tb.sendTelemetryFloat ("kub", t); tb.sendTelemetryFloat ("av noo", h); } millis_counter = millis (); // rov pib dua millis counter} // Txheej txheem lus tb.loop ();}

Kauj Ruam 3: Kev Pom Cov Ntaub Ntawv

Cov Ntaub Ntawv Pom Kev
Cov Ntaub Ntawv Pom Kev

Nyob rau hauv-demo server:

  • ID nkag mus: koj lub npe-demo username (email)
  • lo lus zais: koj tus lej-demo password

Saib nplooj ntawv-nyob demo kom paub meej ntxiv yuav ua li cas kom tau koj tus as khauj.

Mus rau "Devices" ntu thiab nrhiav "Magicbit", qhib cov ntsiab lus ntaus ntawv thiab hloov mus rau "Tseeb telemetry" tab. Yog tias txhua yam tau teeb tsa kom raug koj yuav tsum tuaj yeem pom qhov txiaj ntsig kawg ntawm "kub" thiab "av noo".

Tom qab, qhib "Dashboards" ntu tom qab ntawd nrhiav thiab qhib "magicbit_temperature_humidity_demo_dashboard". Raws li qhov tshwm sim, koj yuav pom daim ntawv teev sijhawm teev qhia qhov ntsuas kub thiab av noo (zoo ib yam li daim duab qhia chaw hauv kev taw qhia).

Pom zoo: