Skip to content

Instantly share code, notes, and snippets.

@dejanb
Last active September 30, 2024 16:55
Show Gist options
  • Save dejanb/85282932d08d26dce2c9323b3d0cc1e2 to your computer and use it in GitHub Desktop.
Save dejanb/85282932d08d26dce2c9323b3d0cc1e2 to your computer and use it in GitHub Desktop.
Test Bluetooth mesh

start clean mesh (first terminal):


$ rm -rf ~/.config/meshcfg/config_db.json
$ sudo rm -rf /var/lib/bluetooth/mesh
$ sudo mkdir /var/lib/bluetooth/mesh
$ sudo /usr/libexec/bluetooth/bluetooth-meshd -nd --debug

provisioner (second terminal):


$ mesh-cfgclient

Warning: config file "/home/pi/.config/meshcfg/config_db.json" not found
[mesh-cfgclient]# create
Created new node with token 522b02d50de1c8a2
Proxy added: org.bluez.mesh.Node1 (/org/bluez/mesh/nodea186fe8c7e3b461daa29664eba26ed2d)
Proxy added: org.bluez.mesh.Management1 (/org/bluez/mesh/nodea186fe8c7e3b461daa29664eba26ed2d)
Attached with path /org/bluez/mesh/nodea186fe8c7e3b461daa29664eba26ed2d
[mesh-cfgclient]# appkey-create 0 0

device (third terminal):


$ bluez/test/test-mesh

join
Joining with UUID 3df8492249f1476491a1e4e1d051a5f7
Join procedure started

provisioner:


[mesh-cfgclient]# provision 3df8492249f1476491a1e4e1d051a5f7

device:

PromptStatic ( static-oob )
Enter 16 octet key on remote device:  6f4b1f31cbe0d0f81b0ef64a1c70b86c

provisioner:


[[mesh-agent]# ] Enter key (hex number): 6f4b1f31cbe0d0f81b0ef64a1c70b86c

device:

Joined mesh network with token 62cb5d464413e5c7

provisioner:


Assign addresses for 2 elements
Provisioning done:
Mesh node:
	UUID = 3DF8492249F1476491A1E4E1D051A5F7
	primary = 00aa

	elements (2):

[mesh-cfgclient]# menu config
[mesh-cfgclient]# target 00aa
Configuring node 00aa

[config: Target = 00aa]# appkey-add 0

[config: Target = 00aa]# composition-get
Received DeviceCompositionStatus (len 29)
Received composion:
	Feature support:
		relay: yes
		proxy: no
		friend: yes
		lpn: no
	 Element 0:
		location: 0000
		SIG defined models:
		  Model ID	0000 "Configuration Server"
		  Model ID	1000 "Generic OnOff Server"
		 Vendor defined models:
		  Model ID	05f1 0001
	 Element 1:
		location: 0000
		SIG defined models:
		  Model ID	1001 "Generic OnOff Client"

[config: Target = 00aa]# bind 00aa 0 1000
[config: Target = 00aa]# bind 00ab 0 1001

device:


attach
Attach mesh node to bluetooth-meshd daemon
Mesh app registered: /org/bluez/mesh/node3df8492249f1476491a1e4e1d051a5f7
Update Model Config 1000
Bindings: [0]
Update Model Config 1001
Bindings: [0]

dest
Enter 4-digit hex destination address:
00aa
Destination address: 00aa
client-menu
*** ON/OFF CLIENT MENU ***
on
Set state: 1
OnOffClient send command
Message Received on Element 00, src= 00ab, dst=00aa
State is ON
Message Received on Element 01, src= 00aa, dst=00ab
OnOffClient process message len = 3
Got state ON from 00aa
off
Set state: 0
OnOffClient send command
Message Received on Element 00, src= 00ab, dst=00aa
State is OFF
Message Received on Element 01, src= 00aa, dst=00ab
OnOffClient process message len = 3
Got state OFF from 00aa
get-state
OnOffClient send command
Message Received on Element 00, src= 00ab, dst=00aa
Get state
Message Received on Element 01, src= 00aa, dst=00ab
OnOffClient process message len = 3
Got state OFF from 00aa
@jcrossley3
Copy link

More concisely put...

   sudo apt install git pip libatlas-base-dev python3-gi
   git clone https://github.com/bluez/bluez.git
   pip install numpy dbus-python termcolor

Ensure bluetooth-meshd is running, and then

   ./bluez/test/test-mesh

@Arniiiii
Copy link

Arniiiii commented Jun 29, 2023

this should be in documentation of bluez mesh. or in test. or comment about how to test inside of bluez/test/test.mesh

@dejanb
Copy link
Author

dejanb commented Jul 7, 2023

@Gerodote I agree, although I don't know where that documentation is (for bluez in general). If you have a pointer to it, please let me know

@Arniiiii
Copy link

Arniiiii commented Jul 7, 2023

@Gerodote I agree, although I don't know where that documentation is (for bluez in general). If you have a pointer to it, please let me know

I guess somewhere there ( I can be wrong ):
https://github.com/bluez/bluez/tree/master/doc
https://github.com/bluez/bluez/tree/master/test

@dejanb
Copy link
Author

dejanb commented Jul 10, 2023

Non of those seems suitable to me. The first is the API spec and the other are tests. Maybe raise an issue with the community to see where examples like this could fit?

@Arniiiii
Copy link

Non of those seems suitable to me. The first is the API spec and the other are tests. Maybe raise an issue with the community to see where examples like this could fit?

Good idea !

@dreamlayers
Copy link

Thank you! Using this I was also able to turn my Sylvania A19 T-C-MD84F bulb on and off. I was having a lot of trouble provisioning them before, and ended up getting /data/user/0/com.ledvance.smartplus/files/Network_*.meshdata from my phone, so I can use the network that Sylvania's app already created. I used https://github.com/NickstaDB/SerializationDumper/releases/tag/1.13 to extract keys and the device address. Configuring the network to work with that was somewhat complicated. But then I simply started with the test-mesh join step here, and after following these instructions I could simply set the Sylvania bulb as the target and control it.

@vincentPlanat
Copy link

Hi,

I'm testing mesh using 2 raspberry PI 5 on which I've recompile &install the latest 5.77 version
I try a basic test where on

  • PI-1 I join (mesh-cfgclient) a node
  • PI-2 I try to discover it (discover-unprovisioned on)

The discover-unprovisioned on works on PI-1 (like in the above example)
but on PI-2 it returns nothing .....
Same system on both side, same stack, same version

Perhaps I'm not proceeding the right way.
If an expert in the community could help me that would be great !!!

Find below my test case.

Regards


On both PI
sudo systemctl disable bluetooth
sudo systemctl stop bluetooth
in /etc/bluetooth/main.conf, AutoEnable=false then reboot

On PI-1
Terminal-1
sudo rm -rf ~/.config/meshcfg/config_db.json
sudo rm -fr /root/.config/meshcfg/config_db.json
sudo rm -rf /var/lib/bluetooth/mesh
sudo mkdir /var/lib/bluetooth/mesh
sudo /usr/libexec/bluetooth/bluetooth-meshd -nd --debug

Terminal-2
sudo mesh-cfgclient
create

Terminal-3
pyhton3 test-mesh
join
==> here I get: Joining with UUID 346d6b0cf5b8446d9beff2078ec9bfdf

Terminal-2
discover-unprovisioned on
list-unprovisioned
==> Here I get:
Unprovisioned devices:
#1 UUID: 346D6B0CF5B8446D9BEFF2078EC9BFDF, RSSI 0, Server: 0001

Up to here all looks fine

On the PI-2, I try to discover the the un provisioned node active on the PI-1
PI-2 & PI-1 have the same 5.77 bluez stack recompile

On PI-2
Terminal-1
sudo rm -rf ~/.config/meshcfg/config_db.json
sudo rm -fr /root/.config/meshcfg/config_db.json
sudo rm -rf /var/lib/bluetooth/mesh
sudo mkdir /var/lib/bluetooth/mesh
sudo /usr/libexec/bluetooth/bluetooth-meshd -nd --debug

Terminal-2
sudo mesh-cfgclient
create
discover-unprovisioned on
list-unprovisioned
Unprovisioned devices:

====>>>
The problem is that my list-unprovisioned on PI-2 / Terminal-2 does
not retrieve anything

I see nevertheless, on PI-2 (see meshd logs below) some beacon
activity, but I don't understand why I can get them on the
list-unprovisioned

Thanks very much for your support
Regards
user@localhost:~ $ sudo /usr/libexec/bluetooth/bluetooth-meshd -nd --debug
D-Bus ready
Loading node configuration from /var/lib/bluetooth/mesh
mesh/mesh-mgmt.c:mesh_mgmt_list() send read index_list
mesh/mesh.c:mesh_init() io 0x55567219e080
mesh/mesh-mgmt.c:read_index_list_cb() Number of controllers: 1
mesh/mesh-mgmt.c:read_info_cb() hci 0 status 0x00
mesh/mesh-mgmt.c:read_info_cb() settings: supp 0001feff curr 00000080
mesh/mesh-mgmt.c:features_cb() Status: 0, Length: 4
index 0 up:1 pwr: 0 mesh: 1
mesh/mesh-io-mgmt.c:read_info_cb() hci 0 status 0x00
Controller hci 0 not in use
mesh/mesh-io-mgmt.c:le_up() HCI0 LE up status: 0
mesh/mesh-io-mgmt.c:ctl_up() HCI0 is up status: 0
mesh/mesh-io-mgmt.c:ctl_up() done 0 mesh startup
mesh_ready_callback
Added Network Interface on /org/bluez/mesh
mesh/mesh-io-mgmt.c:mesh_up() HCI0 Mesh up status: 0
mesh/mesh.c:create_network_call() Create network request
mesh/node.c:node_create()
mesh/node.c:get_app_properties() path /mesh/cfgclient
mesh/node.c:get_element_properties() path /mesh/cfgclient/ele0
mesh/mesh-config-json.c:mesh_config_create() New node config
/var/lib/bluetooth/mesh/f449ed321026445a888075a0f85f18f6/node.json
mesh/mesh-config-json.c:mesh_config_net_key_add() netKey 0000
mesh/net.c:trigger_heartbeat() HB: 0002 --> 0
mesh/net.c:mesh_net_set_friend_mode() mesh_net_set_friend_mode - 0
mesh/net.c:trigger_heartbeat() HB: 0001 --> 0
mesh/cfgmod-server.c:cfgmod_server_init() 00
mesh/prvbeac-server.c:prv_beacon_server_init() 00
mesh/keyring.c:keyring_put_remote_dev_key() Put Dev Key
/var/lib/bluetooth/mesh/f449ed321026445a888075a0f85f18f6/dev_keys/0001
mesh/mesh.c:create_node_ready_cb() Calling JoinComplete (create)
mesh/mesh.c:attach_call() Attach
mesh/node.c:get_app_properties() path /mesh/cfgclient
mesh/node.c:get_element_properties() path /mesh/cfgclient/ele0
mesh/node.c:build_element_config() Element 0
mesh/node.c:dev_key_send_call() DevKeySend
mesh/mesh-config-json.c:mesh_config_write_seq_number() Seq Cache: 1 -> 30001
mesh/model.c:mesh_model_rx() iv_index 00000000 key_aid = 00
mesh/util.c:print_packet() 43751.675 Clr Rx: 800880
mesh/cfgmod-server.c:cfg_srv_pkt() CONFIG-SRV-opcode 0x8008 size 1 idx 000
mesh/model.c:mesh_model_rx() iv_index 00000000 key_aid = 00
mesh/util.c:print_packet() 43751.675 Clr Rx:
0200f10502000100ff7f050000000600000001000400050008000900
mesh/cfgmod-server.c:cfg_srv_pkt() CONFIG-SRV-opcode 0x2 size 27 idx 000
mesh/prvbeac-server.c:prvbec_srv_pkt() PRV-BEAC-SRV-opcode 0x2 size 27 idx 000
mesh/model.c:send_dev_key_msg_rcvd() Send "DevKeyMessageReceived"
mesh/prvbeac-server.c:prvbec_srv_pkt() PRV-BEAC-SRV-opcode 0x8008 size 1 idx 000
mesh/model.c:mesh_model_rx() iv_index 00000000 key_aid = 00
mesh/util.c:print_packet() 43754.793 Clr Rx: 8052053c
mesh/cfgmod-server.c:cfg_srv_pkt() CONFIG-SRV-opcode 0x8052 size 2 idx 000
PB-SVR: src 0001 dst 0001
mesh/util.c:print_packet() 43754.794 App Tx: 80540001053c
mesh/model.c:mesh_model_rx() iv_index 00000000 key_aid = 00
mesh/util.c:print_packet() 43754.794 Clr Rx: 80540001053c
mesh/cfgmod-server.c:cfg_srv_pkt() CONFIG-SRV-opcode 0x8054 size 4 idx 000
mesh/prvbeac-server.c:prvbec_srv_pkt() PRV-BEAC-SRV-opcode 0x8054 size 4 idx 000
mesh/prvbeac-server.c:prvbec_srv_pkt() PRV-BEAC-SRV-opcode 0x8052 size 2 idx 000
mesh/util.c:print_packet() 43757.940 Set SNB to:
2b01002a9d9d56281cefca0000000005e47ebf08b81ef0
mesh/net-keys.c:net_key_beacon_refresh() Set Beacon: IVI: 00000000,
IVU: 0, KR: 0
mesh/net-keys.c:beacon_timeout() beacon 1 for 1 nodes, period 20, obs 2, exp 3
mesh/net-keys.c:beacon_timeout() beacon 1 for 1 nodes, period 20, obs 2, exp 2
mesh/net-keys.c:beacon_timeout() beacon 1 for 1 nodes, period 20, obs 2, exp 2
mesh/manager.c:scan_cancel()
mesh/model.c:mesh_model_rx() iv_index 00000000 key_aid = 00
mesh/util.c:print_packet() 43814.794 Clr Rx: 8053
mesh/cfgmod-server.c:cfg_srv_pkt() CONFIG-SRV-opcode 0x8053 size 0 idx 000
mesh/prvbeac-server.c:prvbec_srv_pkt() PRV-BEAC-SRV-opcode 0x8053 size 0 idx 000
mesh/net-keys.c:beacon_timeout() beacon 1 for 1 nodes, period 20, obs 2, exp 2

@dejanb
Copy link
Author

dejanb commented Sep 4, 2024

Hi Vincent, if I remember correctly (which might not be the case), your expectation to see the unprovisioned device on both PIs is not correct. There can be only one "provisioner" on the mesh. By calling "create" on PI2 you are actually creating a new network.

I hope this helps.

@dreamlayers
Copy link

Yes, provisioning is the action of joining a device to a network. The device can only be a member of one network at a time. Typically devices can only be discovered unprovisioned when they've been reset, like after rapidly turning a light bulb off and on some number of times. You certainly can use one device from two different computers, but both of those computers must be part of the same network. This can be accomplished by copying the relevant keys from one computer to the other. I did this to control a Sylvania light bulb that had been provisioned via Sylvania's app on my phone. After my computer became part of the same network, I was able to control the light bulb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment