StdPJ/Core/Src/Common/Shared/iot_flash_config.c
/**
  * @brief  Write the Wifi parameters to the Flash memory.
  * @retval Error code
  *             0    Success
  *             <0   Unrecoverable error
  */
@brief  Write the Wifi parameters to the Flash memory.
@retval Error code
0    Success
<0   Unrecoverable error
@brief Write the Wifi parameters to the Flash memory . @retval Error code 0 Success <0 Unrecoverable error
int updateWiFiCredentials(void)
{
  wifi_config_t wifi_config;
  int ret = 0;
  memset(&wifi_config, 0, sizeof(wifi_config_t));
  printf("\nEnter SSID: ");
  getInputString(wifi_config.ssid, USER_CONF_WIFI_SSID_MAX_LENGTH);
  msg_info("You have entered %s as the ssid.\n", wifi_config.ssid);
  printf("\n");
  char c;
  do
  {
      printf("\rEnter Security Mode (0 - Open, 1 - WEP, 2 - WPA, 3 - WPA2): \b");
      c = getchar();
  }
  while ( (c < '0')  || (c > '3'));
  wifi_config.security_mode = c - '0';
  msg_info("\nYou have entered %d as the security mode.\n", wifi_config.security_mode);
  if (wifi_config.security_mode != 0)
  {
    printf("\nEnter password: ");
    getInputString(wifi_config.psk, sizeof(wifi_config.psk));
  }
  wifi_config.magic = USER_CONF_MAGIC;
  ret = FLASH_update((uint32_t)&lUserConfigPtr->wifi_config, &wifi_config, sizeof(wifi_config_t));
  if (ret < 0)
  {
    msg_error("Failed updating the wifi configuration in Flash.\n");
  }
  printf("\n");
  return ret;
}
int updateWiFiCredentials ( void ) { wifi_config_t wifi_config ; int ret = 0 ; memset ( & wifi_config , 0 , sizeof ( wifi_config_t ) ) ; printf ( " \n " ) ; getInputString ( wifi_config . ssid , USER_CONF_WIFI_SSID_MAX_LENGTH ) ; msg_info ( " \n " , wifi_config . ssid ) ; printf ( " \n " ) ; char c ; do { printf ( " \r \b " ) ; c = getchar ( ) ; } while ( ( c < ' ' ) || ( c > ' ' ) ) ; wifi_config . security_mode = c - ' ' ; msg_info ( " \n \n " , wifi_config . security_mode ) ; if ( wifi_config . security_mode != 0 ) { printf ( " \n " ) ; getInputString ( wifi_config . psk , sizeof ( wifi_config . psk ) ) ; } wifi_config . magic = USER_CONF_MAGIC ; ret = FLASH_update ( ( uint32_t ) & lUserConfigPtr -> wifi_config , & wifi_config , sizeof ( wifi_config_t ) ) ; if ( ret < 0 ) { msg_error ( " \n " ) ; } printf ( " \n " ) ; return ret ; }
@brief  Write the Wifi parameters to the Flash memory.
@brief Write the Wifi parameters to the Flash memory .