project-chip / connectedhomeip

Matter (formerly Project CHIP) creates more connections between more objects, simplifying development for manufacturers and increasing compatibility for consumers, guided by the Connectivity Standards Alliance.
https://buildwithmatter.com
Apache License 2.0
7.45k stars 1.99k forks source link

PYTHON CHIP CommissionWithCode failing in my code but works in chip-repl[Tooling] #34584

Closed mahadev-0007 closed 2 months ago

mahadev-0007 commented 3 months ago

Reproduction steps / Feature

My setup code

    def repl_controller_setup():
      chip.native.Init()
      global certificateAuthorityManager
      global chipStack
      global caList
      global dev_ctrl
      storagepath = "/tmp/controller-storage.json"
      trust_store = "./credentials/development/paa-root-certs"

      chipStack = ChipStack(persistentStoragePath=storagepath)
      certificateAuthorityManager = chip.CertificateAuthority.CertificateAuthorityManager(chipStack, chipStack.GetStorageManager())

      certificateAuthorityManager.LoadAuthoritiesFromStorage()

      if not certificateAuthorityManager.activeCaList:
          ca = certificateAuthorityManager.NewCertificateAuthority()
          ca.NewFabricAdmin(vendorId=0xFFF1, fabricId=3)
      elif not certificateAuthorityManager.activeCaList[0].adminList:
          certificateAuthorityManager.activeCaList[0].NewFabricAdmin(vendorId=0xFFF1, fabricId=3)

      caList = certificateAuthorityManager.activeCaList

      print(f"FabricId = {caList[0].adminList[0].fabricId}")

      dev_ctrl = caList[0].adminList[0].NewController(paaTrustStorePath=trust_store)

Commission code

async def commission_device(setup_code, node_id):
    await dev_ctrl.CommissionWithCode(setup_code, node_id)

Main

async def main():
    repl_controller_setup()
    print(dev_ctrl, dev_ctrl.nodeId)
    response = await commission_device(setup_code="MT:Y.K90AFN00KA0648G00", node_id=113)
    print(response)
if __name__ == "__main__":
    asyncio.run(main())

So the matter device is actually matter virtual device from google and when run this code

Failed to commission: src/controller/CHIPDeviceController.cpp:1258: CHIP Error 0x000000AC: Internal error
Traceback (most recent call last):
  File "/Users/blabla/Documents/matter/connectedhomeip/testing_out/server.py", line 107, in <module>
    asyncio.run(main())
  File "/usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/blabla/Documents/matter/connectedhomeip/testing_out/server.py", line 102, in main
    response = await commission_device(setup_code="MT:Y.K90AFN00KA0648G00", node_id=113)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/blabla/Documents/matter/connectedhomeip/testing_out/server.py", line 81, in commission_device
    await dev_ctrl.CommissionWithCode(setup_code, node_id)
  File "/Users/blabla/Documents/matter/connectedhomeip/separate/lib/python3.12/site-packages/chip/ChipDeviceCtrl.py", line 2176, in CommissionWithCode
    return await asyncio.futures.wrap_future(ctx.future)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
chip.exceptions.ChipStackError: src/controller/CHIPDeviceController.cpp:1258: CHIP Error 0x000000AC: Internal error

But when I run it with chip-repl it works perfectly. What to do

OS: Macos x64 Processor: Intel i7

Please help meeee

Platform

darwin

Platform Version(s)

No response

Type

Manually tested with SDK

(Optional) If manually tested please explain why this is only manually tested

No response

Anything else?

;)

mahadev-0007 commented 2 months ago

My bad I was dumb the trust store folder was not there i copied from the build folder and it works soryyyy