mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-11 04:28:14 +08:00
station改回ap并关闭station, 保存ap及密码到Flash
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
14
TC1/main.h
14
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user