espressif / esp-rainmaker

ESP RainMaker Agent for firmware development
Apache License 2.0
433 stars 146 forks source link

Switch rename issue (MEGH-3719) #152

Open sijoalexjohnson opened 1 year ago

sijoalexjohnson commented 1 year ago

in the ESP32 firmware if we name the Switch as Switch1. After connecting to the mobile APP if we change the Switch name to Light it reflect in the APP. after restarting the ESP32 hardware . the App shows previous name Switch 1 only. how to solve this issue. Can you update this in the next version.

Switch name is Switch 1 1 2 Renamed Switch 1 name as Light 3 4 After reboot the esp32 hardware . App shows previous name
5

shahpiyushv commented 1 year ago

@sijoalexjohnson , are you using the default switch example as it is, or is it some modified code?

sijoalexjohnson commented 1 year ago

Im using arduino code in the esp32.

I think arduino rainmaker example code have this issue. Using esp-idf its working fine

sanketwadekar commented 1 year ago

Hi @sijoalexjohnson, This issue arises because, in the Switch example, the variable my_switch is initialized outside the setup() function. The statement static Switch my_switch("Switch", &gpio_switch); creates all parameters (name, power) and tries to read their stored values from nvs before nvs has been initialized. Hence, it does not read the name from storage on reboot.

To fix this, you need to make the following changes:

  1. Variable declaration: static Switch my_switch;
  2. Add the following statement in your setup() function
    void setup()
    {
    my_switch = Switch("Switch", &gpio_switch);
    // Existing Code
    }

I've tested this on ESP32 using Arduino Switch Example.

Best Regards, Sanket

sijoalexjohnson commented 1 year ago

Hi @sanketwadekar Thanks. i have tested, its working fine. Regards SijO