[BlueZ] 3, the connection control using a sig mesh meshctl lamp


Foreword

This article describes how to use meshctl pairing, and controls a sig mesh bulb


1, ready to work

1) compile and install meshctl:

meshctl and b luetoothctl are all the same bluez (on a linux Bluetooth protocol stack: Official Linux Bluetooth protocol stack #1

ps: written before bluez installation and use (mainly bluetoothctl)

Here the use of source compiler (not installed - green), copy a script below I named run.sh:

➜  bluez-5.52-pure cat run.sh 
#!/bin/bash

wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.52.tar.xz
tar -xvf bluez-5.52.tar.xz
cd bluez-5.52

./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-mesh
make -j8

Execute the script to automatically download, unpack, configure, compile, and finally in the bluez-5.52/tools/file executable created under themeshctl

Then you can execute the following command to start meshctl:

➜  tools ./meshctl --config mesh 
Waiting to connect to bluetoothd...Reading prov_db.json and local_node.json from mesh directory
[meshctl]# 

ps: --config meshis specified prov_db.jsonand local_node.jsondirectory.



2) Prepare a two-way lamp SIG MESH

Sig mesh to create a two-way lights on iot.tuya.com free development programs:

Then default point down, the hardware debugging phase, the single module may be selected for debugging (about 10 dollars, cheaper), after receiving the two LED modules according to the configuration on the module is connected, the power supply to :( the following diagram, for example: the pin is connected in a high GPIO2 lit white light beads, the pin is connected in a high GPIO7 lighting warm light beads, to give 3.3 after receiving module for module V electricity can)

Of course, you can also use your own development board, develop a standard SIG MESH own support onoff model of light ~


2, meshctl connection configuration, light control sig mesh

1) Search is not yet configured

Input discover-unprovisioned oncommand automatically searches sig mesh surrounding the device is not configured, as a search for the MAC BC:23:4C:04:CC:F7device:

[meshctl]# discover-unprovisioned on
SetDiscoveryFilter success
Discovery started
Adapter property changed 
[CHG] Controller A0:D3:7A:DB:24:B8 Discovering: yes
        Mesh Provisioning Service (00001827-0000-1000-8000-00805f9b34fb)
            Device UUID: bc234c04ccf75012366c63366c677062
            OOB: 0000
[NEW] Device BC:23:4C:04:CC:F7 BC-23-4C-04-CC-F7



2) provision equipment

With the following command distribution network security level is set to 0 :( authentication mechanism created using light graffiti from the IOT platform is: no oob)

[meshctl]# security 0
Provision Security Level set to 0 (low)

Then calls provisionthe device connector is configured :( wherein Composition data of the node configuration information)

[meshctl]# provision  bc234c04ccf75012366c63366c677062
Trying to connect Device BC:23:4C:04:CC:F7 BC-23-4C-04-CC-F7
Adapter property changed 
[CHG] Controller A0:D3:7A:DB:24:B8 Discovering: no
Connection successful
Service added /org/bluez/hci0/dev_BC_23_4C_04_CC_F7/service0008
...
GATT-RX:     00 f4 05 1f de 88 66 06 9f 72 f8 31 ca 0f 9f 46 
GATT-RX:     55 3c 46 89 0e de e5 8e ad 29 
    Composition data for node 0100 {
  "cid":"07d0",
  "pid":"0005",
  "vid":"3033",
  "crpl":"0069",
  "features":{
    "relay":true,
    "proxy":true,
...
}
GATT-TX:     00 f4 2b 62 8c 1e e2 d1 65 31 1d 78 04 28 5d 16 
GATT-TX:     92 a3 db 21 5b 82 fc 75 c3 
[DEL] Device DC:23:4D:0B:74:4F DC-23-4D-0B-74-4F
[DEL] Device BC:23:4C:03:88:D1 BC-23-4C-03-88-D1
[SigMesh-Node-0100]# 



3) binding configuration

Use menu configto enter the subdirectory, using target 0100the nodes to be configured to select the current 0100;

With netkey-add 0configuration 0 to a network device keys using appkey-add 1a device configuration of an application-level secret key (secret network key and the secret key is APP mesh specification requirements, the secret key may be performed in the Home menu meshctl mesh-infoseen);

Finally, bind 0 1 1000to achieve the model: 1000 Binding (using net-key 0 when binding, App-Key 1)
PS: Subscribe to publish a sig mesh joint implementation mechanism of control, every event and action are abstract model, such as: onoff model is predetermined switching logic model, which is a predetermined dead id: 0x1000

[SigMesh-Node-0100]# menu config
[SigMesh-Node-0100]# target 0100
[config: Target = 0100]# netkey-add 0
[config: Target = 0100]# appkey-add 1
[config: Target = 0100]# bind 0 1 1000



4) controls the light switch

Config return from the submenu, enter onoff sub-menu, and then select the 0100 target, then you can use onoff command to achieve control after :( If you open meshctl again, just call connect 0 0100to achieve connection again)

[config: Target = 0100]# back
[config: Target = 0100]# menu onoff 
[config: Target = 0100]# target 0100
[on/off: Target = 0100]# onoff 0
[on/off: Target = 0100]# onoff 1


3, the final results:



: Bluez: bluez of meshctl is a relatively new feature of domestic and foreign data is relatively small, especially in the deployment of cross-compilation system!
: We feel good, we can point to recommend to more people -


[1] .bluez official website
[2] .BLE Mesh Development (1) - nRF52 and meshctl


@beautifulzzzz
以蓝牙技术为基础的的末梢无线网络系统架构及创新型应用探索!
领域:智能硬件、物联网、自动化、前沿软硬件
博客:https://www.cnblogs.com/zjutlitao/
微信交流群|微信:园友交流群|btfzzzz

Guess you like

Origin www.cnblogs.com/zjutlitao/p/12493600.html