Skip to content

Instantly share code, notes, and snippets.

@dejanb
Last active February 8, 2024 15:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

I was able to do all this on my rPi, but not without some trouble. Here are my notes...

  • not clear where test-mesh is from (hint: [[https://github.com/DeltaEvo/bluez/blob/master/test/test-mesh][here]])
  • ModuleNotFoundError: No module named 'numpy'
  • installed pip in order to install numpy
  • still failed to import numpy C extensions so
    sudo apt-get install libatlas-base-dev
  • ModuleNotFoundError: No module named 'dbus' so
    pip install dbus-python
  • then got ModuleNotFoundError's for gi and glib errors and at this
    point decided I might've been expected to install some packages
    required to build the source, so attempted to: sudo apt-get
    build-dep bluez
  • that failed due a version mismatch with libell0, which i then
    deleted, taking bluez-meshd (previously installed from the
    testing repo) along with it.
  • that enabled build-dep to work fine, but that didn't get rid of
    my gi/glib module missing errors -- doh!
  • so then after reinstalling bluez-meshd from testing: sudo apt install python3-gi
  • that brought up test-mesh's main menu -- ta-da!

@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

@Gerodote
Copy link

Gerodote 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

@Gerodote
Copy link

Gerodote 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?

@Gerodote
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.

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