/* * === FUNCTION ====================================================================== * Name: Agent_network_init * Description: Initialize agent system system connection status. * Note: This interface will check the gpio 10 level, when it was press, then * set to DirectConfig mode, else change gpio to reset button. * ===================================================================================== */ void Agent_network_init(void) { UINT8 gpio_val; int ret = 0; /* DirectConfig gpio is valied when set to low level */ BSP_GPIOPinMux(USER_GPIO_DIRECTCONFIG); BSP_GPIOSetDir(USER_GPIO_DIRECTCONFIG, GPIO_DIRECTION_INPUT); Yeelink_Init(); /* if the Directconfig button was pressed(gpio is low level), then set to Directconfig * mode. * */ gpio_val = BSP_GPIOGetValue(USER_GPIO_DIRECTCONFIG); if (gpio_val == 0) { OSTimeDly(20); /* delay 200ms, filter button shake */ gpio_val = BSP_GPIOGetValue(USER_GPIO_DIRECTCONFIG); if (gpio_val == 0) { /* Set system status */ sys_status.status = SYS_STATUS_WIFI_DIRECTCONFING; /* Directconfig mode */ ret = StartDirectConfigConn(); if (ret == 0) { /* Set system to STA mode */ sys_status.status = SYS_STATUS_WIFI_STA_CONNECTED; Agent_reset_init(); return; } } } /* If directconfig function is not triggered, initialize device reset function */ Agent_reset_init(); /* Start the Wifi connection, setup AP or Station mode according to last connection * status store in nor flash. Otherwise, switch to softap mode if connected AP * failed in station mode. * */ if (nl6621_GetConfigData(&Agent_config_data) != 0) { log_info("Get GAgentConfig Data error.\n"); } //测试用 //调试用的 #define wifissid "NUFRONT-test03"//"nu2.4" #define wifikey "nufront.iopjklbnm" //"google.com.k" Agent_config_data.flag |= XPG_CFG_FLAG_CONNECTED; memcpy(Agent_config_data.wifi_ssid,wifissid,strlen(wifissid)); Agent_config_data.wifi_ssid[strlen(wifissid)] = 0; memcpy(Agent_config_data.wifi_key,wifikey,strlen(wifikey)); Agent_config_data.wifi_key[strlen(wifikey)] = 0; //测试用 if ((Agent_config_data.flag & XPG_CFG_FLAG_CONNECTED) == XPG_CFG_FLAG_CONNECTED) { /* setup station mode */ sys_status.status = SYS_STATUS_WIFI_DIRECTCONFING; ret = DRV_WiFi_StaModeConnStart(Agent_config_data.wifi_ssid, Agent_config_data.wifi_key, 1); if (ret != 0) { /* switch to softAP mode */ goto SOFTAP; } sys_status.status = SYS_STATUS_WIFI_STA_CONNECTED; } else { /* setup softap mode */ SOFTAP: log_info("Device Working at AP mode\r\n"); DRV_WiFi_SoftAPModeStart(); sys_status.status = SYS_STATUS_WIFI_SOFTAP; } return; }
/* * === FUNCTION ====================================================================== * Name: GAgent_SetDevNetWork * Description: Start to connect to a network when used DirectConfig mode or STA mode, * otherwise, Create a network with AP mode. * Note: This interface will check the gpio 10 level, when it was press, then * set to DirectConfig mode, else read flag from norflash, and judge launch * SoftAP mode or STA mode. * ===================================================================================== */ void GAgent_SetDevNetWork(void) { UINT8 gpio_val; /* if the Directconfig button was pressed(gpio is low level), then set to Directconfig * mode. * */ gpio_val = BSP_GPIOGetValue(USER_GPIO_DIRECTCONFIG); if (gpio_val == 0) { OSTimeDly(20); /* delay 200ms filter button shake */ gpio_val = BSP_GPIOGetValue(USER_GPIO_DIRECTCONFIG); if (gpio_val == 0) { /* Set system to directConfig status */ sys_status.status = SYS_STATUS_WIFI_DIRECTCONFING; /* Launch directconfig mode */ TestDirectConfig(); g_stGAgentConfigData.flag |= XPG_CFG_FLAG_CONNECTED; nl6621_SaveConfigData(&g_stGAgentConfigData); wifiStatus = wifiStatus | WIFI_STATION_STATUS | WIFI_MODE_STATION; /* Set system to STA mode */ sys_status.status = SYS_STATUS_WIFI_STA_CONNECTED; return; } } if (nl6621_GetConfigData(&g_stGAgentConfigData) != 0) { log_info("Get GAgentConfig Data error.\n"); } /* 启动Wifi连接,根据是否获得保存数据, 决定使用AP或者Station模式 * */ if ((g_stGAgentConfigData.flag & XPG_CFG_FLAG_CONNECTED) == XPG_CFG_FLAG_CONNECTED) { //flash 里面有要加入的网络名称 /* Set system to STA status */ sys_status.status = SYS_STATUS_WIFI_DIRECTCONFING; wifiStatus |= WIFI_STATION_STATUS | WIFI_MODE_STATION; log_info("Try to connect wifi...[%08x]\n", g_stGAgentConfigData.flag); log_info("SSID: %s\n", g_stGAgentConfigData.wifi_ssid); log_info("KEY: %s\n", g_stGAgentConfigData.wifi_key); DRV_WiFi_StationCustomModeStart(g_stGAgentConfigData.wifi_ssid, g_stGAgentConfigData.wifi_key); if (wifi_sta_connect_ap_flag != 0) { /* switch to softAP mode */ goto SOFTAP; } /* Set system status to STA mode */ sys_status.status = SYS_STATUS_WIFI_STA_CONNECTED; } else { SOFTAP: wifiStatus = WIFI_MODE_AP; log_info("Connect2LateWiFi, Working at AP mode\r\n"); DRV_WiFi_SoftAPModeStart(); /* Set system status to STA mode */ sys_status.status = SYS_STATUS_WIFI_SOFTAP; } return; }