Adding support for a proprietary protocol
The Matter Bridge architecture describes the two sides of bridging relationship, Matter Bridged Device and Bridged Device Data Provider.
The Matter Bridged Device represents the side that natively supports Matter, and the Bridged Device Data Provider represents a non-Matter interface.
It is not specified what protocol should be used for a Bridged Device Data Provider role.
The Matter Bridge application supports bridging Matter to Bluetooth® LE data providers that use the Bluetooth LE protocol to communicate with physical end devices, and simulated data providers that emulate real devices behavior in the application. You can add support for any protocol as long as you are able to describe data model translation between Matter and that protocol.
To provide support for a new protocol, you have to implement the Bridged Device Data Provider role that is able to communicate with the physical end devices using that protocol.
The interactions to be implemented by the Bridged Device Data Provider vary depending on the bridged Matter device type.
Typically the Bridged Device Data Provider has to provide up-to-date information about the device’s state by pushing notification about the state changes.
This allows updating the Matter Data Model state and also enables handling Matter subscriptions.
The subscription handling can be implemented either by utilizing the implemented protocol’s native support for pushing notifications by the end device, or by performing periodic data polling, which is less efficient.
If the Matter device can perform write operations or be controlled using Matter invoke command operations, the Bridged Device Data Provider shall be able to send appropriate information to the physical end device.
Complete the following steps to add support for a proprietary protocol:
Create a
MyProtocol Data Providerclass that inherits from theBridged Device Data Providerclass. This class should contain all the data and logic used by all your bridged devices. For reference, see the implementation in thesrc/ble/data_providers/ble_bridged_device.hfile.For each bridged device type, create a
MyProtocol MyDevice Data Providerclass that inherits from theMyProtocol Data Providerclass. These classes keep the state of the Matter device synchronized with the state of the device, using the following functions:NotifyUpdateState()- Called to notify the bridge when the bridged device changed state.UpdateState()- Called by the bridge when the bridged device should update its state (for example, turning a light on or off).
Create a
MyProtocol Connectivity Managerclass that holds information about all current connections of the bridged device. This class must implement the following functions:CHIP_ERROR AddMyProtocolProvider(MyProtocolBridgedDeviceProvider *provider, const MyProtocolId &deviceId); CHIP_ERROR RemoveMyProtocolProvider(const MyProtocolId &deviceId); MyProtocolBridgedDeviceProvider *FindMyProtocolProvider(const MyProtocolId &deviceId);
This class takes care of any connection-related code that your protocol needs.
Create a
MyProtocol Bridged Device Factoryclass that handles device creation, storage, and removal.Adapt the main application to use your newly created classes. Create a new
BRIDGED_DEVICE_MY_PROTOCOLconfiguration, go through the application code and find where theCONFIG_BRIDGED_DEVICE_BTKconfig option is used by the preprocessor. Add support for your protocol in the found instances.
An application with support for MyProtocol would work like this:
The application reads the stored devices and creates them using the
MyProtocol Bridged Device Factoryclass.To bridge new devices, the application needs to know their
MyProtocolconnection details. Those details can be provided by the user or obtained through device discovery. To enable this, implement the necessary shell commands in thesrc/bridge_shell.cppfile.Using the
MyProtocol Bridged Device Factoryclass and knowing the connection details, the application creates and stores new bridged devices. You can use theMyProtocol Connectivity Managerclass to map theMyProtocoldevice ID to the correspondingMyProtocol Device Data Providerinstance.Matter traffic is routed through the
MyProtocol MyDevice Data Providerclass. When data from the device is received, you can use theMyProtocol Connectivity Managerclass to forward the data to the correctMyProtocol MyDevice Data Providerinstance.If a device must be removed, the
MyProtocol Bridged Device Factoryclass handles it.