Cov txheej txheem:

Yuav Ua Li Cas Tswj ESP8266 Raws Li Sonoff Basic Hloov Hloov Nrog Lub Xov Tooj: 4 Cov Kauj Ruam (nrog Duab)
Yuav Ua Li Cas Tswj ESP8266 Raws Li Sonoff Basic Hloov Hloov Nrog Lub Xov Tooj: 4 Cov Kauj Ruam (nrog Duab)

Video: Yuav Ua Li Cas Tswj ESP8266 Raws Li Sonoff Basic Hloov Hloov Nrog Lub Xov Tooj: 4 Cov Kauj Ruam (nrog Duab)

Video: Yuav Ua Li Cas Tswj ESP8266 Raws Li Sonoff Basic Hloov Hloov Nrog Lub Xov Tooj: 4 Cov Kauj Ruam (nrog Duab)
Video: How I Made this Electric Car that can go Anywhere 2024, Kaum ib hlis
Anonim
Yuav Ua Li Cas Tswj ESP8266 Raws Li Sonoff Basic Smart Hloov Nrog Smartphone
Yuav Ua Li Cas Tswj ESP8266 Raws Li Sonoff Basic Smart Hloov Nrog Smartphone

Sonoff yog kab kab rau Smart Home tsim los ntawm ITEAD. Ib qho ntawm cov khoom siv hloov pauv tau thiab pheej yig tshaj plaws los ntawm kab ntawd yog Sonoff Basic. Nws yog Wi-nkaus qhib kev hloov pauv raws li lub nti zoo, ESP8266. Kab lus no piav qhia yuav teeb tsa Cloud4RPi kev pabcuam ntawm Sonoff Basic ntse hloov.

Hauv cov lus qhia yav dhau los, peb tau piav qhia yuav ua li cas nyem lub MicroPythonfirmware tshiab ntawm Sonoff Basic lossis Sonoff Dual ntse hloov. Hauv kab lus no, peb tab tom yuav rov kho ib feem ntawm thawj qhov Sonoff-ua haujlwm siv Cloud4RPi.

Kauj Ruam 1: Txuas Ntawm WebREPL

Txuas ntawm WebREPL
Txuas ntawm WebREPL

Ua ntej peb nkag mus rau Python REPL interface ntawm UART raws tu qauv. Txij li ESP8266 yog Wi-nkaus module, peb tuaj yeem sib tham nrog nws wirelessly. Tig koj lub Rooj Tswjhwm Saib MicroPython-qhib rau, nkag mus rau nws kab hais kom ua thiab nkag mus rau cov lus txib hauv qab no kom pab tau WebREPL:

>> ntshuam webrepl_setup

Cov lus txib no pib tus txheej txheem teeb tsa qhov twg koj tuaj yeem teeb tsa WebREPL pib-pib, teeb tus password, thiab rov pib dua thaum ua tiav.

Tom qab rov pib dua, txuas rau koj li Wi-nkaus network los ntawm kev ua cov lus txib hauv qab no (hloov Wi-Fi teeb tsa nrog koj cov ntaub ntawv):

>> los ntawm network ntshuam WLAN

>> STA = WLAN (0); STA.active (1) >>> STA.connect ('_ YOUR_WIFI_NETWORK_NAME_', '_PASSWORD_') >>> STA.ifconfig ()

Tos ob peb feeb thiab tshawb xyuas STA.isconnected () cov zis. Yog tias nws tso tawm qhov tsis raug, rov txheeb xyuas Wi-Fi daim ntawv pov thawj, rov txuas dua, thiab txheeb xyuas tias STA.isconnected () tso tawm qhov tseeb. Txhawm rau kom tau ESP8266 tus IP chaw nyob hauv koj lub network, ua raws cov lus txib hauv qab no.

>> STA.ifconfig () [0]

'192.168.1.108'

Tam sim no koj tuaj yeem txuas rau ESP8266 ntawm WebREPL (rub tawm daim ntawv HTML no thiab qhib nws nrog koj tus browser).

Ntawm sab xis ntawm WebREPL interface, koj tuaj yeem pom cov ntaub ntawv-tus thawj tswj haujlwm tso cai rau koj rub tawm thiab rub tawm cov cai cov ntaub ntawv rau ESP8266's virtual file system.

Kauj ruam 2: Txuas rau Cloud4RPi

Txuas mus rau Cloud4RPi
Txuas mus rau Cloud4RPi

Rub tawm cov ntawv xav tau rau koj lub khoos phis tawj:

  • simple.py: MQTT Library rau MicroPython. Txuag cov ntawv no ua mqtt.py thaum rub tawm.
  • cloud4rpi.py: Cloud4RPi cov tsev qiv ntawv rau MicroPython.
  • main.py: Qauv code.

Qhib cov ntawv tseem ceeb.py hauv kab ntawv sau (piv txwv li, Visual Studio Code) thiab hloov cov kab hauv qab no:

  • _SSID_ nrog koj lub npe Wi-nkaus network.
  • _PWD_ nrog koj tus password Wi-nkaus network. Yog tias koj muaj lub network qhib, tshem tawm '_PWD_' lub ntsiab lus yam tsis tau tshem tus lej tom qab kom lub WIFI_SSID_PASSWORD sib txawv ua tus tuple nrog ib lub ntsiab lus.
  • _YOUR_DEVICE_TOKEN_ nrog cov cim qhia pom nyob rau sab saum toj ntawm nplooj ntawv ntaus ntawv ntawm cloud4rpi.io. Yog tias koj tsis muaj tus cim, qhib Devices nplooj ntawv, tsim lub cuab yeej siv lub Tshuab Ntaus Tshiab nyob rau sab xis saum toj, thiab siv nws cov cim.
  • Hloov LED_PIN rau 13 thiab BUTTON_PIN rau 0.

Txuag cov ntaub ntawv main.py thiab xa cov mqtt.py, cloud4rpi.py thiab main.py cov ntaub ntawv rau koj ESP8266 ntawm WebREPL txoj cai sab xis.

Koj tuaj yeem siv cov kab hais kom ua kab ntawv uploader xa nrog WebREPL txhawm rau rub cov ntawv.

Pib dua ESP8266. Koj tuaj yeem siv lub console rau qhov no:

>> import tshuab

>> machine.reset ()

Cov ntaub ntawv npe main.py tau pib txiav ntawm khau raj.

Yog tias txhua yam mus zoo, koj tuaj yeem pom lub cuab yeej nyob ntawm Cloud4RPi ntaus ntawv nplooj ntawv.

Kauj Ruam 3: Teeb Chaw Tswj Vaj Huam Sib Luag

Mus rau ntawm Control Panels nplooj ntawv thiab ntxiv cov tswj hwm vaj huam sib luag tshiab thiab ntxiv Cov Hloov widget thiab khi nws mus rau qhov sib txawv ntawm LED.

Siv LED hloov pauv ntawm lub vaj huam sib luag tswj kom tig Sonoff LED rau.

Ntxiv Cov Ntawv Text thiab khi nws rau khawm sib txawv. Kho cov xim sib txawv rau cov hlua "tseeb" thiab "tsis tseeb". Tam sim no koj tuaj yeem nias lub khawm khoos phis tawj thiab pom tias cov widget hloov pauv li cas.

Koj tuaj yeem tswj hwm Sonoff Basic relays los ntawm kev ntxiv qhov hloov pauv tshiab tau khi rau kho vajtse tus pin 12.

relay_pin = Pin (12, Pin. OUT)

def on_relay (tus nqi): relay_pin.value (tus nqi) rov relay_pin.value () #… device.declare ({'Relay': {'hom': 'bool', 'value': Tsis tseeb, 'khi': on_relay}, #…})

Kauj Ruam 4: Qhov Kawg

Peb tau txuas qhov txuas mus rau peb lub teeb duab, saib cov vis dis aus uas peb sim nws.

Pom zoo: