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

prevent to write to SDK settings if no change needed #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/wifi_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static http_parser_settings wifi_config_http_parser_settings = {


static void http_task(void *arg) {
INFO("Staring HTTP server");
INFO("Starting HTTP server");

struct sockaddr_in serv_addr;
int listenfd = socket(AF_INET, SOCK_STREAM, 0);
Expand Down Expand Up @@ -640,16 +640,23 @@ static int wifi_config_station_connect() {
INFO("Found configuration, connecting to %s", wifi_ssid);

struct sdk_station_config sta_config;
memset(&sta_config, 0, sizeof(sta_config));
strncpy((char *)sta_config.ssid, wifi_ssid, sizeof(sta_config.ssid));
sta_config.ssid[sizeof(sta_config.ssid)-1] = 0;
if (wifi_password)
strncpy((char *)sta_config.password, wifi_password, sizeof(sta_config.password));

sdk_wifi_station_set_config(&sta_config);
sdk_wifi_station_get_config(&sta_config);
//only have to set it if it is different
if (strcmp((char *)sta_config.ssid, wifi_ssid) || strcmp((char *)sta_config.password, wifi_password)) {
memset(&sta_config, 0, sizeof(sta_config));
strncpy((char *)sta_config.ssid, wifi_ssid, sizeof(sta_config.ssid));
sta_config.ssid[sizeof(sta_config.ssid)-1] = 0;
if (wifi_password)
strncpy((char *)sta_config.password, wifi_password, sizeof(sta_config.password));

sdk_wifi_station_set_config(&sta_config);
}
sdk_wifi_station_connect();
sdk_wifi_station_set_auto_connect(true);

//only have to set it if it is different
if (!sdk_wifi_station_get_auto_connect()) {
sdk_wifi_station_set_auto_connect(true);
}

free(wifi_ssid);
if (wifi_password)
Expand Down