获取真实IP

This commit is contained in:
zogodo
2019-10-09 22:19:07 +08:00
parent c501a310c7
commit 0d04264da5
4 changed files with 20 additions and 13 deletions

View File

@@ -65,13 +65,10 @@ static int HttpGetTc1Status(httpd_request_t *req)
const unsigned char* sockets = GetSocketStatus();
char* ap_name = "TC1-AP";
char* ap_pwd = "12345678";
char* ip = "192.168.33.222";
char* mask = "255.255.255.0";
char* gateway = "192.168.33.1";
char* tc1_status = malloc(256);
sprintf(tc1_status, TC1_STATUS_JSON, sockets, (int)sys_config->micoSystemConfig.reserved,
sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key,
ap_name, ap_pwd, ip, mask, gateway);
ap_name, ap_pwd, ip_status.ip, ip_status.mask, ip_status.gateway);
OSStatus err = kNoErr;
send_http(tc1_status, strlen(tc1_status), exit, &err);

View File

@@ -82,20 +82,20 @@ int application_start(void)
err = mico_system_init(sys_config);
require_noerr(err, exit);
MicoGpioInitialize((mico_gpio_t) Button, INPUT_PULL_UP);
bool open_ap = false;
MicoGpioInitialize((mico_gpio_t)Button, INPUT_PULL_UP);
if (!MicoGpioInputGet(Button))
{ //开机时按钮状态
os_log("press ap_init");
ApInit();
open_ap = true;
}
bool open_ap = false;
MicoGpioInitialize((mico_gpio_t) Led, OUTPUT_PUSH_PULL);
for (i = 0; i < Relay_NUM; i++)
{
MicoGpioInitialize(Relay[i], OUTPUT_PUSH_PULL);
UserRelaySet(i, user_config->socket[i].on);
open_ap = true;
}
MicoSysLed(0);
@@ -130,13 +130,10 @@ int application_start(void)
os_log("version:%d",user_config->version);
WifiInit();
if (sys_config->micoSystemConfig.reserved != NOTIFY_STATION_UP && !open_ap)
if (!open_ap)
{
ApInit();
}
else
{
WifiConnect(sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key);
if (sys_config->micoSystemConfig.reserved != NOTIFY_STATION_UP) ApInit();
else WifiConnect(sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key);
}
user_udp_init();
KeyInit();

View File

@@ -11,10 +11,15 @@
char wifi_status = WIFI_STATE_NOCONNECT;
mico_timer_t wifi_led_timer;
IpStatus ip_status = { "0.0.0.0", "0.0.0.0", "0.0.0.0" };
//wifi已连接获取到IP地址回调
static void WifiGetIpCallback(IPStatusTypedef *pnet, void * arg)
{
strcpy(ip_status.ip, pnet->ip);
strcpy(ip_status.gateway, pnet->gate);
strcpy(ip_status.mask, pnet->mask);
os_log("got IP:%s", pnet->ip);
wifi_status = WIFI_STATE_CONNECTED;
user_function_cmd_received(1,"{\"cmd\":\"device report\"}");

View File

@@ -19,6 +19,14 @@ extern char* wifi_ret;
extern char wifi_status;
typedef struct {
char ip[16];
char gateway[16];
char mask[16];
} IpStatus;
extern IpStatus ip_status;
extern void WifiInit(void);
extern void ApInit(void);
extern void WifiConnect(char* wifi_ssid, char* wifi_key);