Try to implement LED Blinky on Matter Template Example code.

I want to modify the example code which is provided by Matter SDK and there are several examples are there are Light bulb example code, Light Switch example code and Template code as well. Now I just right now simply wants to understand the code and modify it.


But it very complex to understand the code so can you please provide or explain the basic flow of Template like how it works. 

And also, I want to modify that code want to do some practical's like blink an LED but i did not know exactly where in that code I have to Change.

Please your help will be appreciated. 

Parents
  • Hi,

    I recommend taking a look at Adding clusters to Matter application. The part about using the ZAP tool to add clusters and attributes is not relevant for your question, but section 3 and 4 where you modify and add code are.
    The main takeaway is that you have events (in AppEvent) which are added to a queue when they happen. When an event is first in the queue and should be handled, the corresponding handler will be called. For example, you have the ButtonEvent which is added to the app event queue when a button is pressed. When it is time for this event to be handled, the function ButtonEventHandler() is called, where you can add code for what you want to happen when a specific button is pressed.

    And also, I want to modify that code want to do some practical's like blink an LED but i did not know exactly where in that code I have to Change.

    This depends on when you want the LED to blink. If you want it to blink regularly you could create use a timer similar to sFunctionTimer, and then toggle the LED in the callback.

    Best regards,
    Marte

  • Okay first of all I will take understanding of Adding clusters to Matter application and in that particular section 3 and 4.

    I am also wanting to know from you that Can you please give me some reference to get more knowledge about ZAP tool because I want to perform DHT11 Temperature sensor on Matter Light Switch Example code so in that case is there any use of ZAP tool?

  • Yes Marte that work is done.

    Now I can add new clusters as you said Matter Temperature Sensor I selected and Generate their files as well. 

    When I open callback-stub.cpp file I can See the clusters of Temperature Sensor.

    But Now I have an doubt that How can I add My PIR Sensor with the Temperature Cluster which I created.

    Also Can You me some reference about once I created the cluster of Temperature Sensor and after that at which place in code I have to modify for Implement PIR Sensor on Matter SDK.

  • Hi,

    You should test the sensor standalone before integrating it with Matter, to ensure that the sensor is working correctly and that you are able to get data from it. 
    I recommend starting with DHT: Aosong DHT Digital-output Humidity and Temperature Sensor. This is using DHT22 by default, but if you do not have the dht22 property in the overlay file, then it will use DHT11 instead.

    You will have to create an overlay file for your board (nrf52840dk_nrf52840.overlay) similar to the nrf52dk_nrf52832.overlay that is already in the sample, just with DHT11. Your overlay file should look similar to this:

    / {
    	dht11 {
    		compatible = "aosong,dht";
    		status = "okay";
    		dio-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
    	};
    };

    Best regards,
    Marte

  • Yes Marte, We done above implementation of DHT Sensor.

    We got the temperature and humidity as an Output of DHT11 Sensors that we have for it.

    Now I want to ask that how Can I Integrate it with Matter?

  • Hi,

    I recommend taking a look at the Thingy53 Matter weather station application. This is using the temperature and humidity sensor on the Thingy53 to update the temperature and humidity measurements, so it should be similar to what you are doing.

    Most of the relevant code can be found in app_task.cpp.

    The function UpdateClustersState(), calls sensor_sample_fetch() to fetch new data from the sensor. This is the same as is used in the DHT sample. If fetching sensor data was successful, it calls UpdateTemperatureClusterState() to update the MeasuredValue attribute of the Temperature Measurement cluster. UpdateClustersState() is called regularly using a timer, similar to the SensorTimer in the Adding clusters to Matter application.

    If you have followed the guide and implemented everything there, what you need to do to get the actual measurements is to change SensorMeasureHandler() to be more like the Matter weather station application as explained above. If you only want to have it as a temperature sensor and only update the Temperature Measurement cluster, you can ignore UpdateClustersState() and only add code similar to UpdateTemperatureClusterState() in your SensorMeasureHandler().

    Additionally, you must make sure to add the necessary configurations in prj.conf and nrf52840dk_nrf52840.overlay. For nrf52840dk_nrf52840.overlay you need to add dht11 as in my previous reply. In prj.conf you need to add the following:

    CONFIG_SENSOR=y
    CONFIG_GPIO=y

    Best regards,
    Marte

  • Hey  ,

    First of all Thank you for above kind and brief reply,

    Today I will follow the points and try to implement it as you mention me in above reply and then I will tell you the outcome of  it.

    At the same time I am also facing one more issue regarding Chip-Tool is that, Right now I am accessing Matter Light Bulb device using Chip-Tool which is I am Operating using My Android Mobile but now Problem is that if other user also wants to access that Matter device via there Android phone at that time they did not able to Pair it and it shows them Pairing Failed Message.

    Can You please help me on that topic as well. 

Reply
  • Hey  ,

    First of all Thank you for above kind and brief reply,

    Today I will follow the points and try to implement it as you mention me in above reply and then I will tell you the outcome of  it.

    At the same time I am also facing one more issue regarding Chip-Tool is that, Right now I am accessing Matter Light Bulb device using Chip-Tool which is I am Operating using My Android Mobile but now Problem is that if other user also wants to access that Matter device via there Android phone at that time they did not able to Pair it and it shows them Pairing Failed Message.

    Can You please help me on that topic as well. 

Children
  • Hi,

    I will assist you with that issue in your other ticket so we can keep this ticket focused on the Matter temperature sensor.

    Best regards,
    Marte

  • Hey  ,

    As you guide me in above all steps like to read Thingy Example code and then follow the steps of (Adding clusters to Matter application — nRF Connect SDK 2.4.0 documentation (nordicsemi.com).

    I followed all the steps as you told me but I got stuck at one place.

    Now when I pass the command to the Chip-Tool and below I pasted the commands which I write in Chip-Tool.

    sudo ./chip-tool-debug onoff off 12 1

    [1687858995.056301][152450:152452] CHIP:TOO: Endpoint: 1 Cluster: 0x0000_0402 Attribute 0x0000_0000 DataVersion: 721261378
    [1687858995.057259][152450:152452] CHIP:TOO:   MeasuredValue: 100
    [1687858995.057348][152450:152452] CHIP:EM: <<< [E:5165i S:18343 M:91035238 (Ack:198369677)] (S) Msg TX to 1:000000000000000F [80A3] --- Type 0000:10 (SecureChannel:StandaloneAck)
    [1687858995.057370][152450:152452] CHIP:IN: (S) Sending msg 91035238 on secure session with LSID: 18343
    [1687858995.057423][152450:152452] CHIP:EM: Flushed pending ack for MessageCounter:198369677 on exchange 5165i
    [1687858995.057470][152450:152450] CHIP:CTL: Shutting down the commissioner
    [1687858995.057476][152450:152450] CHIP:CTL: Stopping commissioning discovery over DNS-SD
    [1687858995.057481][152450:152450] CHIP:CTL: Shutting down the controller
    [1687858995.057485][152450:152450] CHIP:IN: Expiring all sessions for fabric 0x1!!
    [1687858995.057488][152450:152450] CHIP:IN: SecureSession[0x7f1598009920]: MarkForEviction Type:2 LSID:18343
    [1687858995.057491][152450:152450] CHIP:SC: SecureSession[0x7f1598009920]: Moving from state 'kActive' --> 'kPendingEviction'
    [1687858995.057495][152450:152450] CHIP:IN: SecureSession[0x7f1598009920]: Released - Type:2 LSID:18343
    [1687858995.057500][152450:152450] CHIP:FP: Forgetting fabric 0x1
    [1687858995.057506][152450:152450] CHIP:TS: Pending Last Known Good Time: 2023-06-01T07:38:45
    [1687858995.057547][152450:152450] CHIP:TS: Previous Last Known Good Time: 2023-06-01T07:38:45
    [1687858995.057550][152450:152450] CHIP:TS: Reverted Last Known Good Time to previous value
    [1687858995.057557][152450:152450] CHIP:CTL: Shutting down the commissioner
    [1687858995.057559][152450:152450] CHIP:CTL: Stopping commissioning discovery over DNS-SD
    [1687858995.057561][152450:152450] CHIP:CTL: Shutting down the controller
    [1687858995.057562][152450:152450] CHIP:CTL: Shutting down the System State, this will teardown the CHIP Stack
    [1687858995.057852][152450:152450] CHIP:DMG: All ReadHandler-s are clean, clear GlobalDirtySet
    [1687858995.057867][152450:152450] CHIP:BLE: BleConnectionDelegate::CancelConnection is not implemented.
    [1687858995.057875][152450:152450] CHIP:FP: Shutting down FabricTable
    [1687858995.057878][152450:152450] CHIP:TS: Pending Last Known Good Time: 2023-06-01T07:38:45
    [1687858995.057901][152450:152450] CHIP:TS: Previous Last Known Good Time: 2023-06-01T07:38:45
    [1687858995.057903][152450:152450] CHIP:TS: Reverted Last Known Good Time to previous value
    [1687858995.057961][152450:152450] CHIP:DL: writing settings to file (/tmp/chip_counters.ini-3n2Cs2)
    [1687858995.058074][152450:152450] CHIP:DL: renamed tmp file to file (/tmp/chip_counters.ini)
    [1687858995.058084][152450:152450] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0)
    [1687858995.058087][152450:152450] CHIP:DL: Inet Layer shutdown
    [1687858995.058090][152450:152450] CHIP:DL: BLE shutdown
    [1687858995.058094][152450:152450] CHIP:DL: System Layer shutdown

    sudo ./chip-tool-debug identify identify 10 12 1

    And After this commands I got an Error that:

    I: 34957 [SC]Received Sigma3 msg
    E: 34966 [SC]The device does not support GetClock_RealTimeMS() API: 3.  Falling back to Last Known Good UTC Time
    E: 35163 [DL]Long dispatch time: 187 ms, for event type 2
    I: 35263 [EM]<<< [E:4417r S:0 M:58029193 (Ack:51879023)] (U) Msg TX to 0:0000000000000000 [0000] --- Type 0000:40 (SecureChannel:StatusReport)
    I: 35276 [IN](U) Sending msg 58029193 to IP address 'UDP:[fd5a:d4ce:1ab2:5fa8:e99b:db8:b197:cff9]:56825'
    I: 35287 [SC]SecureSession[0x200034f8]: Moving from state 'kEstablishing' --> 'kActive'
    D: 35295 [IN]SecureSession[0x200034f8]: Activated - Type:2 LSID:25501

    So can you little bit guide me for solving this and also I want to know that what is next step for printing Temperature value from DHT11 Sensor.

  • Hi,

    I have been out of the office. Have you been able to fix the issue and get the temperature value from the sensor?

    Best regards,
    Marte

Related