我根据httpserver的这个例程写了个用smartconfig连接外部路由器的程序在cc3200 launchpad上运行,但是麻烦的是每次断电再插上都要重新使用smartconfig配置连接。
我对httpserver的修改主要是下边这块:
static int g_iWlanAccess = -1; //初始化
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
...
case SL_WLAN_CONNECT_EVENT:
{
SET_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
//
// Information about the connected AP (like name, MAC etc) will be
// available in 'slWlanConnectAsyncResponse_t'-Applications
// can use it if required
//
// slWlanConnectAsyncResponse_t *pEventData = NULL;
// pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
//
// Copy new connection SSID and BSSID to global parameters
memcpy(g_ucConnectionSSID,pWlanEvent->EventData.
STAandP2PModeWlanConnected.ssid_name,
pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len);
memcpy(g_ucConnectionBSSID,
pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid,
SL_BSSID_LENGTH);
UART_PRINT("[WLAN EVENT] STA Connected to the AP: %s ,"
"BSSID: %x:%x:%x:%x:%x:%x\n\r",
g_ucConnectionSSID,g_ucConnectionBSSID[0],
g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
g_ucConnectionBSSID[5]);
g_iWlanAccess = 0; // 在这里将g_iWlanAccess设置为0
}
....
在static long ConfigureSimpleLinkToDefaultState()中,我期待的是在一开始调用sl_Start的时候就会将g_iWlanAccess设置为0,所以在下边添加了一个判断:
UART_PRINT("Host Driver Version: %s\n\r",SL_DRIVER_VERSION);
UART_PRINT("Build Version %d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d\n\r",
ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3],
ver.ChipFwAndPhyVersion.FwVersion[0],ver.ChipFwAndPhyVersion.FwVersion[1],
ver.ChipFwAndPhyVersion.FwVersion[2],ver.ChipFwAndPhyVersion.FwVersion[3],
ver.ChipFwAndPhyVersion.PhyVersion[0],ver.ChipFwAndPhyVersion.PhyVersion[1],
ver.ChipFwAndPhyVersion.PhyVersion[2],ver.ChipFwAndPhyVersion.PhyVersion[3]);
if (g_iWlanAccess == 0) // 如果已经连上了路由器AP,不在继续设置smartconfig
{
return lRetVal;
}
// Set connection policy to Auto + SmartConfig
// (Device's default connection policy)
lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0);
ASSERT_ON_ERROR(lRetVal);
// Remove all profiles
lRetVal = sl_WlanProfileDel(0xFF);
ASSERT_ON_ERROR(lRetVal);
但是上面的代码好像没有起作用,当我断电重插板子或者按reset键后,都重新进入smartconfig模式了。
因为smartconfig是不能读出密码的,只能读到ssd,所以貌似也没上面办法把密码保存起来。那么请问应如何修改代码才能记住这个连接呢?
非常感谢!!