Cov txheej txheem:

Khawm Qhov Rooj Virtual Siv Mongoose OS thiab XinaBox: 10 Kauj Ruam
Khawm Qhov Rooj Virtual Siv Mongoose OS thiab XinaBox: 10 Kauj Ruam

Video: Khawm Qhov Rooj Virtual Siv Mongoose OS thiab XinaBox: 10 Kauj Ruam

Video: Khawm Qhov Rooj Virtual Siv Mongoose OS thiab XinaBox: 10 Kauj Ruam
Video: 🔴 TOP WORLD NEWS REVIEW 🛑TUS HLUB ONLINE = DAG 💥08/11/2021👏 2024, Kaum ib hlis
Anonim
Khawm Qhov Rooj Virtual Siv Mongoose OS thiab XinaBox
Khawm Qhov Rooj Virtual Siv Mongoose OS thiab XinaBox

Siv Mongoose thiab qee qhov xChips, peb tau ua lub pob qhov rooj virtual. Hloov chaw ntawm lub cev khawm kom nrov cov neeg ua haujlwm hauv, tam sim no lawv tuaj yeem ua lawv tus kheej.

Kauj Ruam 1: Yam Khoom Siv Hauv Txoj Haujlwm no

Cov khoom siv kho vajtse

  • XinaBox CW02 x 1 Koj tuaj yeem siv CW01 hloov chaw
  • XinaBox IP01 x 1
  • XinaBox PU01 x 1 Koj tsuas tuaj yeem siv IP01 rau lub zog, yog tias koj tsis npaj siab yuav tsim cov qauv ntau dua.
  • XinaBox OC03 x 1
  • XinaBox XC10 x 1 Qhov "kua nplaum" uas ua rau nws ua haujlwm tag nrho!

Software apps thiab cov kev pabcuam online

Mongoose OS Yeej txaus thiab yooj yim IoT cov cuab yeej txhim kho… thiab pub dawb

Kauj ruam 2: Zaj dab neeg

Hauv peb qhov kev txais tos peb cov neeg ua haujlwm yuav tsum tau nrov nrov, yog li peb txiav txim siab noj peb tus kheej cov tshuaj thiab tsim lub pob virtual. Qhov chaws no tso cai rau koj xa RPC (Cov Txheej Txheem Hu Xov Tooj Nyob deb), uas zoo li ib txwm siv HTTP hu los ntawm txhua lub browser. Peb siv Mongoose, vim nws yooj yim heev thiab nrawm rau ua haujlwm nrog thiab nws tau tsim-hauv OTA (Tshaj Tawm Huab Cua) hloov kho cov cai, txhais tau tias peb tuaj yeem teeb tsa peb cov thev naus laus zis thiab tseem dhau sijhawm hloov kho lub firmware, yam tsis tawg nws rau kev rov ua dua tshiab.

Kauj ruam 3: Kev npaj

  • Nruab Mongoose-OS: Ncaj nraim rau tom ntej, tsuas yog ua raws cov kauj ruam yooj yim no rau koj OS ntawm no:
  • Nyem IP01 thiab CW02 ua ke siv XC10 txuas. Saib duab hauv qab no:
Duab
Duab
  • Ntxig tus IP01 rau hauv koj lub USB chaw nres nkoj
  • Nco ntsoov tias IP01 hloov pauv nyob hauv txoj haujlwm B thiab DCE.
  • Nyem Mongoose-OS rau CW02 los ntawm koj kab hais kom ua. Zoo li no:

ua cd

export MOS_PORT = bin/mos flash esp32

Koj tuaj yeem tsuas yog nkag mus rau lub console thiab ua feem ntau los ntawm qhov ntawd, tab sis ntawm no peb ua los ntawm kab hais kom ua, yog li txoj haujlwm tau ua tiav sai. Txhawm rau nkag mus rau console:

ua cd

bin/mos

Kauj ruam 4: Kev teeb tsa

Thaum cov theem no tuaj yeem ua tiav hauv ib nqe lus ntev, peb tau txiav txim siab faib lawv, thiab txij li koj yuav theej thiab muab tshuaj txhuam rau lawv ib qho twg, cia ua kom yooj yim:

Teeb I2C tus pin rau tus qauv xChips:

bin/mos config-set i2c.scl_gpio = 14 i2c.sda_gpio = 2

Txuas koj CW02 rau koj li WiFi:

bin/mos wifi

Tshem tawm WiFi hauv AP hom thiab teeb lub npe sau npe, yog li koj tuaj yeem txuas rau CW01 los ntawm lub npe hostname tsis txhob nrhiav qhov chaw nyob IP raug. Qhov no yuav ua haujlwm tsuas yog:

  • Koj tsis txuas WiFi hauv AP hom li peb ua hauv qab no.
  • Xwb siv Mac lossis nruab Bonjour ntawm koj lub tshuab Windows.

bin/mos hu rau Config. Set '{"config": {"wifi": {"ap": {"pab": tsis tseeb}}}}

bin/mos hu rau Config. Set '{"config": {"dns_sd": {"enable": true}}}' bin/mos hu Config. Set '{"config": {"dns_sd": {"host- lub npe ":" xinabox_switch "}}}

Thiab thaum kawg koj yuav tsum rov pib dua CW02 txhawm rau txhawm rau teeb tsa ua haujlwm

bin/mos hu rau Config. Save '{"reboot": tseeb}'

Sai sai tom qab qhov no koj yuav tsum tuaj yeem ping xinabox_switch.local

Kauj ruam 5: Txhim kho

Tshem lub IP01 ntawm koj lub khoos phis tawj thiab sib sau ua ke raws li cov duab saum toj kawg nkaus.

Txuas lub PU01 (lossis yog tias koj txiav txim siab lo nrog IP01) rau hauv USB lub zog siv. Txuas cov xov hluav taws xob sib txuas los ntawm koj qhov kev hloov pauv tam sim no (tawm qhov ntawd, tsuas yog hauv rooj plaub) mus rau OC03 (qhov tsis sib xws tsis muaj teeb meem). Saib Fritzing daim duab.

Thaum muaj zog thiab pom tias koj tab tom tham nrog koj tus xCW02, ua li cas txog kev txheeb xyuas lub npav, aka lub tsheb npav I2C:

bin/mos --port ws: //xinabox_switch.local/rpc hu I2C. Scan

Yog tias txhua yam ua haujlwm thiab koj xOC03 tau teeb tsa raug, koj yuav tsum pom tus lej '56' raug xa rov qab. Ntawd yog I2C chaw nyob ntawm OC03 hauv zauv (hauv hex nws yog 0x38).

Kauj ruam 6: Programming

  • Tam sim no qhib Mongoose hauv hom console, saib saum toj no. Nws yuav tsum qhib nrog Qhov rai uas nws nug tus lej chaw nres nkoj, nkag mus: ws: //xinabox_switch.local/rpc
  • Nws yuav sib txuas lus nrog CW02, thiab paub tias chav tsev twb tau taws thiab txuas nrog WiFi, yog li nws tsuas yog muab 3 qhov cim tseg. Kaw lub qhov rais thiab rov ua dua daim ntawv teev npe
  • Luam thiab paste cov cai hauv qab no rau hauv init.js, thiab nyem rau ntawm save+reboot
  • Tam sim no koj teeb tsa lub program.

Kauj Ruam 7: Xeem

Tam sim no koj tau siv lwm qhov RPC hu los ntawm koj lub davhlau ya nyob twg koj tuaj yeem nkag mus:

bin/mos --port ws: //xinabox_switch.local/rpc hu Hloov

… thiab koj lub suab nrov yuav tsum mus li 2 vib nas this. Koj kuj tseem tuaj yeem ua nws los ntawm - yuav luag - txhua lub browser:

xinabox_switch.local/rpc/Switch

… nrog tib yam.

Kauj Ruam 8: Kauj Ruam Tom ntej

Koj tuaj yeem siv cov cuab yeej uas tuaj yeem tua tawm URL. Kuv ua nws los ntawm Apple App hu ua Workflow, uas tso cai rau kuv ua los ntawm kuv lub xov tooj lossis raws li qhov nyuaj los ntawm kuv Apple Watch, tab sis muaj ntau txoj hauv kev xaiv tawm muaj. Nov yog kuv tsab ntawv Workflow, tab sis nrog hardcoded IP chaw nyob: Txaus siab rau!

Duab
Duab

Apple App: Workflow - ntawm no nrog tus lej IP nyuaj

Kauj Ruam 9: Schematics

Buzzer Circuit Txhim kho OC03 ua ke nrog lub laub uas twb muaj lawm.

Download tau nws ntawm no.

OC03 Circuit Court Txhim kho OC03 ua ke nrog lub laub uas twb muaj lawm.

Download tau nws ntawm no.

Duab
Duab

Kauj ruam 10: Code

init.js JavaScript Koj lub ntsiab thiab tsuas yog tus lej rau txoj haujlwm no.

thauj khoom ('api_config.js');

thauj khoom ('api_gpio.js'); thauj khoom ('api_i2c.js'); thauj khoom ('api_net.js'); thauj khoom ('api_sys.js'); thauj khoom ('api_timer.js'); thauj khoom ("api_rpc.js"); cia coj = Cfg.get ('pins.led'); cia adr = 0x38; cia npav = I2C.get (); I2C.writeRegB (tsheb npav, adr, 3, 0); I2C.writeRegB (tsheb npav, adr, 1, 0); / * tua tsuas yog kom paub tseeb */ cia ncua = 2000; GPIO.set_mode (coj, GPIO. MODE_OUTPUT); RPC.addHandler ('Hloov', ua haujlwm (sib cav) {GPIO.toggle (coj); I2C.writeRegB (tsheb npav, adr, 3, 0); / * nyob rau hauv rooj plaub OC03 tau rov txuas dua * / I2C.writeRegB (tsheb npav, adr, 1, 1); Timer.set (ncua, tsis tseeb, muaj nuj nqi () {GPIO.toggle (coj); I2C.writeRegB (tsheb npav, adr, 1, 0);}, tsis muaj); rov muaj tseeb;});

Pom zoo: