Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

mos config won't save

Hi Everyone,

I'm trying to set wifi.sta.ssid and wifi.sta.pass to "" or NULL or BLANK and then save the config.

static void bridge_setup_erase_sta_credentials(void)
{
  /* Local variables */
  struct mgos_config_wifi_sta sta_setup;
  char *msg = NULL;

  /* Erase ssid, pass */
  mgos_wifi_disconnect(); //disconnect STA.
  memcpy(&sta_setup, mgos_sys_config_get_wifi_sta(), sizeof(sta_setup));
  sta_setup.ssid = "";
  sta_setup.pass = "";
  sta_setup.enable = false;
  if(mgos_wifi_setup_sta(&sta_setup))
  {
    LOG(LL_ERROR, ("STA credentials erased"));//debug
    save_cfg(&mgos_sys_config, &msg);//test
  } else
  {
    LOG(LL_ERROR, ("Unable to erase STA credentials"));//debug
  }
}

When I run this, the printout is STA credentials erased. But when I run mos config-get wifi from the command line, it shows up as the OLD sta.ssid and sta.pass. Can someone point out where I'm going wrong?

Many thanks!!
Andrew

Comments

  • nliviunliviu Romania

    You need to mgos_sys_config_set_wifi_* to update the members of mgos_sys_config before save_cfg.

  • edited August 1

    So basically, I should be using mgos_sys_config_get_wifi_sta() to update the members of mgos_sys_config, not mgos_config_wifi_sta?
    Is it necessary to do a reboot after save_cfg?

  • nliviunliviu Romania

    You can use struct mgos_config_wifi_sta for mgos_wifi_setup_sta as you already do.
    But to update the wifi_sta members of mgos_sys_config you should use mgos_sys_config_set_wifi_sta_enable, mgos_sys_config_set_wifi_sta_ssid, etc.
    As long as you mgos_wifi_setup_sta I don't think a reboot is necessary.

  • edited August 1

    nliviu my man, you are a legend. the mgos_sys_config_set_wifi_sta_enable, etc. method works.
    Just out of interest, where do these get/set functions originate from? They don't appear to be anywhere within the source, but are autogenerated somehow...

  • nliviunliviu Romania

    All mgos_sys_config_get_*/mgos_sys_config_set-* are in build/gen/mgos_config.c and build/gen/mgos_config.h.

Sign In or Register to comment.