Cov txheej txheem:

MQTT Raws li MicroPython ESP32: 5 Cov Kauj Ruam
MQTT Raws li MicroPython ESP32: 5 Cov Kauj Ruam

Video: MQTT Raws li MicroPython ESP32: 5 Cov Kauj Ruam

Video: MQTT Raws li MicroPython ESP32: 5 Cov Kauj Ruam
Video: MicroPython - MQTT tutorial on ESP32 2024, Hlis ntuj nqeg
Anonim
MQTT Raws li MicroPython ESP32
MQTT Raws li MicroPython ESP32
MQTT Raws li MicroPython ESP32
MQTT Raws li MicroPython ESP32

Kuv nyiam khaws cov miv miv. Tom qab ib hnub ntawm kev ua haujlwm hnyav, miv tuaj yeem so kuv thaum kuv mus txog tsev. Tom qab kev qhia nyuaj, tus miv no muaj tus cwj pwm zoo ntawm kev noj zaub mov tsis tu ncua hauv "tsev noj mov" txhua hnub. Tab sis tsis ntev los no kuv yuav tsum tau mus ob peb hnub thiab tsis muaj leej twg saib xyuas miv hauv tsev, yog li kuv xav siv MQTT rau kev tswj chaw taws teeb pub mis. Yog tias miv tau noj, qhov no tuaj yeem ua rau kuv nco thiab cia kuv tso siab rau

MQTT

MQTT yog tus neeg siv khoom-server raws cov lus tshaj tawm / sau npe yuav hloov pauv raws tu qauv. MQTT raws tu qauv yog qhov hnyav, yooj yim, qhib, thiab yooj yim rau siv, thiab cov yam ntxwv no ua rau nws siv tau dav.

Tshaj tawm thiab sau npe yuav

MQTT raws tu qauv txhais ob hom kev sib koom hauv lub network: tus tshaj tawm xov xwm thiab qee tus neeg siv khoom. Tus neeg sawv cev yog tus neeg rau zaub mov uas tau txais tag nrho cov lus los ntawm tus neeg siv khoom thiab tom qab ntawd xa cov lus no mus rau cov neeg siv khoom sib xws. Tus neeg siv khoom yog txhua yam uas tuaj yeem cuam tshuam nrog tus neeg sawv cev xa thiab tau txais cov lus. Tus neeg siv khoom tuaj yeem yog tus nyob ntawm qhov chaw IoT sensor lossis daim ntawv thov uas ua cov txheej txheem IoT hauv cov ntaub ntawv chaw.

Kauj Ruam 1: Cov khoom siv

Khoom siv
Khoom siv

Kho vajtse:

MakePython ESP32 Cov

MakePython ESP32 yog ESP32 pawg thawj coj nrog kev sib xyaw SSD1306 OLED zaub.

servo tsav

HC-SR04

Software:

uPyCraft IDE

Nyem rub tawm uPyCraft IDE rau Windows

Kauj ruam 2: Kev thaiv kab

Thaiv
Thaiv

MakePython ESP32 - Servo

  • 3V3 - VCC (kab liab)
  • GND - GND (kab xim av)
  • IO14 - Teeb liab (kab kab kab)

MakePython ESP32-HC-SR04

  • 3V3 - VCC
  • IO13 - Tus lej
  • IO12 - Echo
  • GND - NCO

Kauj ruam 3: Code

Rub tawm thiab khiav cov cai tau muab ntawm no.

Ua cov kev hloov hauv qab no rau cov ntaub ntawv main.py, tom qab ntawd txuag thiab khiav.

Hloov kho SSID thiab PSW txhawm rau txuas WiFi

SSID = 'Makerfabs' #REPLACE_WITH_YOUR_SSID

PSW = '20160704' #REPLACE_WITH_YOUR_PASSWORD

Hloov kho tus IP ntawm koj tus broker MQTT thiab txiav txim siab cov ncauj lus rau kev tshaj tawm thiab kev tso npe

mqtt_server = '39.106.151.85 '#REPLACE_WITH_YOUR_MQTT_BROKER_IP

topic_sub = b'feed 'topic_pub = b'state'

Txuas thiab sau npe yuav cov ncauj lus

def txuas_and_subscribe ():

global client_id, mqtt_server, topic_sub client = MQTTClient (client_id, mqtt_server) client.set_callback (sub_cb) client.connect () client.subscribe (topic_sub) print ('Txuas rau %s MQTT broker, subscribed rau %s topic' %(mqtt_s, topic_sub)) rov qab cov neeg siv khoom

tshaj tawm cov lus

client = txuas_and_subscribe ()

client.publish (topic_pub, msg)

Kauj ruam 4: MQTT Chaw

MQTT Chaw
MQTT Chaw
MQTT Chaw
MQTT Chaw

Koj tuaj yeem rub tawm thiab teeb tsa MQTT tus neeg siv khoom ntawm no, tso cai rau koj los tswj chaw taws teeb ntawm koj lub xov tooj ntawm tes lossis khoos phis tawj.

  • Qhib thiab nyem rau Tsim MQTT Client
  • Lub npe input pub
  • Cov txheej txheem xaiv mqtt / tcp
  • Tswv yim tswv yim: 39.106.151.85:1883
  • Nyem tseg

Kauj Ruam 5: Tshaj tawm thiab Sau Npe

Tshaj tawm thiab Sau Npe
Tshaj tawm thiab Sau Npe
Tshaj tawm thiab Sau Npe
Tshaj tawm thiab Sau Npe

Tom qab txuas, cov ncauj lus los tshaj tawm cov tswv yim: pub. Cov nyiaj them poob haujlwm: nyob rau, thiab tom qab ntawd nyem tshaj tawm

Lub cav servo tig thiab pib pub mis.

Cov ncauj lus kom sau npe nkag lub xeev, thiab tom qab ntawd nyem rau npe

Thaum tus miv nyob ze tus neeg pub zaub mov noj, cov npe teev npe tau txais: miv tau noj …, miv tau txais tom qab tawm mus: Tus miv tawm mus.

Txawm hais tias koj tso tus miv tom tsev, koj tsis tas yuav txhawj xeeb tias nws tshaib plab.

Pom zoo: