Khumbula igama I-MQTTKuba uhlobo lwenethiwekhi lwenethiwekhi M2M (Umatshini kuMatshini) eza kuvakala kancinci. Iya isiba ngumbulelo othandwa kakhulu kwixesha elitsha le-Intanethi yezinto okanye i-IoT (i-Intanethi yeZinto) kwisifinyezo sayo ngesiNgesi. Ukongeza, yiprotocol evulekileyo, enika izibonelelo ezininzi.
Ngapha koko, iye yaba yenye yeentsika eziphambili ze-IoT, njengoko ilungile kwizixhobo ezinomda wokuhambisa njengale. Isichazi MQTT sivela Umyalezo oQhelekileyo woThutho lweTelemetryUmgangatho ovulekileyo ovela kwi-OASIS kunye ne-ISO (ISO / IEC 20922) yonxibelelwano lwenethiwekhi kwaye ngokubanzi isebenza kwi-TCP / IP eyaziwayo.
Iinkqubo zenethiwekhi
Los iinkqubo zonxibelelwano Yimigaqo evumela izixhobo okanye iinkqubo ezingaphezulu ezimbini okanye iinkqubo zokunxibelelana. Oko kukuthi, ngumgaqo wokudlulisa ulwazi ngeendlela ezahlukeneyo kunye nefomathi echaziweyo, nokuba iphunyezwe yisoftware kunye nezixhobo zekhompyutha (okanye zombini).
El esemgangathweni yomgaqo-nkqubo ichaza ubuninzi beempawu zonxibelelwano. Inokuya kwimigaqo yokuvumelanisa, iisemantiki, is syntax, ifomathi yepakethi, njl. Kwaye inyani kukuba ayisiyonto ixabisekileyo, kuba enkosi kwezi protocols namhlanje sinokusebenzisa i-Intanethi kunye nezinye iinethiwekhi zonxibelelwano ...
Kwaye, akukho kuphela umthetho olandelwayo, kodwa uninzi. Umzekelo, abadumileyo I-DNS, FTP, MQTT, HTTP kunye ne-HTTPS, IMAP, LDAP, NTP, DHCP, SSH, Telnet, SNMP, SMTP, njl. Ngelixa kuluhlu lwezothutho unokufumana ezinye ezidumileyo njenge-TCP, i-UDP, njl.njl. i-IoT), i-IPSec, njl.
Malunga neeprotokholi ze-IoT
Ewe kunjalo, kukho iinkqubo ezithile zonxibelelwano okanye ezinokusetyenziswa kwifayile ye- yasebukhosi-. Oko kukuthi, kuthathelwa ingqalelo icandelo elidlulileyo, baya kuba luthotho lwemigangatho echaziweyo ukwenzela ukuba izixhobo ze-IoT ezimbini nangaphezulu zinxibelelane kwaye ziqondane, kwaye zihlala zi-M2M, oko kukuthi, unxibelelwano ngomatshini ukuya kumatshini. izixhobo ezininzi ze-IoT ziqhagamshele kunye nokwabelana ngolwazi oluvela kwiisenzi okanye eminye imithombo
Ngenxa yenani elikhulu lezixhobo ze-IoT, ezi protocols kufuneka zihlangabezane neemfuno ezingaphaya komda wobubanzi bebhendi, isantya, njl. (Qaphela ukuba izixhobo ezininzi zingenisiwe kwaye zinexabiso eliphantsi), ezihlala zikho kwizixhobo ezithile. Kwaye ndiyathetha inyani yokuba kufuneka ichache, ukuze ube nakho ukongeza izixhobo ezithe xaxe xa kukho imfuneko kwaye ngaphandle kokuchaphazela inkqubo yehlabathi.
Kananjalo kufuneka babenazo ukuxhomekeka okuphantsi Ukudibana phakathi kwezixhobo, ukwenzela ukuba iingxaki ziveliswe ukuba isixhobo siyasuswa. Kwaye ke, kwangaxeshanye, ukusebenzisana okuphezulu kuyafunwa ukuze kusebenze kunye nenani elikhulu lezixhobo kunye neenkqubo ezahlukeneyo, kuba ilizwe le-IoT linobuzaza kakhulu.
Ezinye izinto eziluncedo ziya kuba lula ukuzisebenzisa, ukhuselekonjl. Gcina ukhumbula ukuba i-IoT yenza umceli mngeni omkhulu kwicandelo lokhuseleko. Ngakumbi ke xa uninzi lwezixhobo ezixhumeneyo zihlala zibaluleke kakhulu kwiimeko ezithile ... umzekelo, iithoyi zabantwana.
Iikhonsepthi ezibalulekileyo
Oko kwathethi, kufuneka kuthiwe izisombululo ze-IoT zisebenzisa iserver esembindini ukufumana imiyalezo evela kuzo zonke izixhobo ezixhumeneyo ezikhuphayo kwaye zisasazwe kuzo zonke izixhobo ze-IoT ezimanyileyo. Loo seva yinto eyaziwa njenge umzila okanye umrhwebi. Into ekude nolwalamano oluqhelekileyo lomthengi-weseva ngeendlela ezithile.
Ngakolunye uhlangothi, iindlela onokuzifumana kwezi nkqubo zonxibelelwano ze-IoT zezi:
- I-PubSub: Shicilela / Susbcribe yipateni yemiyalezo apho isixhobo (Sub) sazisa umrhwebi ukuba ufuna ukufumana umyalezo, ngelixa esinye isixhobo (iPub) sipapasha imiyalezo yokuba umrhwebi asasaze kwesinye isixhobo esilindele.
- RRPC: Inkqubo yokuLungisa iRouter Iifowuni yenye yeepateni zenkqubo yokude. Kuyo, isixhobo (Callee) sazisa umrhwebi ukuba siyakwenza inkqubo ethile kwaye umrhwebi uyisasaza kwesinye isixhobo (umfownela apho inkqubo iyenziwa.
Ngoku, ukwenza ezi ndlela okanye iipateni, a izibonelelo zemiyalezo. Ngale ndlela, ezimbini zinokwahlula:
- Umgca womyalezoInkonzo yokuthumela imiyalezo apho umgca omnye womyalezo wenziwe kubo bonke abathengi abaqala ukubhalisa kubroker. Le yokugqibela iya kugcina imiyalezo igcinwe ide ihanjiswe kumxhasi. Ukuba umxhasi okanye umamkeli akaxhunyiwe, igcinwa ide idityaniswe. Ezi ntlobo zeenkonzo zifana nezo zisetyenziselwa ii -apps zemiyalezo ekhawulezileyo ezinje ngeTelegra, WhatsApp, Messenger, njl.
- Inkonzo Yomyalezo: Le yenye inkonzo apho umrhwebi ethumela imiyalezo kumxumi womamkeli odibeneyo, ukuhluza ngohlobo lomyalezo. Ukuba umxhasi okanye isixhobo esamkelwayo sikhutshiwe, imiyalezo iyalahleka (nangona inokuba inenkqubo yokuloga).
Iiprotokholi ze-IoT
Sele sikubonile oku kungasentla, ngoku makhe sijonge ngakumbi Iiprotokholi ze-IoT ezaziwa ngcono. Phakathi kwezona zibalaseleyo ze-M2M zezi:
- I-AMQP (iProtokholi yoMyalezo oPhambili)yiprothokholi yohlobo lwePubSub yomgca womyalezo. Yenzelwe ukusebenzisana kakuhle kunye nokuqinisekisa ukuthembeka. Ikhethekileyo kwizicelo zomdibaniso, ukusebenza okuphezulu, uthungelwano oluphezulu lokuhamba, ukugxeka, njl.
- I-WAMP (iProtokholi yoLawulo lweSicelo seWebhu): yenye iprothokholi evulekileyo yohlobo lwePubSub njenge-rRPC, kwaye iyasebenza kwiWebSocket.
- I-CoAP (Inkqubo Yesicelo Esinyanzelekileyo)Ngumgaqo olungiselelwe ngokukodwa ukusetyenziswa kwezakhono ezisezantsi.
- I-TOMP (iProtokholi yoLungiso loMyalezo oPhezulu)Inkqubo elula kakhulu kunye nokufezekisa ukusebenzisana okuphezulu. I-HTTP isetyenziselwa ukuhambisa imiyalezo ebhaliweyo.
- I-XMPP (iProtocol yeMiyalezo eXtensikayo kunye noBukho): enye iprotocol esetyenziswe kwi-IoT yokuthumela imiyalezo kwangoko kwaye isekwe kwiXML. UJan eli tyala nalo livulekile.
- I-WMQ (Umyalezo womyalezo weWebSphere)Umgaqo-nkqubo ophuhliswe yi-IBM. Luhlobo lomgca woMyalezo, njengoko igama lawo libonisa, kwaye ujolise kumyalezo.
- I-MQTT: (jonga icandelo elilandelayo)
Konke malunga neMQTT
El Inkqubo ye-MQTT Yinkqubo yomgaqo wonxibelelwano womgca, olandela ipateni yePubSub, kunye nohlobo lwe-M2M, njengoko senditshilo. Isetyenziswa ngokubanzi kwi-IoT, kwaye isekwe kwisitaki se-TCP / se-IP esisetyenziswa kwi-Intanethi.
Kwimeko ye-MQTT, lonke unxibelelwano lugcinwa luvulekile kwaye iphinda isetyenziswe kunxibelelwano ngalunye oluyimfuneko. Into eyahlukileyo kwinto eyenzekayo kwezinye iinkqubo ezaziwayo, ukuba unxibelelwano ngalunye lwenzeka lufuna unxibelelwano olutsha.
Inzuzo
Izibonelelo zenkqubo ye-MQTT zibonakala ngokucacileyo kunxibelelwano lwe-M2M ye-IoT. Ukongeza kuyo yonke into ekhankanywe apha ngasentla, yiprotocol ebonelela:
- Ukomelela, ukudibanisa abathengi abaninzi nangakumbi.
- Ukudibanisa phakathi kwabaxhasi, ukuxhomekeka kancinci.
- I-Asynchronism.
- Lula.
- Ukukhanya ukuze ungasebenzisi izixhobo ezininzi (nangona ukhuseleko lwe-TLS / SSL lunyuka).
- Amandla ombane asebenza kwizixhobo ezixhomekeke kwibhetri okanye ukusebenza kwi-24/7, ayifuni bandwidth enkulu (efanelekileyo kunxibelelwano olucothayo, njengaleyo engenazingcingo).
- Ukhuseleko kunye nomgangatho, ukuthembeka okukhulu kunye nokomelela kunxibelelwano.
Historia
I-MQTT yenziwe kwi-90s, kunye nohlobo lwangaphambili lwe umthetho olandelwayo ngo-1999. Yenziwe nguGqirha Andy Stanford-Clark we-IBM kunye no-Arlen Nipper we-Cirrus Link (eyayisakuba yi-Eurotech).
La uluvo lokuqala yayikukudala umthetho olandelwayo wokujonga umbhobho ohamba entlango, kunye nomgaqo-nkqubo wonxibelelwano osebenzayo (ukusetyenziswa kwebandwidth ephantsi), ukukhanya, kunye nokusetyenziswa kwamandla aphantsi. Ngelo xesha kwakubiza kakhulu, kodwa ngoku ibe yiprothokholi enexabiso eliphantsi kwaye ivulekile.
Iprotocol yokuqala yaphuculwa ngenkangeleko ye iinguqulelo ezintsha, njenge-MQTT v3.1 (2013) phantsi kwe-OASIS (Umbutho woPhuculo lweMigangatho yoLwazi oluCwangcisiweyo), njl. Kuya kufuneka uyazi ukuba ekuqaleni yayiyiprothokholi ye-IBM, kodwa ukuba yayiza kukhutshwa ngo-2010, kwaye yaphela yaba ngumgangatho kwi-OASIS ...
Indlela uqhagamshelo lwe-MQTT lusebenza ngayo
Inkqubo ye-MQTT isebenzisa Icebo lokucoca ulwelo, kwimiyalezo ethunyelwa kumthengi ngamnye, ngokusekelwe kwizihloko okanye izihloko ezicwangciswe ngokweziqendu. Ngale ndlela, umthengi unokuthumela umyalezo kwisihloko esithile. Ngale ndlela, bonke abaxhasi okanye izixhobo ezixhumeneyo ezibhalisela isihloko ziya kufumana imiyalezo ngomthengisi.
NjengeMQ, imiyalezo izakuhlala emgceni kwaye azilahlekanga de umthengi afumane loo myalezo.
Unxibelelwano, njengoko ndibonakalisile, lwenziwe ngeTCP / IP, kwaye umncedisi okanye umrhwebi uya kugcina irekhodi labaxhasi abaxhunyiwe. Ngokuzenzekelayo, izixhobo ziya kusebenzisa iinombolo zokunxibelelana ezingunombolo 1883, nangona ungadibana nezibuko 8883 ukuba usebenzisa i-SSL / TLS yokhuseleko olongeziweyo.
Ukuze unxibelelwano lube nokwenzeka, ayimfuneko kuphela kubaxhasi, iiseva kunye namazibuko. Kwakhona abanye iipakethe okanye imiyalezo ethunyelweyo ukuze unxibelelwano luqhubeke:
- Ukuseka uxhulumanisoQhagamshela umyalezo / ipakethi ethunyelwe ngumthengi ngalo lonke ulwazi oluyimfuneko. Olu lwazi lubandakanya i-ID yomthengi, igama lomsebenzisi, ipassword, njl. Umrhwebi okanye umncedisi uphendula ngepakethi yeCONNACK eya kuthi yazise umxhasi ukuba unxibelelwano lwamkelwe, lwaliwe, njl.
- Thumela kwaye ufumane imiyalezo: Xa uxhulumaniso lusekiwe, PAPasha iipakethi okanye imiyalezo esetyenzisiweyo nesihloko kunye nomthwalo wokuhlawulwa komyalezo othunyelwe kumrhwebi. Kwelinye icala, abaxhasi abanomdla okanye abathengi basebenzisa i-SUBSCRIBE kunye ne-UNSUSCRIBE iiphakheji ukuze babhalise okanye barhoxise umrhumo wabo ngokwahlukeneyo. Umrhwebi uya kuphendula kwakhona nge-SUBACK kunye ne-UNSUBACK package ngokwahlukeneyo ukunika ingxelo ngempumelelo yomsebenzi ocelwe ngumthengi.
- Ukugcina unxibelelwano: Ukuqinisekisa ukuba unxibelelwano luhlala luvulekile, abathengi banokuthumela ipakethi ye-PINGREQ ngamaxesha athile eya kuthelekiswa nepakethi ye-PINGRESP esuka kwiseva.
- Phelisa unxibelelwano: xa umthengi ekhupha unxibelelwano, uthumela i-DISCONNECT packet ukunika ingxelo ngalo msitho.
Abo imiyalezo okanye iipakethe Ezi ndithethe ngazo zinesakhiwo esifanayo nezinye iipakethi zezinye iinkqubo zomnatha:
- Okubhalwe ngasentla okanye okubhalwe ngasentla: yinxalenye emiselweyo ehlala phakathi kwee-byte ezi-2-5. Inekhowudi yolawulo, i-ID yohlobo lomyalezo othunyelweyo, kunye nobude bayo. Phakathi kwe-1-4 i-byte isetyenziselwa ukufaka ubude, kusetyenziswa ii-bits zokuqala eziyi-7 ze-octet nganye njengedatha yobude kunye nokuqhubeka kokujonga ukuba kukho ngaphezulu kwe-byte enye eyenza ubude bomyalezo.
- Intloko eguqukayo: akusoloko kunyanzelekile, kodwa kuyanyanzeleka. Iqulethwe kuphela kwezinye iipakeji kwiimeko ezithile okanye imiyalezo ethile.
- Umxholo okanye idatha: ipakethe yedatha yeyona nto iqulethe umyalezo oza kuthunyelwa. Inokuba isuka kwi-kB embalwa ukuya kuthi ga kwi-256 MB umda.
Ukuba unomdla wokwazi ikhowudi ehambelanayo kwihexadecimal zeentlobo zemiyalezo ethunyelweyo zezi:
Mensaje | Ikhowudi |
---|---|
QHUBA | 0x10 |
BUYELA | 0x20 |
PAPASHA | 0x30 |
IPUBACK | 0x40 |
IPHEPHA | 0x50 |
PUBREL | 0x60 |
I-PUBCOMP | 0x70 |
BHALISA | 0x80 |
UMBUZO | 0x90 |
ZINGABHALI | 0xA0 |
UKUKHUMBULA | 0xB0 |
IPINGREQ | 0xC = |
PINGRESP | 0xD0 |
UKUQINISWA | 0xE0 |
Umgangatho nokhuseleko lonxibelelwano
Enye inkcukacha ebalulekileyo yemiyalezo ye-MQTT yile umgangatho wenkonzo okanye iQoS, kunye nokhuseleko. Ukuqina kwenkqubo yonxibelelwano kwimeko yokusilela kunye nokukhuseleka kwayo kuya kuxhomekeka koku.
Ngokumalunga nomgangatho wayo, inokumiselwa Amanqanaba ahlukeneyo angama-3:
- I-QoS 0 (ukungazi)-Umyalezo uthunyelwa kube kanye, kwaye kwimeko yokusilela awuzukuhanjiswa. Isetyenziswa xa ingabalulekanga.
- I-QoS 1 (yazisa): umyalezo uya kuthunyelwa amaxesha ngamaxesha njengoko kufuneka ukuqinisekisa ukuhanjiswa kumthengi. Icala elisezantsi kukuba umthengi unokufumana umyalezo ofanayo amatyeli aliqela.
- I-QoS 2 (iqinisekisiwe)-Yafana nale ingasentla, kodwa iqinisekisiwe ukuhanjiswa kube kanye kuphela. Ihlala isetyenziselwa iinkqubo ezibaluleke ngakumbi apho kufuneka ukuthembeka okukhulu.
Kwelinye icala, njenge Ukhuseleko lweMQTT, amanyathelo ahlukeneyo anokusetyenziswa ukuqinisekisa ukomelela kwalo mba. Njengoko sele nditshilo ngaphambili, ukungqinwa kwegama lomsebenzisi kunye negama eligqithisiweyo, njengezinye iinkqubo ezininzi, kunokuqinisekiswa kusetyenziswa i-SSL / TLS. Nangona izixhobo ezininzi ze-IoT ezinamandla aphantsi, okanye oovimba, zinokuba neengxaki zomsebenzi omninzi xa usebenzisa olu hlobo lonxibelelwano olukhuselekileyo ...
Ngesi sizathu, izixhobo ezininzi ze-IoT ezisebenzisa i-MQTT zisebenzisa iipassword kunye nabasebenzisi kwi itekisi yombhalo, ezinokuthi zenze umntu ahogele ukugcwala kwenethiwekhi ukuze azifumane ngokulula. Kwaye ukuba ayonelanga, umrhwebi unokuqwalaselwa ukuba amkele unxibelelwano olungaziwayo, oluya kuvumela nawuphi na umsebenzisi ukuba aseke unxibelelwano, kubandakanya umngcipheko omkhulu.
Sebenzisa iMQTT ngeArduino
Ewe unako Sebenzisa umthetho olandelwayo we-MQTT kunye neArduino kunye nezinye iibhodi zophuhliso, kunye neRapsberry Pi, njl. Ukwenza oku, kuya kufuneka unikeze ibhodi yakho yeArduino ngokudibanisa, ukuba ayinayo. Kwakhona, ithala leencwadi Umthengi waseArduino weMQTT izokukunceda kule misebenzi. Eli thala lencwadi liyahambelana:
- ArduinoYUN
- IArduino WiFi (ikhaka)
- IArduino Ethernet (ikhaka)
- Imodyuli ye-ESP8266
- I-Intel Galileo / Edison
- Raspberry Pi
- ...
Ngokukhawuleza ndi Kwikhowudi yokusebenzisa iMQTT kolunye usetyenziso, inyani kukuba ilula. Kumfanekiso kaFritzing ungabona ipleyiti Arduino UNO kudityaniswe kuyo ngo-Arduino Ethernet kwaye ikwadityanisiwe Ukufuma DHT22 ukufuma kunye nobushushu isivamvo, nangona ibinokuba yenye into ...
Kulungile, ngoku uthethile, ngekhowudi ekufuneka uyingenisile I-Arduino IDE Ukusebenza ngomgaqo olandelwayo we-MQTT kwiArduino, ilula nje:
- ukuba thumela imiyalezo I-MQTT
#include <SPI.h> #include <Ethernet.h> #include <PubSubClient.h> #include <DHT.h> #define DHTPIN 2 #define DHTTYPE DHT22 // Direccion MAC del adaptador Ethernet byte mac[] = { 0xCE, 0xAB, 0x0E, 0x3F, 0xFE, 0xD4 }; // IP del servidor (broker) IPAddress mqtt_server(192, 168, 1, 4); // Topic o tema con el que se trabaja const char* topicName = "test"; DHT dht(DHTPIN, DHTTYPE); EthernetClient ethClient; PubSubClient client(ethClient); void setup() { Serial.begin(9600); if (Ethernet.begin(mac) == 0) { Serial.println("Fallo en Ethernet usando DHCP"); } // Puerto 1883 de comunicación client.setServer(mqtt_server, 1883); dht.begin(); } void loop() { if (!client.connected()) { Serial.print("Conectando ...\n"); client.connect("Cliente Arduino"); } else { // Envío de informacion del sensor de temperatura y humedad float temp = dht.readTemperature(); char buffer[10]; dtostrf(temp,0, 0, buffer); client.publish(topicName, buffer); } // Tiempo entre envíos en ms (cada 10 segundos) delay(10000); }
- ukuba fumana imiyalezo yi MQTT ufuna ipleyiti kuphela Arduino UNO kunye nonxibelelwano, kunye neArduino Ethernet okanye nayiphi na into. Ngokuphathelele ikhowudi, umzekelo uya kuba:
#include <SPI.h> #include <Ethernet.h> #include <PubSubClient.h> // Direccion MAC del adaptador Ethernet byte mac[] = { 0xCE, 0xAB, 0x0E, 0x3F, 0xFE, 0xD4 }; // IP del servidor (broker) IPAddress mqtt_server(192, 168, 1, 4); // Topic o tema con el que trabajr const char* topicName = "test"; EthernetClient ethClient; PubSubClient client(ethClient); void callback(char* topic, byte* payload, unsigned int length) { Serial.print("El mensaje ha llegado ["); Serial.print(topic); Serial.print("] "); int i=0; for (i=0;i<length;i++) { Serial.print((char)payload[i]); } Serial.println(); } void setup() { Serial.begin(9600); if (Ethernet.begin(mac) == 0) { Serial.println("Fallo en Ethernet al usar configuración DHCP"); } client.setServer(mqtt_server, 1883); client.setCallback(callback) } void loop() { if (!client.connected()) { Serial.print("Conectando ..."); if (client.connect("rece_arduino")) { Serial.println("conectado"); client.subscribe(topicName); } else { delay(10000); } } // Cliente a la escucha client.loop(); }
Ngolwazi oluthe kratya, unako Khuphela simahla zethu Incwadana yePDF kunye nekhosi ye-Arduino IDE yokuqalisa inkqubo.