diff --git a/TC1/http_server/app_httpd.c b/TC1/http_server/app_httpd.c index ef81403..5f2359f 100644 --- a/TC1/http_server/app_httpd.c +++ b/TC1/http_server/app_httpd.c @@ -109,7 +109,7 @@ static int HttpGetTc1Status(httpd_request_t *req) char* tc1_status = malloc(412); sprintf(tc1_status, TC1_STATUS_JSON, sockets, ip_status.mode, sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key, - ap_name, ap_key, MQTT_SERVER, MQTT_SERVER_PORT, VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, 0L); + user_config->ap_name, user_config->ap_key, MQTT_SERVER, MQTT_SERVER_PORT, VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, 0L); OSStatus err = kNoErr; send_http(tc1_status, strlen(tc1_status), exit, &err); diff --git a/TC1/main.c b/TC1/main.c index a1d1f7d..a378949 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -72,7 +72,7 @@ int application_start(void) if (!MicoGpioInputGet(Button)) { //开机时按钮状态 os_log("press ap_init"); - ApInit(); + ApInit(false); open_ap = true; } @@ -109,7 +109,7 @@ int application_start(void) { if (sys_config->micoSystemConfig.reserved != NOTIFY_STATION_UP) { - ApInit(); + ApInit(true); } else { diff --git a/TC1/main.h b/TC1/main.h index 7ed0bdc..09adf9e 100644 --- a/TC1/main.h +++ b/TC1/main.h @@ -4,14 +4,14 @@ #include "mico.h" #include "micokit_ext.h" -#define VERSION "v1.0.14" +#define VERSION "v1.0.15" #define TYPE 1 #define TYPE_NAME "zTC1" #define ZTC1_NAME "zTC1-%s" -#define USER_CONFIG_VERSION 5 +#define USER_CONFIG_VERSION 6 #define SETTING_MQTT_STRING_LENGTH_MAX 32 //必须4字节对齐。 #define SOCKET_NAME_LENGTH 32 @@ -36,13 +36,15 @@ typedef struct { char version; - char mqtt_ip[SETTING_MQTT_STRING_LENGTH_MAX]; //mqtt service ip - int mqtt_port; //mqtt service port - char mqtt_user[SETTING_MQTT_STRING_LENGTH_MAX]; //mqtt service user - char mqtt_password[SETTING_MQTT_STRING_LENGTH_MAX]; //mqtt service user + char mqtt_ip[SETTING_MQTT_STRING_LENGTH_MAX]; + int mqtt_port; + char mqtt_user[SETTING_MQTT_STRING_LENGTH_MAX]; + char mqtt_password[SETTING_MQTT_STRING_LENGTH_MAX]; char socket_status[SOCKET_NUM]; //记录当前开关 char user[maxNameLen]; WiFiEvent last_wifi_status; + char ap_name[32]; + char ap_key[32]; } user_config_t; extern char rtc_init; diff --git a/TC1/user_wifi.c b/TC1/user_wifi.c index bfa455f..46c8d0f 100644 --- a/TC1/user_wifi.c +++ b/TC1/user_wifi.c @@ -11,8 +11,6 @@ char wifi_status = WIFI_STATE_NOCONNECT; mico_timer_t wifi_led_timer; IpStatus ip_status = { 0, ZZ_AP_LOCAL_IP, ZZ_AP_LOCAL_IP, ZZ_AP_NET_MASK }; -char ap_name[32] = { 0 }; -char ap_key[32] = { 0 }; //wifi已连接获取到IP地址回调 static void WifiGetIpCallback(IPStatusTypedef *pnet, void * arg) @@ -50,7 +48,7 @@ static void WifiStatusCallback(WiFiEvent status, void* arg) sys_config->micoSystemConfig.reserved = status; mico_system_context_update(sys_config); - ApInit(); //打开AP + ApInit(false); //打开AP wifi_status = WIFI_STATE_NOCONNECT; if (!mico_rtos_is_timer_running(&wifi_led_timer)) @@ -174,26 +172,27 @@ void WifiInit(void) void ApConfig(char* name, char* key) { - strncpy(ap_name, name, 32); - strncpy(ap_key, key, 32); - os_log("ApConfig ap_name[%s] ap_key[%s]", ap_name, ap_key); - ApInit(); - //TODO 保存ap及密码到Flash + strncpy(user_config->ap_name, name, 32); + strncpy(user_config->ap_key, key, 32); + os_log("ApConfig ap_name[%s] ap_key[%s]", user_config->ap_name, user_config->ap_key); + micoWlanSuspendStation(); + ApInit(false); + mico_system_context_update(sys_config); } -void ApInit() +void ApInit(bool use_defaul) { - if (ap_name[0] == 0) + if (use_defaul) { - sprintf(ap_name, ZZ_AP_SSID, str_mac + 6); - sprintf(ap_key, "%s", ZZ_AP_KEY); - os_log("ApInit ap_name[%s] ap_key[%s]", ap_name, ap_key); + sprintf(user_config->ap_name, ZZ_AP_NAME, str_mac + 6); + sprintf(user_config->ap_key, "%s", ZZ_AP_KEY); + os_log("ApInit ap_name[%s] ap_ke[%s]", user_config->ap_name, user_config->ap_key); } network_InitTypeDef_st wNetConfig; memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st)); - strcpy((char *)wNetConfig.wifi_ssid, ap_name); - strcpy((char *)wNetConfig.wifi_key, ap_key); + strcpy((char *)wNetConfig.wifi_ssid, user_config->ap_name); + strcpy((char *)wNetConfig.wifi_key, user_config->ap_key); wNetConfig.wifi_mode = Soft_AP; wNetConfig.dhcpMode = DHCP_Server; wNetConfig.wifi_retry_interval = 100; diff --git a/TC1/user_wifi.h b/TC1/user_wifi.h index c95c586..8b0e16d 100644 --- a/TC1/user_wifi.h +++ b/TC1/user_wifi.h @@ -13,7 +13,7 @@ enum WIFI_STATE_CONNECTED, }; -#define ZZ_AP_SSID "TC1-AP-%s" +#define ZZ_AP_NAME "TC1-AP-%s" #define ZZ_AP_KEY "12345678" #define ZZ_AP_LOCAL_IP "192.168.0.1" #define ZZ_AP_DNS_SERVER "192.168.0.1" @@ -22,8 +22,6 @@ enum #define WIFI_SCAN_RESULT_JSON "{'success':%d,'ssids':[%s],'secs':[%s]}" extern bool scaned; extern char* wifi_ret; -extern char ap_name[32]; -extern char ap_key[32]; extern char wifi_status; typedef struct { @@ -44,7 +42,7 @@ typedef struct { extern IpStatus ip_status; extern void WifiInit(void); -extern void ApInit(void); +extern void ApInit(bool use_defaul); extern void ApConfig(char* name, char* key); extern void WifiConnect(char* wifi_ssid, char* wifi_key); diff --git a/TODO.txt b/TODO.txt index fe5c652..d51c3b6 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,10 +1,6 @@ 1. 登录 -2. station改回ap并关闭station 3. 删除定时任务 -4. 保存ap及密码到Flash 5. 重复定时任务 -6. 去掉C_Json -7. 去除user_udp 8. 统一os_log 9. 更新web socket状态