使用 D-Bus Python Bluez Mesh API 获取新配置节点的组成数据

问题描述 投票:0回答:1

我目前正在 Raspberry Pi 4 上使用 Python D-Bus API 实现基于 BlueZ v5.54 的 Provisioner 节点,示例为 test-mesh,我想读取网状网络中节点的组成数据。我使用

mesh-cfgclient
进行了测试,结果显示没问题,所以我认为在我的方法中应该是可行的。

但是,直到现在我还没有找到解决办法。大家有这方面的方法吗?我对 BlueZ D-Bus 没有太多经验,因此我们将不胜感激。

我尝试使用 DevKeySend() 和配置组合数据获取消息操作码,但它不起作用并且什么也不显示。这是我与之相关的代码:

def __cmd_feature(self):
    if attached != True:
        print(set_error('Disallowed: node is not attached'))
        return
    
        # create an empty element object to
    glo_element = Element(bus, 0x02)
    opcode = 0x8008          # Configuration Data Get opcode
    page = 0
    data = bytearray(struct.pack('<HB', opcode, page))

        # send message to read Composition Data, net_idx = 0 (default)
    node.DevKeySend(glo_element.get_path(), dst_addr, False, net_idx, data,
            reply_handler=generic_reply_cb,
            error_handler=generic_error_cb)

class Element(dbus.service.Object):
        ...
        # If successful, this function should be executed
        @dbus.service.method(MESH_ELEMENT_IFACE, in_signature="qbqay", out_signature="")
    def DevKeyMessageReceived(self, source, remote, net_idx, data):
        print('Received data:')
        print(source)
        print(remote)
        print(net_idx)
        print(data)

... the rest of code is similar to 'test-mesh' example

我还创建了一些命令和一个用于配置的节点菜单,如示例中所示进行测试。这是我的应用程序控制台:

pi@raspberrypi:~/Desktop/test $ python btmesh_provisioner.py b3fc4cd44cb2fcec
Register OnOff Server model on element 0
OnOff Server 
State is OFF
Register Vendor model on element 0
Register OnOff Client model on element 1
OnOff Client
*** MAIN MENU ***
token  - set node ID (token)
create  - create mesh network
appkey-index  - set AppKey index
appkey-new  - create appkey
scan-start  - scan for near unprovisioned devs
scan-cancel  - cancel scanning
element-index  - set Element index
add  - add device to mesh network
join  - join mesh network
attach  - attach mesh node
remove  - delete node
dest  - set destination address
uuid  - set remote uuid
vendor-send  - send raw vendor message
config-menu  - Node Configuration menu
client-menu  - On/Off client menu
help  - show list command
quit  - exit the test

attach
Attach mesh node to bluetooth-meshd daemon
Mesh app registered: /org/bluez/mesh/node0a0102030405060708090a0b0c0d0e0f
scan-start
Scanning...
Scan procedure started
ScanResult RSSI -69 dddd08a6f7a05fde0000000000000000000000000000
uuid 
Enter 32-digit hex remote UUID:
dddd08a6f7a05fde0000000000000000

add
Adding dev UUID dddd08a6f7a05fde0000000000000000
AddNode procedure started
RequestProvData for Ele_Cnt 3
AddNodeComplete of node 02a6 uuid dddd08a6f7a05fde0000000000000000
dest
Enter 4-digit hex destination address:
02a6
Destination address: 02a6
config-menu

*** ON/OFF CLIENT MENU ***
appkey-add  - add AppKey index in network
element-props  - get Element properites
feature  - show node feature
back  - back to main menu
quit  - exit the test

feature
feature

(Nothing happened, end)

bluetooth-meshd 的日志(尝试执行 __cmd_feature 时):

mesh/node.c:dev_key_send_call() DevKeySend
mesh/model.c:msg_send() (7fff) 0x1d42618
mesh/model.c:msg_send() net_idx 0
mesh/model.c:mesh_model_rx() iv_index 00000000 key_aid = 00
mesh/net.c:send_seg() segN 0 segment 0 seg_off 0
mesh/util.c:print_packet() 48717.451 Clr-Net Tx: 007f000005000102a6007285cbd97716d600000000
TX: Network 0001 -> 02a6 : 053920934cd6cecf313a42ebb7bc7db15c3d0d5488 (21) : TTL 127 : SEQ 000005
mesh/util.c:print_packet() 48717.452 RX: Network [enc] :: 053920934cd6cecf313a42ebb7bc7db15c3d0d5488
mesh/util.c:print_packet() 48717.452 RX: Network [clr] :: 057f000005000102a6007285cbd97716d6

预期结果(当我使用mesh-cfgclient测试时):

[config: Target = 00aa]# composition-get 
Received dev key message (len 32):[config: 
Received DeviceCompositionStatus (len 31)
Received composion:
        Feature support:
                relay: yes
                proxy: yes
                friend: no
                lpn: no
         Element 0:
                location: 0000
                SIG defined models:
                  Model ID      0000
                  Model ID      1000
         Element 1:
                location: 0000
                SIG defined models:
                  Model ID      1000
         Element 2:
                location: 0000
                SIG defined models:
                  Model ID      1000
raspberry-pi bluetooth dbus bluez bluetooth-mesh
1个回答
0
投票

同样的问题,正在寻找解决方案=]]

© www.soinside.com 2019 - 2024. All rights reserved.