mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 21:18:13 +08:00
重新打开ap
This commit is contained in:
@@ -108,7 +108,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, ELAND_AP_KEY, "MQTT.ADDR", 1883, VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, 0L);
|
||||
ap_name, ap_key, "MQTT.ADDR", 1883, VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, 0L);
|
||||
|
||||
OSStatus err = kNoErr;
|
||||
send_http(tc1_status, strlen(tc1_status), exit, &err);
|
||||
@@ -178,15 +178,22 @@ static int HttpSetWifiConfig(httpd_request_t *req)
|
||||
|
||||
int buf_size = 97;
|
||||
char *buf = malloc(buf_size);
|
||||
int mode = -1;
|
||||
char *wifi_ssid = malloc(32);
|
||||
char *wifi_key = malloc(64);
|
||||
char *wifi_key = malloc(32);
|
||||
|
||||
err = httpd_get_data(req, buf, buf_size);
|
||||
require_noerr(err, exit);
|
||||
|
||||
sscanf(buf, "%s %s", wifi_ssid, wifi_key);
|
||||
|
||||
sscanf(buf, "%d %s %s", &mode, wifi_ssid, wifi_key);
|
||||
if (mode == 1)
|
||||
{
|
||||
WifiConnect(wifi_ssid, wifi_key);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApConfig(wifi_ssid, wifi_key);
|
||||
}
|
||||
|
||||
send_http("OK", 2, exit, &err);
|
||||
|
||||
|
||||
@@ -415,18 +415,21 @@ function ChangeMode(m) {
|
||||
}
|
||||
|
||||
function ChangeInput(type) {
|
||||
if(mode != 1) {
|
||||
if (mode == 0) {
|
||||
ap_name = ssid_ipt.value;
|
||||
ap_pswd = pswd_ipt.value;
|
||||
} else {
|
||||
} else if (mode == 1) {
|
||||
station_name = ssid_ipt.value;
|
||||
station_pswd = pswd_ipt.value;
|
||||
} else {
|
||||
alert("mode error: " + mode);
|
||||
}
|
||||
}
|
||||
|
||||
//Quotation Marks
|
||||
function ContainQM(str) {
|
||||
if (str.indexOf("'") >= 0
|
||||
if (str == ""
|
||||
|| str.indexOf("'") >= 0
|
||||
|| str.indexOf('"') >= 0
|
||||
|| str.indexOf(' ') >= 0
|
||||
|| str.length > 32) {
|
||||
@@ -434,25 +437,36 @@ function ContainQM(str) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
var qm_mess = "Sorry, can't use ' or \" or space.\n\nAlso, length <= 32."
|
||||
var qm_mess = "Sorry, can't use ' or \" or space or empty.\n\nAlso, length <= 32."
|
||||
var le_mess = "Sorry, length < 8."
|
||||
|
||||
function SubmitNetwork() {
|
||||
if(mode != 1) {
|
||||
if (mode == 0) {
|
||||
if (ContainQM(ap_name) || ContainQM(ap_pswd)) {
|
||||
alert(qm_mess);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (ap_pswd.length < 8) {
|
||||
alert(le_mess);
|
||||
}
|
||||
var params = mode + " " + ap_name+" "+ap_pswd;
|
||||
} else if (mode == 1) {
|
||||
if (ContainQM(station_name) || ContainQM(station_pswd)) {
|
||||
alert(qm_mess);
|
||||
return;
|
||||
}
|
||||
var params = station_name+" "+station_pswd;
|
||||
if (station_pswd.length < 8) {
|
||||
alert(le_mess);
|
||||
}
|
||||
var params = mode + " " + station_name+" "+station_pswd;
|
||||
} else {
|
||||
alert("mode error: " + mode);
|
||||
return;
|
||||
}
|
||||
HttpPost("/wifi/config", function (re) {
|
||||
alert(re);
|
||||
}, params);
|
||||
}
|
||||
}
|
||||
|
||||
function Rescan() {
|
||||
HttpPost("/wifi/scan", function (re) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@
|
||||
#include "mico.h"
|
||||
#include "micokit_ext.h"
|
||||
|
||||
#define VERSION "v0.11.2"
|
||||
#define VERSION "v0.11.3"
|
||||
|
||||
#define TYPE 1
|
||||
#define TYPE_NAME "zTC1"
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
char wifi_status = WIFI_STATE_NOCONNECT;
|
||||
|
||||
mico_timer_t wifi_led_timer;
|
||||
IpStatus ip_status = { 0, ELAND_AP_LOCAL_IP, ELAND_AP_LOCAL_IP, ELAND_AP_NET_MASK };
|
||||
char ap_name[16];
|
||||
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)
|
||||
@@ -136,6 +137,7 @@ static void WifiLedTimerCallback(void* arg)
|
||||
|
||||
void WifiConnect(char* wifi_ssid, char* wifi_key)
|
||||
{
|
||||
os_log("WifiConnect wifi_ssid[%s] wifi_key[%s]", wifi_ssid, wifi_key);
|
||||
//wifi配置初始化
|
||||
network_InitTypeDef_st wNetConfig;
|
||||
|
||||
@@ -171,21 +173,34 @@ void WifiInit(void)
|
||||
if (!mico_rtos_is_timer_running(&wifi_led_timer)) mico_rtos_start_timer(&wifi_led_timer);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void ApInit()
|
||||
{
|
||||
sprintf(ap_name, ELAND_AP_SSID, str_mac+6);
|
||||
os_log("ApInit ap_name[%s]", ap_name);
|
||||
if (ap_name[0] == 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
network_InitTypeDef_st wNetConfig;
|
||||
memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
|
||||
strcpy((char *)wNetConfig.wifi_ssid, ap_name);
|
||||
strcpy((char *)wNetConfig.wifi_key, ELAND_AP_KEY);
|
||||
strcpy((char *)wNetConfig.wifi_key, 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);
|
||||
strcpy((char *)wNetConfig.local_ip_addr, ZZ_AP_LOCAL_IP);
|
||||
strcpy((char *)wNetConfig.net_mask, ZZ_AP_NET_MASK);
|
||||
strcpy((char *)wNetConfig.dnsServer_ip_addr, ZZ_AP_DNS_SERVER);
|
||||
micoWlanStart(&wNetConfig);
|
||||
|
||||
os_log("ApInit ssid[%s] key[%s]", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
|
||||
|
||||
@@ -13,16 +13,17 @@ enum
|
||||
WIFI_STATE_CONNECTED,
|
||||
};
|
||||
|
||||
#define ELAND_AP_SSID "TC1-AP-%s"
|
||||
#define ELAND_AP_KEY "12345678"
|
||||
#define ELAND_AP_LOCAL_IP "192.168.0.1"
|
||||
#define ELAND_AP_DNS_SERVER "192.168.0.1"
|
||||
#define ELAND_AP_NET_MASK "255.255.255.0"
|
||||
#define ZZ_AP_SSID "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"
|
||||
#define ZZ_AP_NET_MASK "255.255.255.0"
|
||||
|
||||
#define WIFI_SCAN_RESULT_JSON "{'success':%d,'ssids':[%s],'secs':[%s]}"
|
||||
extern bool scaned;
|
||||
extern char* wifi_ret;
|
||||
extern char ap_name[16];
|
||||
extern char ap_name[32];
|
||||
extern char ap_key[32];
|
||||
extern char wifi_status;
|
||||
|
||||
typedef struct {
|
||||
@@ -44,6 +45,7 @@ extern IpStatus ip_status;
|
||||
|
||||
extern void WifiInit(void);
|
||||
extern void ApInit(void);
|
||||
extern void ApConfig(char* name, char* key);
|
||||
extern void WifiConnect(char* wifi_ssid, char* wifi_key);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user