-
Notifications
You must be signed in to change notification settings - Fork 162
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
Switch power state persist (MEGH-2324) #79
Comments
Hey @adukale, I did not work on this yet but i have similar trouble with power states after reboots. I'll back soon with my own solution if will not shared by rainmaker angels👾 |
@adukale , I tried this out with the switch example and this indeed works for me. Here is the patch, which is similar to yours
The log shows me this message when I add the power parameter to switch. "Init" basically means that the callback was called because of a value available in persistent storage (nvs).
However, I found that there is a bug which causes the callback to be missed if you use the standard device APIs. The switch example uses the low level APIs as below, which work
However, it does not work for the below code (which is used in multi device)
The reason for this is that here, the parameter gets added before the callback gets registered. I will check how this can be fixed., Can you confirm if your observation matches with this? |
@shahpiyushv @adukale Hello guys, This is my win10 based working tags; My idf prompt warned me for *power_param
and this is esp_rmaker_standard_params.c
and my esp info lines after flashed with this line; I (16955) app_main: Received write request via : Local Need to add esp_rmaker_param_get_stored_value function for get value from nvs? 🤔 |
Hi @shahpiyushv, I tried your patch to persist gipo pin status and made the change in the switch example. I (1066) app_main: Received write request via : Init any other change is required so please point to us. I am using the latest IDF version and mobile applications Thanks, |
Correct. This doesn't work in multi device example. |
@nirmeshru , have you changed the output gpio number here? |
@shahpiyushv yes, I changed the gpio number to gpio 2. |
@shahpiyushv I can confirm the behaviour reported by @nirmeshru
But the state does not get updated. |
I think I found out an issue: I'll try to find more onto this. |
@adukale , @nirmeshru once you get the callback, the rest of the logic is in the example code itself, and not the core rainmaker functionality. Since you are getting the above prints, the "persistency" itself is working fine and clearly the issue is with the driver. I found that the culprit is this line which was causing |
@shahpiyushv Correct. Removed the line and now switch state is getting restored. Closing the issue as the same is resolved. |
I have noticed one bug lately but didn't pay attention to. The switch state persists after reboot and the state gets updated correctly in ESP Rainmaker app however the state doesn't get updated in HomeKit app. The state is always true or false which is defined here: https://github.com/espressif/esp-rainmaker/blob/master/examples/homekit_switch/main/app_main.c#L222 Is there any way to update switch status from NVS in HomeKit? |
In RainMaker, for persistent params, the write callback gets invoked. The callback not only updates the actual state of the switch and data model in RainMaker, but also updates the HomeKit data. However, during initialisation, the HomeKit update gets ignored because it is initialised after RainMaker. I think you can capture the value of power received in write_cb for ctx->src = ESP_RMAKER_REQ_SRC_INIT and pass it to |
Thank you for your response, however I am getting little bit confused. Can you share an exmaple? |
Here is a quick (but untested) patch. Please try and let us know if it works
|
Thanks for your quick response. I got your logic now but won't this apply "switch_init_state" to all switches added in this example?
I have modified set_power_state() and app_homekit_update_state() functions to accept device as parameter. With your example code the switch_init_state will be applicable for all 5 devices. |
Assuming that you have modified app_homekit_start() to initialise your HomeKit switches, you can also try calling this BEFORE you add the devices in RainMaker. This way, since the HomeKit data model will already be initialised, the app_homekit_update_state() in write_cb will ensure that the switch states are correctly updated in HomeKit, |
Actually due to oversight I had missed modifying app_homekit_start(), thanks to you I was able to find it and fix.
Then I am executing below
And finally, initializing the accessories in homekit
This seems to be working, I'll test for some time. Also, I tried executing Thanks for your kind support. |
I have modified esp_rmaker_standard_params.c with following code to add persist flag to power parameter:
But the same is not working. I have attached a relay to switch example GPIO, but after reboot power state is not retained.
Am I missing someadditional code?
Thanks is advance.
The text was updated successfully, but these errors were encountered: