Running python matter_server.server

Unfortunately, I cannot use HA as my base OS so I am trying to run the python-matter-server on my Pi.

Unfortunately, it fails to start effectively. I am not sure if things are not properly configured (notice the write error near the start) or there is a missing a dependence associated with chip-repl?

Prior to this I have been running chip-tool and that is having problems with --storage-directory for persistent configurations and I wonder if this might be related.

Any insight?

thanks
-brian

log follows:

pi@noble:~$ sudo python3 -m matter_server.server --log-file /home/pi/MS
2024-12-13 16:11:04.687 (MainThread) INFO [matter_server.server.stack] Initializing CHIP/Matter Logging...
2024-12-13 16:11:04.690 (MainThread) INFO [matter_server.server.stack] Initializing CHIP/Matter Controller Stack...
[1734135065.579701][47072:47072] CHIP:CTL: Setting attestation nonce to random value
[1734135065.633169][47072:47072] CHIP:CTL: Setting CSR nonce to random value
[1734135065.789149][47072:47072] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_kvs
[1734135065.791127][47072:47072] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /data/chip_factory.ini
[1734135065.791585][47072:47072] CHIP:DL: failed to open file (/data/chip_factory.ini-mW0bj7) for writing
[1734135065.791672][47072:47072] CHIP:DL: Configuration Manager initialization failed: src/platform/Linux/CHIPLinuxStorageIni.cpp:122: CHIP Error 0x000000AD: Open file failed
2024-12-13 16:11:05.792 (MainThread) ERROR [root] Uncaught exception
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/lib/python3.12/dist-packages/matter_server/server/__main__.py", line 247, in <module>
    main()
  File "/usr/local/lib/python3.12/dist-packages/matter_server/server/__main__.py", line 224, in main
    server = MatterServer(
             ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/matter_server/server/server.py", line 138, in __init__
    self.stack = MatterStack(self, bluetooth_adapter_id, enable_server_interactions)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/matter_server/server/stack.py", line 108, in __init__
    chip.native.Init(999 if bluetooth_adapter_id is None else bluetooth_adapter_id)
  File "/usr/local/lib/python3.12/dist-packages/chip/native/__init__.py", line 248, in Init
    handle.dll.pychip_CommonStackInit(ctypes.c_char_p(params)).raise_on_error()
  File "/usr/local/lib/python3.12/dist-packages/chip/native/__init__.py", line 87, in raise_on_error
    raise self.to_exception()
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/chip/native/__init__.py", line 119, in to_exception
    return chip.exceptions.ChipStackError.from_chip_error(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/chip/exceptions/__init__.py", line 48, in from_chip_error
    return cls(chip_error, str(chip_error))
                           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/chip/native/__init__.py", line 123, in __str__
    GetLibraryHandle().pychip_FormatError(ctypes.pointer(self), buf, 256)
    ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/chip/native/__init__.py", line 257, in GetLibraryHandle
    handle = _GetLibraryHandle(Library.CONTROLLER, HandleFlags.REQUIRE_INITIALIZATION in flags)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/chip/native/__init__.py", line 234, in _GetLibraryHandle
    raise Exception("CHIP handle has not been initialized!")
Exception: CHIP handle has not been initialized!
[1734135067.285938][47072:47072] CHIP:SPT: VerifyOrDie failure at src/system/SystemLayerImplSelect.h:59: mLayerState.Destroy()

1 Like

On my install ther file permission were not properly set for some reason. Make sure data folder and files has correct permissions

THANK YOU. I created /data and set its ownership to pi:pi which is how I am running the server. That seemed to allow me to write the configuration files there. (Is there a way to specify a location different than /data for the output files?)

I then hit another roadblock where chip-clusters was a different version than chip-core. I uninstalled and reinstalled and that seems ok.

fwiw, when I installed things were incomplete so I slowly built up the components. I started with a base Ubuntu with some apt packages I need and then added the following to get to where I am now. Does this seem right to you? Am I missing something that I have not yet realized?

mkdir .venv
python3 -m venv ~/.venv/general
source ~/.venv/general/bin/activate

sudo apt install cmake libcairo2-dev libdbus-glib-1-dev libgirepository1.0-dev
pip install home-assistant-chip-core
pip install home-assistant-chip-clusters
pip install cryptography
pip install python-matter-server
pip install zeroconf
mkdir /data
sudo chown pi:pi /data

python3 -m matter_server.server

I run the server in docker so I don’t deal with the details. Just simple docker run and works.

I also don’t have ipv6 on my network so trying to figure that out.