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?

Parents
  • HI Zolu, 
    Could you post the full log ? 
    Have you followed the instruction here : https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.meshsdk.v4.2.0/md_scripts_interactive_pyaci_doc_demo_configuration.html?cp=7_2_2_4_8_1_2 ? 


    db.node[0].unicast_address is stored in the db .jason file when you call db = MeshDB("database/example_database.json") for example. 

  • Hi

    I have followed the instructions.

    Sharing the log.

    [{'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}]}]
    RX: 04810200fe
    parsed_packet {event: DeviceStarted, data: {'operating_mode': 2, 'hw_error': 0, 'data_credit_available': 254}}
    Device rebooted.
    TX: 61697fcb8c4071fc2c55d748dba1d44e28639bf9034428dde111549951d9d6b596f25e4300c6cac7ca8cffc71019888c5655136afbe6f1385ba3c0da57599b7ad7ab065fb70b44ee97f8bddff027e1d94b2a2f199fe295c512a54e74e9332f561609
    TX: 059f01000100
    RX: 03846900
    parsed_packet {event: CmdRsp, data: {'opcode': 105, 'status': 0, 'data': ''}}
    Success
    TX: 1392000018eed9c2a56add85049ffc3c59ad0e12
    RX: 03849f00
    parsed_packet {event: CmdRsp, data: {'opcode': 159, 'status': 0, 'data': ''}}
    Success
    TX: 1597000000004f68ad85d9f48ac8589df665b6b49b8a
    RX: 058492000000
    parsed_packet {event: CmdRsp, data: {'opcode': 146, 'status': 0, 'data': ''}}
    SubnetAdd: {'subnet_handle': 0}
    TX: 1597010000002aa2a6ded5a0798ceab5787ca3ae39fc
    RX: 058497000000
    parsed_packet {event: CmdRsp, data: {'opcode': 151, 'status': 0, 'data': ''}}
    AppkeyAdd: {'appkey_handle': 0}
    TX: 0161
    RX: 058497000100
    parsed_packet {event: CmdRsp, data: {'opcode': 151, 'status': 0, 'data': ''}}
    AppkeyAdd: {'appkey_handle': 1}
    RX: 03846100
    parsed_packet {event: CmdRsp, data: {'opcode': 97, 'status': 0, 'data': ''}}
    Success
    RX: 1ac02eb87ff2f7fa436aa978749c7dad1ce0ca0001e978749c7ded
    parsed_packet {event: ProvUnprovisionedReceived, data: {'uuid': '2eb87ff2f7fa436aa978749c7dad1ce0', 'rssi': -54, 'gatt_supported': 0, 'adv_addr_type': 1, 'adv_addr': 'e978749c7ded'}}
    Received UUID 2eb87ff2f7fa436aa978749c7dad1ce0 with RSSI: -54 dB
    RX: 1ac02eb87ff2f7fa436aa978749c7dad1ce0ca0001e978749c7ded
    parsed_packet {event: ProvUnprovisionedReceived, data: {'uuid': '2eb87ff2f7fa436aa978749c7dad1ce0', 'rssi': -54, 'gatt_supported': 0, 'adv_addr_type': 1, 'adv_addr': 'e978749c7ded'}}
    RX: 1ac02eb87ff2f7fa436aa978749c7dad1ce0cd0001e978749c7ded
    parsed_packet {event: ProvUnprovisionedReceived, data: {'uuid': '2eb87ff2f7fa436aa978749c7dad1ce0', 'rssi': -51, 'gatt_supported': 0, 'adv_addr_type': 1, 'adv_addr': 'e978749c7ded'}}
    RX: 1ac02eb87ff2f7fa436aa978749c7dad1ce0c30001e978749c7ded
    parsed_packet {event: ProvUnprovisionedReceived, data: {'uuid': '2eb87ff2f7fa436aa978749c7dad1ce0', 'rssi': -61, 'gatt_supported': 0, 'adv_addr_type': 1, 'adv_addr': 'e978749c7ded'}}
    RX: 1ac02eb87ff2f7fa436aa978749c7dad1ce0c40001e978749c7ded
    parsed_packet {event: ProvUnprovisionedReceived, data: {'uuid': '2eb87ff2f7fa436aa978749c7dad1ce0', 'rssi': -60, 'gatt_supported': 0, 'adv_addr_type': 1, 'adv_addr': 'e978749c7ded'}}
    TX: 0162
    TX: 2d63002eb87ff2f7fa436aa978749c7dad1ce018eed9c2a56add85049ffc3c59ad0e120000000000001700000000
    RX: 03846200
    parsed_packet {event: CmdRsp, data: {'opcode': 98, 'status': 0, 'data': ''}}
    Success
    RX: 0484630000
    parsed_packet {event: CmdRsp, data: {'opcode': 99, 'status': 0, 'data': ''}}
    Provision: {'context': 0}
    RX: 02c100
    parsed_packet {event: ProvLinkEstablished, data: {'context_id': 0}}
    Link established
    RX: 0bc300010001000000000000
    parsed_packet {event: ProvCapsReceived, data: {'context_id': 0, 'num_elements': 1, 'public_key_type': 0, 'static_oob_types': 1, 'output_oob_size': 0, 'output_oob_actions': 0, 'input_oob_size': 0, 'input_oob_actions': 0}}
    Received capabilities
    Number of elements: 1
    TX: 056600000000
    RX: 0484660000
    parsed_packet {event: CmdRsp, data: {'opcode': 102, 'status': 0, 'data': ''}}
    OobUse: {'context': 0}
    RX: 62c700e9609b24f99abf6de016abc0d944c05eb2af8e087c8119d9ee164cadc5891f9c0247dcd9244a1681375893868bd25b617285efdd4f089d13b9fe4371cc8011a87fcb8c4071fc2c55d748dba1d44e28639bf9034428dde111549951d9d6b596f2
    parsed_packet {event: ProvEcdhRequest, data: {'context_id': 0, 'peer_public': 'e9609b24f99abf6de016abc0d944c05eb2af8e087c8119d9ee164cadc5891f9c0247dcd9244a1681375893868bd25b617285efdd4f089d13b9fe4371cc8011a8', 'node_private': '7fcb8c4071fc2c55d748dba1d44e28639bf9034428dde111549951d9d6b596f2'}}
    ECDH request received
    TX: 226800b69e7419cdad09316a5a2533dac355e227fff83a334f49324a640d775838c6ba
    RX: 0484680000
    parsed_packet {event: CmdRsp, data: {'opcode': 104, 'status': 0, 'data': ''}}
    EcdhSecret: {'context': 0}
    RX: 2cc50000000000000017000000adc55eff8f93a1acce9bf4914a85072f18eed9c2a56add85049ffc3c59ad0e12
    parsed_packet {event: ProvComplete, data: {'context_id': 0, 'iv_index': 0, 'net_key_index': 0, 'address': 23, 'iv_update_flag': 0, 'key_refresh_flag': 0, 'device_key': 'adc55eff8f93a1acce9bf4914a85072f', 'net_key': '18eed9c2a56add85049ffc3c59ad0e12'}}
    Provisioning complete
            Address(es): 0x17-0x17
            Device key: adc55eff8f93a1acce9bf4914a85072f
            Network key: 18eed9c2a56add85049ffc3c59ad0e12
    Adding device key to subnet 0
    Adding publication address of root element
    TX: 159c17000000adc55eff8f93a1acce9bf4914a85072f
    TX: 03a41700
    RX: 05849c000800
    parsed_packet {event: CmdRsp, data: {'opcode': 156, 'status': 0, 'data': '}}
    DevkeyAdd: {'devkey_handle': 8}
    RX: 0584a4000000
    parsed_packet {event: CmdRsp, data: {'opcode': 164, 'status': 0, 'data': ''}}
    AddrPublicationAdd: {'address_handle': 0}
    RX: 03c20000
    parsed_packet {event: ProvLinkClosed, data: {'context_id': 0, 'close_reason': 0}}
    Provisioning link closed
    Sending opcode: 8008, data: 00
    TX: 0eab08000100000008000000800800
    RX: 0784ab0001000000
    parsed_packet {event: CmdRsp, data: {'opcode': 171, 'status': 0, 'data': ''}}
    PacketSend: {'token': 1}
    RX: 05d201000000
    parsed_packet {event: MeshTxComplete, data: {'token': 1}}
    {event: MeshTxComplete, data: {'token': 1}}
    RX: 2ad017000100080000000401e978749c7dedbf160002005900000000002800070000000300000002000010
    parsed_packet {event: MeshMessageReceivedUnicast, data: {'src': 23, 'dst': 1, 'appkey_handle': 8, 'subnet_handle': 0, 'ttl': 4, 'adv_addr_type': 1, 'adv_addr': 'e978749c7ded', 'rssi': -65, 'actual_length': 22, 'data': 'Y('}}
    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"
            }
          ]
        }
      ]
    }
    Sending opcode: 00, data: 0000004f68ad85d9f48ac8589df665b6b49b8a
    TX: 1fab08000100000008000000000000004f68ad85d9f48ac8589df665b6b49b8a
    RX: 0784ab0002000000
    parsed_packet {event: CmdRsp, data: {'opcode': 171, 'status': 0, 'data': ''}}
    PacketSend: {'token': 2}
    RX: 05d202000000
    parsed_packet {event: MeshTxComplete, data: {'token': 2}}
    {event: MeshTxComplete, data: {'token': 2}}
    RX: 1ad017000100080000000401e978749c7dedbe0600800300000000
    parsed_packet {event: MeshMessageReceivedUnicast, data: {'src': 23, 'dst': 1, 'appkey_handle': 8, 'subnet_handle': 0, 'ttl': 4, 'adv_addr_type': 1, 'adv_addr': 'e978749c7ded', 'rssi': -66, 'actual_length': 6, 'data': '800300000000'}}
    Appkey status: AccessStatus.SUCCESS
    Appkey add 0 succeded for subnet 0 at node 0017
    Sending opcode: 803d, data: 100000000010
    TX: 13ab08000100000008000000803d100000000010
    RX: 0784ab0003000000
    parsed_packet {event: CmdRsp, data: {'opcode': 171, 'status': 0, 'data': ''}}
    PacketSend: {'token': 3}
    RX: 05d203000000
    parsed_packet {event: MeshTxComplete, data: {'token': 3}}
    {event: MeshTxComplete, data: {'token': 3}}
    RX: 1dd017000100080000000401e978749c7dedc20900803e01100000000010
    parsed_packet {event: MeshMessageReceivedUnicast, data: {'src': 23, 'dst': 1, 'appkey_handle': 8, 'subnet_handle': 0, 'ttl': 4, 'adv_addr_type': 1, 'adv_addr': 'e978749c7ded', 'rssi': -62, 'actual_length': 9, 'data': '803e01100000000010'}}
    Model app bind status: AccessStatus.INVALID_ADDRESS
    Sending opcode: 8202, data: 0100
    TX: 0fab0000010000000800000082020100
    RX: 0784ab0004000000
    parsed_packet {event: CmdRsp, data: {'opcode': 171, 'status': 0, 'data': ''}}
    PacketSend: {'token': 4}
    RX: 05d204000000
    parsed_packet {event: MeshTxComplete, data: {'token': 4}}
    {event: MeshTxComplete, data: {'token': 4}}

  • Could you post the script log where you type the commands in PyACI ? 

  • Hi Hung,

    First time when I am trying with a node it's getting an unicast address which is getting stored in example_database.json file. On reflashing the same nrf52 DK and running the script a different unicast address is assigned to the node.

    So first time on launching the command:

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

    it works fine.Next time if I reflash the same board and launch the same command it gives an error:

    Model app bind status: AccessStatus.INVALID_ADDRESS
  • Can you just post the whole thing before and after you type cc.model_app_bind ? 

Reply Children
  • 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