Cov txheej txheem:

Yuav ua li cas nyem MicroPython Firmware ntawm ESP8266 Raws li Sonoff Ntse Hloov: 3 Cov Kauj Ruam (nrog Duab)
Yuav ua li cas nyem MicroPython Firmware ntawm ESP8266 Raws li Sonoff Ntse Hloov: 3 Cov Kauj Ruam (nrog Duab)

Video: Yuav ua li cas nyem MicroPython Firmware ntawm ESP8266 Raws li Sonoff Ntse Hloov: 3 Cov Kauj Ruam (nrog Duab)

Video: Yuav ua li cas nyem MicroPython Firmware ntawm ESP8266 Raws li Sonoff Ntse Hloov: 3 Cov Kauj Ruam (nrog Duab)
Video: Golang vs Python #shorts tiktok hackmymozg 2024, Kaum ib hlis
Anonim
Yuav ua li cas nyem MicroPython Firmware ntawm ESP8266 Raws li Sonoff Ntse Hloov
Yuav ua li cas nyem MicroPython Firmware ntawm ESP8266 Raws li Sonoff Ntse Hloov

Sonoff yog dab tsi?

Sonoff yog kab kab rau Smart Home tsim los ntawm ITEAD. Ib qho ntawm cov khoom siv hloov pauv tau tshaj plaws thiab pheej yig los ntawm kab ntawd yog Sonoff Basic thiab Sonoff Dual. Cov no yog Wi-nkaus qhib kev hloov pauv raws li lub nti zoo, ESP8266. Thaum Sonoff cov tsev tsim khoom yuav ua haujlwm tau zoo rau cov neeg siv yooj yim, lwm tus tuaj yeem xav hack rau hauv kho vajtse ntawd thiab khiav lawv tus kheej cov cai ntawm nws. Kho vajtse ntawm Sonoff Ntse Hloov yog qhov xav tsis thoob, txiav txim siab nws tus nqi qis:

  • ESP8266 nrog 1MB nyem
  • 220V AC integrated power adapter
  • 10A Relay (lossis ob qho hauv Sonoff Dual)
  • Onboard LED (lossis ob qho hauv Sonoff Dual)
  • Onboard khawm

Yog tias koj xav tswj hwm tag nrho cov khoom siv no uas koj nyiam cov lus programming, cov ntawv qhia no yog rau koj.

Kauj ruam 1: Hacking Hardware

Hacking Hardware
Hacking Hardware
Hacking Hardware
Hacking Hardware
Hacking Hardware
Hacking Hardware

ESP8266 yog programmed ntawm qhov chaw nres nkoj txuas. Ob qho Sonoff Basic thiab Sonoff Dual muaj nws ntawm PCD.

Tej zaum koj yuav xav tau muab tus pin txuas rau ntawm PCB kom txuas tau yooj yim USB-UART adapter.

Kauj ruam 2: Npaj rau Hacking Software

Npaj rau Hacking Software
Npaj rau Hacking Software

Kuv nyiam Python, yog li kuv yuav siv MicroPython firmware. Koj kuj tseem tuaj yeem siv ib qho SDK txhawb. Cia peb pib ua kom pom MicroPython hloov chaw ntawm Sonoff firmware uas yog tus tswv:

Nruab qhov esptool python pob uas ua rau pom qhov ESP8266 yooj yim dua:

pip nruab esptool

Rub tawm qhov tseeb ruaj khov MicroPython firmware los ntawm MicroPython rub tawm nplooj ntawv. Txuas lub USB-UART adapter rau lub rooj tsavxwm. Rau kev nyab xeeb, nws tau pom zoo kom siv lub rooj tsavxwm los ntawm lub adapter hloov ntawm 220V AC lub qhov (socket). Nco tseg tias koj tsuas yog siv 3.3V, yog tias koj txuas ESP8266 nti mus rau 5V lub zog siv, nws yuav tuag.

Khau ESP8266 rau hauv Flash hom. Koj tuaj yeem ua nws los ntawm rub tus GPIO0 tus pin thaum txhawb lub cuab yeej ntawm:

  • Ntawm Sonoff Basic, GPIO0 tsuas yog khawm xwb. Txuas lub USB-UART adapter rau koj lub PC thaum tuav lub pob thiab koj nyob hauv Hom Flash.
  • Ntawm Sonoff Dual, txhua yam nyuaj me ntsis. Koj yuav tsum tau luv Circuit Court ob daim pawm ntawm PCB thaum ua lub rooj tsavxwm. Cov ntaub qhwv uas xav tau muaj nyob ntawm daim duab saum toj no. Siv tus tweezers lossis xaim hlua xaim me me ntawm lawv.

Thaum ESP8266 nyob hauv Hom Flash, lub rooj tsavxwm LED yuav tsum tsis txhob nyem.

Nco ntsoov tias koj tuaj yeem nkag mus rau qhov chaw nres nkoj txuas tau qhib los ntawm USB-UART adapter. Ntawm Linux nws yuav yog / dev / ttyUSB0, ntawm Mac koj yuav tsum tshawb nrhiav qee yam xws li "usbserial" lossis "usbmodem" hauv ls / dev / cu.* Lossis ls / dev / tty.* Hais kom ua tawm, ntawm Windows nws yuav tsum yog COM3 lossis siab dua. Nruab USB-UART adapter tsav tsheb yog tias tsim nyog.

Lwv lub flash siv lub esptool. Hloov qhov /dev /ttyUSB0 rau koj qhov chaw nres nkoj yog tias xav tau:

esptool.py --port /dev /ttyUSB0 lwv_flash

Tej zaum koj yuav tsum tau khiav esptool.py ua tus superuser nkag mus rau qhov chaw nres nkoj txuas.

Kauj ruam 3: Flashing

Flashing
Flashing

Yog tias kev tshem tawm tau ua tiav, txiav lub rooj tsav xwm lub zog, khau raj ESP8266 hauv Flash hom dua, thiab nyem koj lub firmware:

esptool.py --port /dev /ttyUSB0 --baud 460800 write_flash --flash_size = ntes 0 esp8266-20170823-v1.9.2.bin

Yog tias qhov ua tiav tau ua tiav, txiav lub rooj tsav xwm lub zog, txuas nws dua yam tsis tau nyem lub pob, thiab qhib qhov chaw nres nkoj hauv lub davhlau ya nyob twg. Ntawm Linux thiab Mac koj tuaj yeem siv tshuaj ntsuam /dev /ttyUSB0 115200 (hloov /dev /ttyUSB0 rau koj qhov chaw nres nkoj yog tias xav tau), ntawm Windows koj tuaj yeem siv PuTTY (tus nqi baud default yog 115200). Thaum koj txuas, nyem Enter, thiab yog tias koj pom peb lub kaum sab xis ntawm Python plhaub, dua li txhua yam ua haujlwm!

>> >>> pab () Txais tos rau MicroPython! Rau cov ntawv online thov mus ntsib https://docs.micropython.org/en/latest/esp8266/. Rau kev txheeb xyuas cov ntaub ntawv suav nrog hauv kab lus ceeb toom ua 'import port_diag'. Kev teeb tsa WiFi yooj yim: ntshuam network sta_if = network. WLAN (network. STA_IF); sta_if.active (True) sta_if.scan () # Tshawb nrhiav kom muaj cov ntsiab lus nkag tau sta_if.connect ("", "") # Txuas mus rau AP sta_if.isconnected () # Txheeb xyuas kom muaj kev sib txuas tau zoo # Hloov lub npe/tus password ntawm ESP8266's AP: ap_if = network. WLAN (network. AP_IF) ap_if.config (essid = "", authmode = network. AUTH_WPA_WPA2_PSK, password = "") Tswj cov lus txib: CTRL-A-ntawm kab dawb, nkag mus rau hom REPL nyoos CTRL- B-ntawm kab dawb paug, nkag mus rau ib txwm REPL hom CTRL-C-cuam tshuam txoj haujlwm khiav haujlwm CTRL-D-ntawm kab dawb paug, rov kho qhov muag ntawm lub rooj tsavxwm CTRL-E-ntawm kab dawb, nkag mus hom Txhawm rau pab ntxiv rau ntawm yam khoom tshwj xeeb, ntaus ntawv pab (obj) >>>

Hauv cov lus qhia tom ntej, peb yuav piav qhia yuav ua li cas cuam tshuam nrog Cloud4RPi platform ntawm MQTT raws tu qauv.

Pom zoo: