This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PyACI : auto determination of node number

Hi,

I am new to BLE Mesh development using Nordic.

I am trying to write a python script for mesh provisioning an configuration using Serial Interface.

when I am launching the command:

cc.model_app_bind(db.nodes[0].unicast_address, 0, mt.ModelId(0x1000))

Output is coming as:
Model app bind status : INVALID ADDRESS

How can I determine the node number and assign to the model_app_bind command while running the python script?

  • python interactive_pyaci.py -d /dev/ttyACM0
    db = MeshDB("database/example_database.json")
    db.provisioners
    p = Provisioner(device, db)
    p.scan_start()
    p.scan_stop()
    p.provision(name="Light_Bulb")
    cc = ConfigurationClient(db)
    device.model_add(cc)
    cc.publish_set(8, 0) 
    cc.composition_data_get()
    cc.appkey_add(0)
    cc.model_app_bind(db.nodes[0].unicast_address, 0, mt.ModelId(0x1000))
    gc = GenericOnOffClient()
    device.model_add(gc)
    gc.publish_set(0, 0)
    gc.set(True)

  • Please, I want to see also the response from PyACI when you type those commands. Please copy everything. Something like this: 

  • In [1]: db = MeshDB("database/example_database.json")
    
    In [2]: db.provisioners
    Out[2]: [{'name': 'BT Mesh Provisioner', 'UUID': _UUID(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 'allocated_unicast_range': [{'low_address': 0010, 'high_address': 7fff}], 'allocated_group_range': [{'low_address': c000, 'high_address': feff}]}]
    
    In [3]: p = Provisioner(device, db)
    
    In [4]: 2020-08-07 22:29:32,153 - INFO - ttyACM1: Success
    2020-08-07 22:29:32,155 - INFO - ttyACM1: Success
    2020-08-07 22:29:32,159 - INFO - ttyACM1: SubnetAdd: {'subnet_handle': 0}
    2020-08-07 22:29:32,163 - INFO - ttyACM1: AppkeyAdd: {'appkey_handle': 0}
    2020-08-07 22:29:32,167 - INFO - ttyACM1: AppkeyAdd: {'appkey_handle': 1}
    In [4]: p.scan_start()
    
    In [5]: 2020-08-07 22:29:46,855 - INFO - ttyACM1: Success
    2020-08-07 22:29:47,497 - INFO - ttyACM1: Received UUID 2eb87ff2f7fa436aa978749c7dad1ce0 with RSSI: -29 dB
    In [5]: p.scan_stop()
    
    In [6]: 2020-08-07 22:30:07,734 - INFO - ttyACM1: Success
    In [6]: p.provision(name="Lights")
    
    In [7]: 2020-08-07 22:30:17,295 - INFO - ttyACM1: Provision: {'context': 0}
    2020-08-07 22:30:17,349 - INFO - ttyACM1: Link established
    2020-08-07 22:30:17,429 - INFO - ttyACM1: Received capabilities
    2020-08-07 22:30:17,429 - INFO - ttyACM1: Number of elements: 1
    2020-08-07 22:30:17,432 - INFO - ttyACM1: OobUse: {'context': 0}
    2020-08-07 22:30:17,675 - INFO - ttyACM1: ECDH request received
    2020-08-07 22:30:17,683 - INFO - ttyACM1: EcdhSecret: {'context': 0}
    2020-08-07 22:30:18,117 - INFO - ttyACM1: Provisioning complete
    2020-08-07 22:30:18,117 - INFO - ttyACM1: Address(es): 0x11-0x11
    2020-08-07 22:30:18,118 - INFO - ttyACM1: Device key: 0344426c6880433d387644128d4b1897
    2020-08-07 22:30:18,118 - INFO - ttyACM1: Network key: 18eed9c2a56add85049ffc3c59ad0e12
    2020-08-07 22:30:18,118 - INFO - ttyACM1: Adding device key to subnet 0
    2020-08-07 22:30:18,119 - INFO - ttyACM1: Adding publication address of root element
    2020-08-07 22:30:18,125 - INFO - ttyACM1: DevkeyAdd: {'devkey_handle': 8}
    2020-08-07 22:30:18,127 - INFO - ttyACM1: AddrPublicationAdd: {'address_handle': 0}
    2020-08-07 22:30:18,277 - INFO - ttyACM1: Provisioning link closed
    In [7]: cc = ConfigurationClient(db)
    
    In [8]: device.model_add(cc)
    
    In [9]: cc.publish_set(8, 0)
    
    In [10]: cc.composition_data_get()
    
    In [11]: 2020-08-07 22:31:31,879 - INFO - ttyACM1: PacketSend: {'token': 1}
    2020-08-07 22:31:31,899 - INFO - ttyACM1: {event: MeshTxComplete, data: {'token': 1}}
    2020-08-07 22:31:31,980 - INFO - ttyACM1.ConfigurationClient: Received composition data (page 0x00): {
    "cid": "0059",
    "pid": "0000",
    "vid": "0000",
    "crpl": 40,
    "features": {
    "relay": 0,
    "proxy": 0,
    "friend": 0,
    "low_power": 2
    },
    "elements": [
    {
    "index": 0,
    "location": "0000",
    "models": [
    {
    "modelId": "0000"
    },
    {
    "modelId": "0002"
    },
    {
    "modelId": "1000"
    }
    ]
    }
    ]
    }
    In [11]: cc.appkey_add(0)
    
    In [12]: 2020-08-07 22:31:46,182 - INFO - ttyACM1: PacketSend: {'token': 2}
    2020-08-07 22:31:46,251 - INFO - ttyACM1: {event: MeshTxComplete, data: {'token': 2}}
    2020-08-07 22:31:46,275 - INFO - ttyACM1.ConfigurationClient: Appkey status: AccessStatus.SUCCESS
    2020-08-07 22:31:46,279 - INFO - ttyACM1.ConfigurationClient: Appkey add 0 succeded for subnet 0 at node 0011
    In [12]: cc.model_app_bind(db.nodes[0].unicast_address, 0, mt.ModelId(0x1000))
    
    In [13]: 2020-08-07 22:32:16,030 - INFO - ttyACM1: PacketSend: {'token': 3}
    2020-08-07 22:32:16,060 - INFO - ttyACM1: {event: MeshTxComplete, data: {'token': 3}}
    2020-08-07 22:32:16,087 - INFO - ttyACM1.ConfigurationClient: Model app bind status: AccessStatus.INVALID_ADDRESS

  • As you can find at line 30 you have the address 0x11. This meant there was another node provisioned before the node you posted. 
    Then when you do cc.model_app_bind(db.nodes[0].unicast_address, 0, mt.ModelId(0x1000)) it will try to bind the application key to the model on the db.nodes[0].unicast_address address. This address is most likely 0x10, not 0x11. And if there is model 0x1000 on this element (0x10) then you will receive invalid address. 

    Please either use db.nodes[1].unicast_address (or use the actual address that matches your node in this case 0x11) or check the example_database.json and remove the provisioned node (you can use the backup file). Then try again. 

Related