SILICON LABS LETŠOAO

SILICON LABS 21Q2 Bluetooth Features Lab

SILICON LABS 21Q2 Bluetooth Features Lab

Bukana ea Lab ea Likarolo tsa Bluetooth 21Q2

Bukana ena ea lab e u tsamaisa ho tse ling tsa likarolo tse ncha tsa Bluetooth SDK tse hlahisitsoeng pakeng tsa tokollo ea 20Q4 le 21Q2. Lab ena re tla theha NCP example le ho ngola software e amohelang batho ka puo ea Python. Ka ho sebelisa tšobotsi e ncha ea GATT re tla boela re hahe polokelo ea boitsebiso ea GATT ho tsoa ho software e amohelang sebakeng sa ho sebelisa GATT Configurator. Qetellong karolo ea LE Power Control e hlahisoa ka ho holisa software ea moamoheli.SILICON LABS 21Q2 Bluetooth Features Lab 1

Lintho tse hlokahalang

Ho phethela lab ena, o tla hloka tse latelang:

  • Li-Thunderboard BG22 tse peli kapa li-WSTK tse peli tse nang le boto efe kapa efe ea seea-le-moea ea EFR32BG/EFR32MG kapa motsoako oa tsena
  • Simplicity Studio 5 e kentsoe, e nang le Gecko SDK v3.2 ho kenyelletsa le Bluetooth SDKv3.2
  • PC eo ho eona Python v3.6 kapa hamorao e kentsoeng

Ho khantša Lisebelisoa tse reriloeng bakeng sa Ts'ebetso ea NCP

  • Hokela liboto tsa hau tse peli tsa seea-le-moea 'me u bule Simplicity Studio 5
  • Khetha e 'ngoe ea liboto tsa seea-le-moea ho tab ea Debug Adapters
  • Beha SDK e Ratoang ho v3.2.0 ho Overview tab ya Launcher view
  • Bula Example Projects & Demos tab
  • Fumana ponts'o e ncha ea Bluetooth - NCP.
  • Tobetsa Matha ho khantša setšoantšo sa sepheo sa NCP botong.SILICON LABS 21Q2 Bluetooth Features Lab 2

(Tlhokomeliso: ho fapana le Bluetooth - NCP Empty, morero ona ha o kenyeletse database ea GATT e hahiloeng esale pele, empa e na le GATT API e matla e lumelletsoeng, e leng ntho e hlokahalang bakeng sa likarolo tse latelang)

  • Pheta mehato e tšoanang bakeng sa boto e 'ngoe ea seea-le-moea.

Ho theha Sesebelisoa sa Seva sa Bluetooth ho Python

Rea qala

  • Sephutheloana sa pybgapi se fana ka monyetla oa ho fana ka litaelo tsa BGAPI ho sesebelisoa se shebiloeng ho tsoa ho PC ho sebelisa puo ea lenaneo la Python. Ho kenya sephutheloana sena thaepa tse latelang moleng oa taelo: pip install pybgapi Bakeng sa boitsebiso bo eketsehileng mabapi le ketelo ea sephutheloana https://pypi.org/project/pybgapi/
  • Fumana tlhaloso ea morao-rao ea BGAPI file tlasa
  • C:\SiliconLabs\SimplicityStudio\v5\developer\sdks\gecko_sdk_suite\v3.2.0\protocol\bluetooth\api\sl_bt.xapi mme o e kopise mo foldareng ya gago e e berekang.
  • Bula python bash (mofuta oa python ho CLI)
  • Kenya laeborari ea bgapi ka taelo e latelang: >>> kenya bgapi
  • Fumana nomoro ea boema-kepe ea COM (mohlala COM49) ea e 'ngoe ea liboto tsa hau tsa seea-le-moea. U lokela ho batla "JLink CDC UART Port" ho Motsamaisi oa Sesebelisoa kapa sesebelisoa seo u se ratang haholo.SILICON LABS 21Q2 Bluetooth Features Lab 3
  • Hokela ho boto ea radio ea hau:
    • >>> kgokelo = bgapi.SerialConnector('COM49')
  • Qala laeborari ea pybgapi bakeng sa node ena:
    • >>> node = bgapi.BGLib(khokahanyo,'sl_bt.xapi')
  • Bula puisano ea BGAPI mabapi le node ena:
    • >>> node.open()
  • Sheba hore na u ka buisana le boto, u sebelisa taelo ea system_hello (). U lokela ho fumana karabelo ea system_hello:
    • >>> node.bt.system.hello()
      • bt_rsp_system_hello(sephetho=0)
  • Seta node ea hau bocha ka taelo e latelang:
    • node.bt.system.reset(0)
  • Joale o lokela ho fumana ketsahalo ea system_boot. Ho lata ketsahalo ea morao-rao, sebelisa taelo e latelang:
    • evt = node.get_events(max_events=1)
    • hatisa(evt)
      • [bt_evt_system_boot(major=3, minor=2, patch=0, build=774, bootloader=17563648, hw=1, hash=1181938724)]

Ho aha database ea GATT

  • Sesebelisoa sa sepheo sa Bluetooth - NCP ha se kenyeletse polokelong ea litaba ea GATT e hahiloeng esale pele. Mona re tla theha database ho tsoa ho khoutu. Qala lenaneo la ho aha database:
    • >>> seboka = node.bt.gattdb.new_session().session
  • Kenya tšebeletso e ncha polokelong ea polokelo ea GATT. Mona re tla eketsa tšebeletso ea phihlello e akaretsang e amoheloang ke Bluetooth SIG. Ena ke ts'ebeletso ea mantlha (0x0) e se nang lifolakha tse behiloeng (0x0) le 16bit UUID (0x1800).
    • service = node.bt.gattdb.add_service(session, 0, 0, bytes.frmhex(“0018”)).tšebeletso
  • Kenya tšobotsi e ncha tšebeletsong. Mona re tla kenyelletsa tšobotsi ea Lebitso la Sesebelisoa ho tšebeletso ea Generic Access e nang le thepa ea BALA (0x2), ha ho litlhoko tsa tšireletso (0x0), ha ho lifolakha (0x0), 16bit UUID (0x2a00), bolelele bo fapaneng (0x2), bolelele bo boholo ba 20 le ka boleng ba pele ba "PyBGAPI

Example":

  • >>> char = node.bt.gattdb.add_uuid16_characteristic(nako, tšebeletso, 2, 0, 0, bytes.fromhx('002a'), 2,
    • 20, li-byte('PyBGAPI Example','utf-8′)).sebopeho
    • 3.15 Kenya tshebetsong tshebeletso e ntjha:
  • >>> node.bt.gattdb.start_service(nako, tshebeletso)
    • bt_rsp_gattdb_start_service(sephetho=0)
  • Kenya tšebetsong tšobotsi e ncha:
    • >>> node.bt.gattdb.start_characteristic(session, char)
      • bt_rsp_gattdb_start_characteristic(sephetho=0)
  • Boloka liphetoho 'me u koale nako ea ho hlophisa polokelong ea litaba:
    • >>> node.bt.gattdb.commit(session)
    • bt_rsp_gattdb_commit(sephetho=0)

Ho hokela ho Seva

  • 3.18 Kaha joale re na le lebitso la sesebelisoa polokelong ea polokelo ea GATT, re ka qala ho bapatsa. Stack e tla bapatsa sesebelisoa ka bo eona ka lebitso le hlalositsoeng polokelong ea eona ea GATT:
    • >>> advertiser_set = node.bt.advertiser.create_set().handle
    • >>> node.bt.advertiser.start(advertiser_set, 2, 2)
      • bt_rsp_advertiser_start(sephetho=0)
  • Qala EFR Connect fonong ea hau, 'me u fumane papatso ea sesebelisoa sa hau e le "PyBGAPI Example ”
  • O ka hokela sesebelisoa mme oa fumana database ea eona ea GATT eo hajoale e nang le tšobotsi ea Lebitso la Sesebelisoa

Tlhokomeliso: haeba u batla ex ea kapele haholoample ntle le ho khathatseha ka database ea GATT, o ntse o ka khantša Bluetooth - NCP Empty example ho boto ea hau, e nang le database ea GATT e hahiloeng esale pele. Tabeng ena sohle seo u lokelang ho se etsa ka lehlakoreng la moamoheli ke:

  • >>> import bgapi
  • >>> kgokelo = bgapi.SerialConnector('COM49')
  • >>> node = bgapi.BGLib(khokahanyo,'sl_bt.xapi')
  • >>> node.open()
  • >>> advertiser_set = node.bt.advertiser.create_set().handle
  • >>> node.bt.advertiser.start(advertiser_set, 2, 2)
    • bt_rsp_advertiser_start(sephetho=0)

Ho theha Sesebelisoa sa Client sa Bluetooth ho Python

  • Ho theha moreki ho thata ho feta ho kenya tšebetsong seva. Kahoo re tla ngola python script. Bula mongolo oo u o ratang 'me u thehe e ncha file, ha re e bitse client.py
  • Fumana tse latelang:SILICON LABS 21Q2 Bluetooth Features Lab 4
  • Joalo ka molemong oa seva, re tla hokela node ka UART. Sebelisa nomoro ea boema-kepe ea COM ea boto ea hau ea bobeli mona:SILICON LABS 21Q2 Bluetooth Features Lab 5
  • Ho tloha mona, kopo ea rona e tla tsamaisoa ke ketsahalo. Nako le nako ha ketsahalo ea Bluetooth e hlahisoa ke stack, re tla sebetsana le ketsahalo ebe re khanna kopo pele:SILICON LABS 21Q2 Bluetooth Features Lab 6
  • Ha re hlalose ts'ebetso ea ts'ebetso ea ketsahalo mme re kenye sebapali bakeng sa ketsahalo ea system_boot, moo re tla qala ho hlahloba lisebelisoa tsa peripheral. Hlokomela, hore ts'ebetso ena e lokela ho hlalosoa pele ho loop ea nakoana (le ka mor'a tlhaloso ea phapang ea node).SILICON LABS 21Q2 Bluetooth Features Lab 7.
  • Hang ha scanner e se e qalile, node e tla be e fumana litlaleho tsa scan. Ha re kenyeng mohlokomeli oa liketsahalo bakeng sa litlaleho tsa scan ka har'a ts'ebetso ea sl_bt_on_event(). Haeba tlaleho ea scan ninete e fumaneha ka lebitso la sesebelisoa se bapalitsoeng "PyBGAPI Example", moreki o tla bula khokahano ho sesebelisoa seo: SILICON LABS 21Q2 Bluetooth Features Lab 7
  • Ha u se u fihlile ntlheng ena ho bohlokoa ho hlahloba hore na moreki oa hau o fumana seva. Etsa bonnete ba hore u se u qalile papatso ho sesebelisoa se seng, ebe u boloka client.py, 'me u e qale ho tloha molaong oa taelo. U lokela ho bona ntho e kang ena: SILICON LABS 21Q2 Bluetooth Features Lab 8
  • Moreki o tlameha ho fumana lits'ebeletso le litšobotsi ho seva. Mona re tla fumana tšebeletso ea generic Access le tšobotsi ea Lebitso la Sesebelisoa, 'me qetellong re bale boleng ba tšobotsi ea Lebitso la Sesebelisoa. Tlosa tšebetso ea sl_bt_on_event() ea hau ea hajoale ka khoutu e latelang:SILICON LABS 21Q2 Bluetooth Features Lab 9 SILICON LABS 21Q2 Bluetooth Features Lab 10
  • Boloka client.py 'me u e qale ho tloha molaong oa taelo. U lokela ho bona ntho e kang ena:SILICON LABS 21Q2 Bluetooth Features Lab 11

Ho eketsa tšobotsi ea LE Power Control

Ho khantša lisebelisoa tse reriloeng

LE Power Control ha e sebetse ho Bluetooth example merero ka ho sa feleng. Ho kenya tšobotsi ena, Bluetooth > Feature > PowerControl software component e tlameha ho kengoa.

  • Bula sesebelisoa view ea Bonolo Studio 5.
  • Khetha e 'ngoe ea lisebelisoa tsa hau ho "Debug Adapters". Etsa bonnete ba hore SDK e ratoang ke v3.2.
  • Bula Example Projects & Demos tab 'me u fumane Bluetooth - NCP Empty example. Tobetsa [Create] ho theha morero. (Lekhetlong lena ha re batle ho haha ​​​​database ea GATT, kahoo re sebelisa NCP Empty, e nang le ea kamehla.)
  • Bula tab ea GATT Configurator, khetha tšobotsi ea Lebitso la Sesebelisoa, 'me u ngole "Silabs Ex".ample" boleng ba pele ka "PyBGAPI Example” (e le hore moreki a tle a tsebe seva). Hape ngolla bolelele ba boleng ka 15.
  • Tobetsa ctrl-s ho boloka database.
  • Ho "Project Configurator" bula "Software Components" tab.
  • Fumana karolo ea Bluetooth > Feature > PowerControl software, ebe o tobetsa [Install]SILICON LABS 21Q2 Bluetooth Features Lab 12
  • Tobetsa ho cogwheel haufi le karolo ea PowerControlsoftware ho hlahloba meeli e ka holimo le e tlase ea mefuta ea khauta. Beha moeli o tlase oa 1M
    • PHY ho ea ho -45 (ho e-na le -60). Le hoja ts'ebetsong boleng bona bo sa nepahale, bo tla fella ka liphetoho tse ngata tsa Tx, tse molemo bakeng sa merero ea lipontšo.
  • Mofuteng oa 3.2.0 oa SDK, ho hlokahala hore ho sebelisoe mokhoa o monyenyane oa ho sebetsa ho hlophisa mofuta oa khauta hantle: bula sl_bluetooth.c file e fumanoa ho foldareng ea /autogen ea projeke ea hau ebe u tsamaisa sl_bt_init_power_control(); pitso ea mosebetsi PELE sl_bt_init_stack(&config);SILICON LABS 21Q2 Bluetooth Features Lab 13
  • Theha projeke 'me u e khantše boto ea hau.
  • Haeba liboto tsa hau tse peli li tšoana, u khantše setšoantšo se tšoanang le letlapeng le leng. Haeba boto ea hau ea bobeli e le boto e fapaneng, joale pheta mehato e ka holimo bakeng sa boto ea bobeli.

Ho qala seva le moreki

  • Joale hape, bula bash ea Python, ikopanye le boto ea hau ea pele, 'me u qale ho bapatsaSILICON LABS 21Q2 Bluetooth Features Lab 14
  • Fetola sesebelisoa sa hau sa moreki hore se se ke sa tsoa kamora ho bala lebitso la sesebelisoa. Fumana mela e latelang, 'me u e kenye maikutlong:SILICON LABS 21Q2 Bluetooth Features Lab 15
  • Boloka 'me u tsamaise sesebelisoa sa hau sa bareki
    • py.\client.py
  • Beha liboto tsa hau tse peli hole, ebe butle u li tsamaisa haufi le tse ling. Joale o lokela ho bona hore stack e qala ho fokotsa matla a eona ho tloha ho 8dBm ea kamehla ho ea ho -3dBm (e leng matla a fokolang a Tx ka ho sa feleng):SILICON LABS 21Q2 Bluetooth Features Lab 16

Litokomane / Lisebelisoa

SILICON LABS 21Q2 Bluetooth Features Lab [pdf] Buka ea Taelo
21Q2, Bluetooth Features Lab, 21Q2 Bluetooth Features Lab, Features Lab, Lab

Litšupiso

Tlohela maikutlo

Aterese ea hau ea lengolo-tsoibila e ke ke ea phatlalatsoa. Libaka tse hlokahalang li tšoailoe *