Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[request] Replace polling by event in Matter examples #62

Open
rei-vilo opened this issue Jun 17, 2024 · 3 comments
Open

[request] Replace polling by event in Matter examples #62

rei-vilo opened this issue Jun 17, 2024 · 3 comments
Labels
featurerequest Feature request

Comments

@rei-vilo
Copy link

Summary

In many examples, delay before two consecutive data acquisition is performed by polling.

if ((last_action_temp + 10000) < millis()) {
last_action_temp = millis();
float current_cpu_temp = getCPUTemp();
// Publish the temperature value - you can also use 'matter_temp_sensor = current_cpu_temp'
matter_temp_sensor.set_measured_value_celsius(current_cpu_temp);
Serial.printf("Current CPU temperature: %.02f C\n", current_cpu_temp);
}

This might not be especially low-power.

How to use instead an event raised by a timer? As SiLabs core for Arduino seems to rely on FreeRTOS, the RTOS elements should be already available.

Thank you!

@rei-vilo rei-vilo added the featurerequest Feature request label Jun 17, 2024
@silabs-bozont
Copy link
Collaborator

Hello @rei-vilo,

Yes, the examples use polling - so they're might not be that power efficient.
We'll look into introducing event callbacks to the library so you can block your user task and wait for Matter events to happen - it's a good idea.

@silabs-bozont
Copy link
Collaborator

Hello @rei-vilo,

I just realized what you need here is to replace the busy-looping with a simple delay() - that'll block the user task for the provided amount of time allowing the device to enter a low-power mode and also run the radio stack if necessary. We'll also introduce support for ArduinoLowPower to allow more control.

What I was thinking about is the ability to register a callback for your devices which is called when some property changes. This would allow you to block your user task and go low power until something changes - then only react to it once without constantly polling for changes. This will be very useful, so it'll be definitely coming.

@rei-vilo
Copy link
Author

rei-vilo commented Jun 17, 2024

Thank you for the suggestion.

Actually, a delay() fits perfectly if there is only one single task.

As the weather sensor can raise an interrupt, I am considering using events. This is what I did for the Low Power Home Network Weather Monitoring project based on sub-1GHz and TI-RTOS: idle mode required as little as 0.0267 mW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
featurerequest Feature request
Projects
None yet
Development

No branches or pull requests

2 participants