删除多余, 获取保存的wifi和密码

This commit is contained in:
zogodo
2019-09-24 16:54:46 +08:00
parent 48aafdcc77
commit 1e4ca281d8
2 changed files with 8 additions and 99 deletions

View File

@@ -107,84 +107,23 @@ save_out:
return err; return err;
} }
static int web_send_result_page(httpd_request_t *req) static int http_get_wifi_config(httpd_request_t *req)
{ {
OSStatus err = kNoErr; OSStatus err = kNoErr;
bool para_succ = false;
int buf_size = 512;
char *buf;
char value_ssid[maxSsidLen];
char value_pass[maxKeyLen];
char value_user[maxNameLen];
mico_Context_t* context = NULL;
context = mico_system_context_get( ); char* status = get_socket_status();
buf = malloc(buf_size); err = httpd_send_all_header(req, HTTP_RES_200, strlen(status), HTTP_CONTENT_HTML_STR);
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status headers."));
err = httpd_get_data(req, buf, buf_size); err = httpd_send_body(req->sock, socket_status, strlen(status));
require_noerr( err, Save_Out ); require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status body."));
err = httpd_get_tag_from_post_data(buf, "SSID", value_ssid, maxSsidLen);
require_noerr( err, Save_Out );
err = httpd_get_tag_from_post_data(buf, "USER", value_user, maxNameLen);
require_noerr( err, Save_Out );
if(!strncmp(value_ssid, "\0", 1))
goto Save_Out;
if(!strncmp(value_user, "\0", 1))
goto Save_Out;
strncpy(context->micoSystemConfig.ssid, value_ssid, maxSsidLen);
strncpy(user_config->user, value_user, maxNameLen);
err = httpd_get_tag_from_post_data(buf, "PASS", value_pass, maxKeyLen);
require_noerr( err, Save_Out );
strncpy(context->micoSystemConfig.key, value_pass, maxKeyLen);
strncpy(context->micoSystemConfig.user_key, value_pass, maxKeyLen);
context->micoSystemConfig.keyLength = strlen(context->micoSystemConfig.key);
context->micoSystemConfig.user_keyLength = strlen(context->micoSystemConfig.key);
context->micoSystemConfig.channel = 0;
memset(context->micoSystemConfig.bssid, 0x0, 6);
context->micoSystemConfig.security = SECURITY_TYPE_AUTO;
context->micoSystemConfig.dhcpEnable = true;
para_succ = true;
Save_Out:
if(para_succ == true)
{
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(index_html), HTTP_CONTENT_HTML_STR);
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http index_html headers.") );
err = httpd_send_body(req->sock, index_html, sizeof(index_html));
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http index_html body.") );
context->micoSystemConfig.configured = allConfigured;
mico_system_context_update(context);
mico_system_power_perform( context, eState_Software_Reset );
}
else
{
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(index_html), HTTP_CONTENT_HTML_STR);
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http index_html headers.") );
err = httpd_send_body(req->sock, index_html, sizeof(index_html));
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http index_html body.") );
}
exit: exit:
if(buf) free(buf);
return err; return err;
} }
static int http_wifi_config(httpd_request_t *req) static int http_set_wifi_config(httpd_request_t *req)
{ {
OSStatus err = kNoErr; OSStatus err = kNoErr;
@@ -226,9 +165,8 @@ save_out:
struct httpd_wsgi_call g_app_handlers[] = { struct httpd_wsgi_call g_app_handlers[] = {
{"/", HTTPD_HDR_DEFORT, 0, http_get_index_page, NULL, NULL, NULL}, {"/", HTTPD_HDR_DEFORT, 0, http_get_index_page, NULL, NULL, NULL},
{"/result.htm", HTTPD_HDR_DEFORT, 0, NULL, web_send_result_page, NULL, NULL},
{"/socket", HTTPD_HDR_DEFORT, 0, http_get_socket_status, http_set_socket_status, NULL, NULL}, {"/socket", HTTPD_HDR_DEFORT, 0, http_get_socket_status, http_set_socket_status, NULL, NULL},
{"/wifi/config", HTTPD_HDR_DEFORT, 0, NULL, http_wifi_config, NULL, NULL}, {"/wifi/config", HTTPD_HDR_DEFORT, 0, http_get_wifi_config, http_set_wifi_config, NULL, NULL},
}; };
static int g_app_handlers_no = sizeof(g_app_handlers)/sizeof(struct httpd_wsgi_call); static int g_app_handlers_no = sizeof(g_app_handlers)/sizeof(struct httpd_wsgi_call);

View File

@@ -199,32 +199,3 @@ void ap_init()
micoWlanStart(&wNetConfig); micoWlanStart(&wNetConfig);
} }
static void Wifi_SoftAP_threed(mico_thread_arg_t arg)
{
/*
network_InitTypeDef_st wNetConfig;
mico_rtos_lock_mutex(&WifiConfigMutex);
SendElandStateQueue(APServerStart);
micoWlanSuspend();
mico_rtos_thread_sleep(2);
Eland_httpd_start();
WifiSet_log("Soft_ap_Server");
memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
strcpy((char *)wNetConfig.wifi_ssid, ELAND_AP_SSID);
strcpy((char *)wNetConfig.wifi_key, ELAND_AP_KEY);
wNetConfig.wifi_mode = Soft_AP;
wNetConfig.dhcpMode = DHCP_Server;
wNetConfig.wifi_retry_interval = 100;
strcpy((char *)wNetConfig.local_ip_addr, ELAND_AP_LOCAL_IP);
strcpy((char *)wNetConfig.net_mask, ELAND_AP_NET_MASK);
strcpy((char *)wNetConfig.dnsServer_ip_addr, ELAND_AP_DNS_SERVER);
WifiSet_log("ssid:%s key:%s", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
micoWlanStart(&wNetConfig);
mico_rtos_get_semaphore(&wifi_SoftAP_Sem, 5000);
mico_rtos_unlock_mutex(&WifiConfigMutex);
mico_rtos_delete_thread(NULL);
*/
}