Cov txheej txheem:

NodeMCU ESP8266 - MQTT - Ubidots: 5 Kauj Ruam
NodeMCU ESP8266 - MQTT - Ubidots: 5 Kauj Ruam

Video: NodeMCU ESP8266 - MQTT - Ubidots: 5 Kauj Ruam

Video: NodeMCU ESP8266 - MQTT - Ubidots: 5 Kauj Ruam
Video: NodeMCU ESP8266 Send Data to Raspberry Pi Using MQTT Broker 2024, Hlis ntuj nqeg
Anonim
NodeMCU ESP8266 - MQTT - Ubidots
NodeMCU ESP8266 - MQTT - Ubidots
NodeMCU ESP8266 - MQTT - Ubidots
NodeMCU ESP8266 - MQTT - Ubidots
NodeMCU ESP8266 - MQTT - Ubidots
NodeMCU ESP8266 - MQTT - Ubidots

MQTT yog OASIS tus qauv txheej txheem xa xov rau Internet ntawm Yam (IoT). Nws tau tsim los ua qhov hnyav tshaj tawm tshaj tawm/sau npe xa xov uas yog qhov zoo tshaj plaws rau kev txuas cov khoom siv tej thaj chaw deb nrog tus lej me me hneev taw thiab tsawg network kev sib kis. MQTT niaj hnub no tau siv ntau yam lag luam, xws li tsheb, tsim khoom, sib txuas lus, roj thiab roj, thiab lwm yam.

Vim li cas MQTT: MQTT cov neeg siv khoom tsawg heev, xav tau cov peev txheej tsawg kawg thiaj li tuaj yeem siv rau ntawm cov tswj me me. MQTT cov ntawv xov xwm lub taub hau me me los ua kom muaj kev sib txuas zoo hauv network.

Kev Sib Txuas Lus Ob Directional: MQTT tso cai rau kev xa xov ntawm lub cuab yeej mus rau huab thiab huab rau ntaus ntawv. Qhov no ua rau yooj yim tshaj tawm cov lus rau pawg ntawm yam.

Nplai rau Ntau lab Yam: MQTT tuaj yeem ntsuas txuas nrog ntau lab ntawm IoT cov cuab yeej.

Kev ntseeg tau ntawm kev xa xov: Nws yog qhov tseem ceeb rau ntau qhov IoT siv rooj plaub. Qhov no yog vim li cas MQTT muaj 3 qhov kev txhais tau zoo ntawm qib kev pabcuam:

  • 0 - feem ntau ib zaug,
  • 1- tsawg kawg ib zaug,
  • 2 - raws nraim ib zaug

Kev txhawb nqa rau Kev Sib Txuas Tsis Txaus Siab: Ntau IoT cov cuab yeej txuas nrog cov xov tooj ntawm tes tsis txaus ntseeg. MQTT kev txhawb nqa rau ntu ntu txuas ntxiv txo lub sijhawm rov txuas tus neeg siv khoom nrog tus tswv lag luam.

Kev Nyab Xeeb Kev Nyab Xeeb: MQTT ua kom yooj yim rau encrypt cov lus siv TLS thiab txheeb xyuas cov neeg siv siv cov txheej txheem kev lees paub niaj hnub no, xws li OAuth.

Khoom siv

  1. NodeMCU ESP8266 (lossis) lwm lub Rooj Sib Tham ESP8266
  2. Kev Sau Npe Ubidots
  3. Txhawb nqa lub tsev qiv ntawv los ntawm GitHub.
  4. Arduino IDE txhawm rau upload cov cai.

Kauj Ruam 1: Pib teeb tsa ntawm Arduino IDE

Kev teeb tsa thawj zaug ntawm Arduino IDE
Kev teeb tsa thawj zaug ntawm Arduino IDE
Kev teeb tsa thawj zaug ntawm Arduino IDE
Kev teeb tsa thawj zaug ntawm Arduino IDE
Kev teeb tsa thawj zaug ntawm Arduino IDE
Kev teeb tsa thawj zaug ntawm Arduino IDE
Kev teeb tsa thawj zaug ntawm Arduino IDE
Kev teeb tsa thawj zaug ntawm Arduino IDE
  1. Rub tawm UbidotsMQTTESP8266 lub tsev qiv ntawv los ntawm GIT Repository
  2. Qhib Arduino IDE, mus rau "nyiam" los ntawm "ntawv" ntawv qhia zaub mov.
  3. Hauv kab ntawv "Tus Thawj Saib Xyuas Lub Rooj Sib Tham Ntxiv URLs", sau cov hauv qab no: https://arduino.esp8266.com/stable/package_esp8266… & nias rau Ok mus txuas ntxiv.
  4. Nkag mus rau "Ntxiv. ZIP Library" los ntawm "Sketch> Include Library" ntawv qhia zaub mov thiab qhia txoj hauv kev ntawm rub tawm cov ntawv zip.
  5. Tos tshwj tsis yog IDE tau txais cov lus: Lub tsev qiv ntawv ntxiv rau koj lub tsev qiv ntawv. Txheeb xyuas "suav nrog Lub Tsev Qiv Ntawv" cov ntawv qhia zaub mov.
  6. Nkag mus rau "suav nrog Lub Tsev Qiv Ntawv" los ntawm "Sketch" & kos rau "Ubidots MQTT rau ESP8266"

Kauj ruam 2: Ubidots API Cov Ntawv Pov Thawj

Ubidots API Cov Ntawv Pov Thawj
Ubidots API Cov Ntawv Pov Thawj
Ubidots API Cov Ntawv Pov Thawj
Ubidots API Cov Ntawv Pov Thawj
Ubidots API Cov Ntawv Pov Thawj
Ubidots API Cov Ntawv Pov Thawj

Nkag mus rau Ubidots thiab sau ntawv ceeb toom ntawm API Cov Ntawv Pov Thawj. Thov nco ntsoov tias peb tsuas xav tau tus nqi ntawm "Default Token".

Kauj Ruam 3: Txoj Cai.

Txoj Cai.
Txoj Cai.
Txoj Cai.
Txoj Cai.

#suav nrog "UbidotsESPMQTT.h"

#define TOKEN "********************************************** *** "// Koj Ubidots TOKEN

#define WIFINAME "*********" // Koj SSID

#define WIFIPASS "******************" // Koj Wifi Pass

Ubidots tus thov kev pab (TOKEN);

tsis muaj dab tsi hu rov qab (char* ntsiab lus, byte* them nyiaj, tsis tau kos npe ntev)

{

Serial.print ("Cov lus tuaj txog [");

Serial.print (ncauj lus);

Serial.print ("]");

rau (int kuv = 0; kuv <ntev; kuv ++)

{

Serial.print ((char) payload );

}

void teeb tsa ()

{

client.setDebug (muaj tseeb);

Serial.begin (115200);

client.wifiConnection (WIFINAME, WIFIPASS);

client.begin (hu rov qab);

}

void lub voj ()

{

yog (! client.connected ())

{

client.reconnect ();

}

ntab tus nqi 1 = analogRead (A0);

client.add ("kub", tus nqi 1);

client.ubidotsPublish ("kuv-tshiab-ntaus ntawv");

client.loop (); cov.

}

Nco tseg: Thov xa mus rau cov screenshots kom pom zoo dua ntawm kab.

Kauj Ruam 4: Txuas, Sau & Tso Cai.

Txuas, Sib Sau & Tshaj Tawm Txoj Cai.
Txuas, Sib Sau & Tshaj Tawm Txoj Cai.
Txuas, Sib Sau & Tshaj Tawm Txoj Cai.
Txuas, Sib Sau & Tshaj Tawm Txoj Cai.
Txuas, Sib Sau & Tshaj Tawm Txoj Cai.
Txuas, Sib Sau & Tshaj Tawm Txoj Cai.

Nws tsis yog lub sijhawm los txuas koj NodeMCU ESP8266 rau koj lub PC/Laptop, txheeb xyuas nws qhov chaw nres nkoj, suav sau thiab xa cov cai.

Thov ua qhov kev pab tsim nyog los ntawm cov ntawv txuas nrog kom nkag siab cov txheej txheem yog tias koj tshiab rau Arduino IDE.

Kauj Ruam 5: Kuaj Kawg.

Kuaj Kawg.
Kuaj Kawg.

Yog tias txhua yam mus tau zoo, koj yuav tsum muaj peev xwm soj ntsuam zoo ib yam uas tau sawv cev hauv lub screenshot.

Kab no hauv txoj cai "client.ubidotsPublish (" kuv-tshiab-ntaus ntawv ");" tau luam tawm.

Nco tseg: Yog tias tsis muaj dab tsi tau sawv cev hauv Ubodots dashboard, nws tau hais kom tshem tawm thiab txuas dua ntawm NodeMCU.

Khaws koj tus kheej mloog. Kuv sim tshaj tawm ob peb ntxiv nrog Ubidots & NodeMCU ESP8266.

Pom zoo: