mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 21:48:25 +08:00
返回扫描结果
This commit is contained in:
@@ -148,10 +148,22 @@ exit:
|
|||||||
|
|
||||||
static int http_get_wifi_scan(httpd_request_t *req)
|
static int http_get_wifi_scan(httpd_request_t *req)
|
||||||
{
|
{
|
||||||
static int n = 1;
|
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
if (scaned)
|
||||||
|
{
|
||||||
|
scaned = false;
|
||||||
|
send_http(wifi_ret, strlen(wifi_ret), exit, &err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
send_http("NO", 2, exit, &err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
static int n = 1;
|
||||||
char* re = (n++)%4 == 0 ? "OK" : "NO";
|
char* re = (n++)%4 == 0 ? "OK" : "NO";
|
||||||
send_http(re, 2, exit, &err);
|
send_http(re, 2, exit, &err);
|
||||||
|
*/
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
*(P_ERR) = httpd_send_body(req->sock, (const unsigned char*)DATA, LEN); \
|
*(P_ERR) = httpd_send_body(req->sock, (const unsigned char*)DATA, LEN); \
|
||||||
require_noerr_action(*(P_ERR), LABEL, app_httpd_log("ERROR: Unable to send http DATA body.")); \
|
require_noerr_action(*(P_ERR), LABEL, app_httpd_log("ERROR: Unable to send http DATA body.")); \
|
||||||
|
|
||||||
#define TC1_STATUS_JSON \
|
#define TC1_STATUS_JSON \
|
||||||
"{\
|
"{\
|
||||||
'sockets':'%s',\
|
'sockets':'%s',\
|
||||||
'mode':%d,\
|
'mode':%d,\
|
||||||
|
|||||||
@@ -333,7 +333,8 @@ function Rescan() {
|
|||||||
|
|
||||||
function GetScanResult() {
|
function GetScanResult() {
|
||||||
HttpGet("/wifi/scan", function (re) {
|
HttpGet("/wifi/scan", function (re) {
|
||||||
if (re == "OK") {
|
if (re != "NO") {
|
||||||
|
var ret = JSON.parse(re);
|
||||||
rescan_btn.innerHTML = "Rescan";
|
rescan_btn.innerHTML = "Rescan";
|
||||||
rescan_btn.disabled = false;
|
rescan_btn.disabled = false;
|
||||||
return;
|
return;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -73,10 +73,35 @@ static void wifi_status_callback(WiFiEvent status, void* arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool scaned = false;
|
||||||
|
char* wifi_ret = NULL;
|
||||||
//wifi扫描结果回调
|
//wifi扫描结果回调
|
||||||
void wifi_scan_callback(ScanResult *pApList, mico_Context_t * const inContext)
|
void wifi_scan_callback(ScanResult_adv* scan_ret, void* arg)
|
||||||
{
|
{
|
||||||
os_log("wifi_scan_callback ApNum[%d] ApList[0](%s)", (int)pApList[0].ApNum, pApList[0].ApList[0].ssid);
|
int count = (int)scan_ret->ApNum;
|
||||||
|
os_log("wifi_scan_callback ApNum[%d] ApList[0](%s)", count, scan_ret->ApList[0].ssid);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
wifi_ret = malloc(sizeof(char)*count * (32 + 2) + 50);
|
||||||
|
char* ssids = malloc(sizeof(char)*count * 32);
|
||||||
|
char* secs = malloc(sizeof(char)*count * 2);
|
||||||
|
char* tmp1 = ssids;
|
||||||
|
char* tmp2 = secs;
|
||||||
|
for (; i < count; i++)
|
||||||
|
{
|
||||||
|
sprintf(tmp1, "'%s',", scan_ret->ApList[i].ssid);
|
||||||
|
tmp1 += (strlen(scan_ret->ApList[i].ssid) + 3);
|
||||||
|
|
||||||
|
sprintf(tmp2, "%d,", scan_ret->ApList[i].security);
|
||||||
|
tmp2 += 2;
|
||||||
|
}
|
||||||
|
*(--tmp1) = 0;
|
||||||
|
*(--tmp2) = 0;
|
||||||
|
|
||||||
|
sprintf(wifi_ret, WIFI_SCAN_RESULT_JSON, 1, ssids, secs);
|
||||||
|
|
||||||
|
scaned = true;
|
||||||
|
free(ssids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,8 +166,8 @@ void wifi_init(void)
|
|||||||
//wifi连接状态改变回调
|
//wifi连接状态改变回调
|
||||||
mico_system_notify_register(mico_notify_WIFI_STATUS_CHANGED, (void*) wifi_status_callback, NULL);
|
mico_system_notify_register(mico_notify_WIFI_STATUS_CHANGED, (void*) wifi_status_callback, NULL);
|
||||||
//wifi扫描结果回调
|
//wifi扫描结果回调
|
||||||
mico_system_notify_register(mico_notify_WIFI_SCAN_COMPLETED, (void*)wifi_scan_callback, NULL);
|
mico_system_notify_register(mico_notify_WIFI_SCAN_ADV_COMPLETED, (void*)wifi_scan_callback, NULL);
|
||||||
|
|
||||||
//sntp_init();
|
//sntp_init();
|
||||||
//启动定时器开始进行wifi连接
|
//启动定时器开始进行wifi连接
|
||||||
if (!mico_rtos_is_timer_running(&wifi_led_timer)) mico_rtos_start_timer(&wifi_led_timer);
|
if (!mico_rtos_is_timer_running(&wifi_led_timer)) mico_rtos_start_timer(&wifi_led_timer);
|
||||||
|
|||||||
@@ -2,16 +2,34 @@
|
|||||||
#define __USER_WIFI_H_
|
#define __USER_WIFI_H_
|
||||||
|
|
||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
|
#include "mico_wlan.h"
|
||||||
#include "micokit_ext.h"
|
#include "micokit_ext.h"
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
WIFI_STATE_FAIL,
|
WIFI_STATE_FAIL,
|
||||||
WIFI_STATE_NOCONNECT,
|
WIFI_STATE_NOCONNECT,
|
||||||
WIFI_STATE_CONNECTING,
|
WIFI_STATE_CONNECTING,
|
||||||
WIFI_STATE_CONNECTED,
|
WIFI_STATE_CONNECTED,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
typedef struct _WifiResult
|
||||||
|
{
|
||||||
|
char ssid[32];
|
||||||
|
wlan_sec_type_t security;
|
||||||
|
}
|
||||||
|
WifiResult;
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define WIFI_SCAN_RESULT_JSON "{'success':%d,'ssids':[%s],'secs':[%s]}"
|
||||||
|
|
||||||
|
extern char* wifi_ret;
|
||||||
|
|
||||||
extern char wifi_status;
|
extern char wifi_status;
|
||||||
|
extern bool scaned;
|
||||||
|
//extern WifiResult* wifi_rets;
|
||||||
|
|
||||||
extern void wifi_init(void);
|
extern void wifi_init(void);
|
||||||
extern void ap_init(void);
|
extern void ap_init(void);
|
||||||
extern void wifi_connect(char* wifi_ssid, char* wifi_key);
|
extern void wifi_connect(char* wifi_ssid, char* wifi_key);
|
||||||
|
|||||||
Reference in New Issue
Block a user