This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc3200 可以配置多个wifi策略吗?wifi策略保存后 怎么判断配置文件是否存在?

Other Parts Discussed in Thread: CC3200

你好 cc3200 sl_WlanProfileAdd 把ssid 和 password添加到配置文件中 

1.请问可以添加多个吗?

2.怎么判断是否有配置文件?

3.上电后 如果有配置文件 会自动连接吗?不需要执行sl_WlanConnect吗?

谢谢!

  • 这个profiles存储在serial flash file system, 掉电不丢失,会自动连接。

    请参考如下

    e2echina.ti.com/.../74127

  • 你好:

    1.如果配置多个策略 是否是把addprofile的参数Priority 更改下,如果Priority值是一样的 那么就会覆盖吧?

    2.profile文件存在flash中  那么怎么去判断profle文件中是否有存入ssid和password呢? 有read的接口吗

    3.上电后 自动连接 这个是在代码中哪里执行的,或者说 连接ap之后 会有什么接口回调吗(便于判断是否连接成功)

    谢谢!




  • static long SetConnectionPolicy() { unsigned char policyVal; long lRetVal = -1; /* Clear all stored profiles and reset the policies */ lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), 0, 0); ASSERT_ON_ERROR(lRetVal); //Add Profile /* user needs to change SSID_NAME = "<Secured AP>" SECURITY_TYPE = SL_SEC_TYPE_WPA SECURITY_KEY = "<password>" and set the priority as per requirement to connect with a secured AP */ SlSecParams_t secParams; secParams.Key = SECURITY_KEY; secParams.KeyLen = strlen(SECURITY_KEY); secParams.Type = SECURITY_TYPE; lRetVal = sl_WlanProfileAdd(SSID_NAME,strlen(SSID_NAME),0,&secParams,0,1,0); ASSERT_ON_ERROR(lRetVal); //set AUTO policy lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); ASSERT_ON_ERROR(lRetVal); while(1) { //wait until IP is acquired while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { _SlNonOsMainLoopTask(); } UART_PRINT("\n\r===>>> Device connected to AP\n\r"); // Wait while(IS_CONNECTED(g_ulStatus)) { _SlNonOsMainLoopTask(); } CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); UART_PRINT("\n\r===>>> Device disconnected from AP\n\r"); } } ************************************************* CC3200 CONNECTION_POLICY Application ************************************************* Host Driver Version: 1.0.0.1 Build Version 2.2.0.1.31.1.2.0.2.1.0.3.23 Device is configured in default state Device started as STATION [WLAN EVENT] STA Connected to the AP: TP-LINK-APK2 ,BSSID: a0:f3:c1:b1:d6:6e [NETAPP EVENT] IP Acquired: IP=192.168.0.100 , Gateway=192.168.0.1 ===>>> Device connected to AP [WLAN ERROR]Device disconnected from the AP AP: TP-LINK-APK2,BSSID: a0:f3:c1:b1:d6:6e on an ERROR..!! ===>>> Device disconnected from AP [WLAN EVENT] STA Connected to the AP: TP-LINK-APK2 ,BSSID: a0:f3:c1:b1:d6:6e [NETAPP EVENT] IP Acquired: IP=192.168.0.100 , Gateway=192.168.0.1 ===>>> Device connected to AP [WLAN ERROR]Device disconnected from the AP AP: TP-LINK-APK2,BSSID: a0:f3:c1:b1:d6:6e on an ERROR..!! ===>>> Device disconnected from AP [WLAN EVENT] STA Connected to the AP: TP-LINK-APK2 ,BSSID: a0:f3:c1:b1:d6:6e [WLAN ERROR]Device disconnected from the AP AP: TP-LINK-APK2,BSSID: a0:f3:c1:b1:d6:6e on an ERROR..!! [WLAN EVENT] STA Connected to the AP: TP-LINK-APK2 ,BSSID: a0:f3:c1:b1:d6:6e [NETAPP EVENT] IP Acquired: IP=192.168.0.100 , Gateway=192.168.0.1 ===>>> Device connected to AP [WLAN ERROR]Device disconnected from the AP AP: TP-LINK-APK2,BSSID: a0:f3:c1:b1:d6:6e on an ERROR..!! ===>>> Device disconnected from AP [WLAN EVENT] STA Connected to the AP: TP-LINK-APK2 ,BSSID: a0:f3:c1:b1:d6:6e [NETAPP EVENT] IP Acquired: IP=192.168.0.100 , Gateway=192.168.0.1 ===>>> Device connected to AP

    优先级可以一样, 以通过API调用(sl_WlanProfileAdd,sl_WlanProfileDel,sl_WlanProfileGet)管理连接配置文件,
    但是get时不允许获取密码,这是用户无法操作的。你各种状态都有对应的event SL_WLAN_CONNECT_EVENT
  • 你好:
    初学者 请见谅啊,就是想添加多个账号密码的时候,通过addprofile的方式 添加第二个的时候 不会把第一个覆盖掉吗?
    尝试过这样的操作,第一次add一个账号密码 断电后 连接了 然后没有做删除操作 再添加 第二个账号密码 那么再重启 就直接连接了第二个ssid,addprofile的时候 所传参数是一致的。
    另外如果两个ssid的Priority 是一样的 那么上电后 会怎么确认优先级。
  • ssid的Priority这个应该是可以的,我没有去细查。sl_WlanProfileAdd不会覆盖。如果相同优先级,可能会根据RSSI好的优先。
  • 你试试相同看看,没试过。
    你可以参考:dev.ti.com/.../group___wlan.html
  • 你好  关于 断电之前 add profile了 

    但是上电后 程序里什么都不操作

    1.直接执行main方法 这样 不能触发联网操作

    2.尝试上电后 在main里面执行lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL, 1 /*PolicyValLen*/);

    还是不能联网。

    所以想问下  存profile之后  断电开机 需要在main里面执行什么 才会触发联网

  • user5951870 说:

    你好  关于 断电之前 add profile了 

    但是上电后 程序里什么都不操作

    1.直接执行main方法 这样 不能触发联网操作

    2.尝试上电后 在main里面执行lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL, 1 /*PolicyValLen*/);

    还是不能联网。

    所以想问下  存profile之后  断电开机 需要在main里面执行什么 才会触发联网

    这个问题有人回复吗

  • 你有log以及返回值提供吗

  • log 不知道 怎么抓取 程序是在调用 setpolicy 之前有  的 sl_Start(0,0,0)函数 执行失败了  这个函数的返回值是1

    开机上电后的程序是(在main函数中 执行 sl_Start(0,0,0) 再执行setpolicy)

    问题1:执行sl_Start之前需要什么必要操作吗? 为什么会调用这个失败

    现在目的就是  profile之前add上了  想在开机后 自动连接Ap

  • 首先没有API可以在 sl_Start()之前调用,你的操作时对的,你需要先sl_Start 然后setpolicy。sl_Start 为 1 ROLE_UNKNOWN ,你怎么启动的?

     mode = sl_Start(0, 0, 0);
        if (mode < 0)
        {
            Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, mode, DEVICE_ERROR);
        }
    
        if(mode != ROLE_STA)
        {
            /* Set NWP role as STA */
            mode = sl_WlanSetMode(ROLE_STA);
            if (mode < 0)
            {
                Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, mode, WLAN_ERROR);
            }
    
            /* For changes to take affect, we restart the NWP */
            status = sl_Stop(SL_STOP_TIMEOUT);
            if (status < 0)
            {
                Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, status, DEVICE_ERROR);
            }
    
            mode = sl_Start(0, 0, 0);
            if (mode < 0)
            {
                Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, mode, DEVICE_ERROR);
            }
        }
    
        if(mode != ROLE_STA)
        {
            printError("Failed to configure device to it's default state", mode);
        }
    
    SetConnectionPolicy
    

    我是怀疑你是否add 成功了。

  • 你好 sl_start返回0 我知道为啥了 因为 我在之前的sl_start之后 没有执行sl_stop

    我的操作如下:
    1.上电后先执行sl_start setpolicy去连接wifi(此时是没有profile的 因为无法判断是否有 所以只能有没有都去执行这个(不知道这么做是否导致了后续的问题))

    2.执行完1的动作后 去执行addprofile 和 setpolicy(但是这个时候 两个函数返回值都对 并没有联网成功的netevent回调)


    问题: 在没有profile的情况下 去执行l_start setpolicy去连接wifi 会有哪些问题?怎么去判断有没有profile 从而去决定是否连接操作呢?
  • 通常先去sl_WlanProfileGet()判断一下。
  • 你好 关于sl_WlanProfileGet的用法 有事例代码吗?
  • 你好 在main函数里面 直接执行的lRetVal = sl_Start(0, 0, 0);的时候 程序就卡死在这个函数里面了

    如果在任务中去执行 就没有问题? 请问这是我哪里配置的不对吗?

    对比了example中的例程 没有差别 不明白为啥 lRetVal = sl_Start(0, 0, 0);就直接卡死了
  • 试了下 在自带的例程中 main里面直接执行sl_start 也会卡死
  • 这就有可能是你的硬件有问题,因为SDK的demo是好的,你在试试吧
  • 你好 我又尝试了几次,

    现象如下:

    1.用事例代码connection_policy 在这面的main函数中 执行下面的操作 发现 第一次可以执行 sl_start(0,0,0)成功。
    重新download程序 (在线调试那种) 第二次就卡死在里面了 需要reset之后 才可以成功,代码如下:
    int main(void)
    {
    long lRetVal = -1;

    //
    // Initialize Board configurations
    //
    BoardInit();

    lRetVal = sl_Start(0, 0, 0);

    InitializeAppVariables();
    //
    // Following function configure the device to default state by cleaning
    // the persistent settings stored in NVMEM (viz. connection profiles &
    // policies, power policy etc)
    //
    // Applications may choose to skip this step if the developer is sure
    // that the device is in its default state at start of applicaton
    //
    // Note that all profiles and persistent settings that were done on the
    // device will be lost
    //
    lRetVal = ConfigureSimpleLinkToDefaultState();


    2.在自己程序中 同样的main函数中 执行sl_start(0,0,0) 每次都会卡死在里面

    代码如下:
    void main()
    {
    long lRetVal = -1;
    OsiReturnVal_e m_osiRetVal;

    //
    // Board Initialization
    //
    BoardInit();
    lRetVal = sl_Start(0, 0, 0);


    同样都是在执行了 BoardInit(); 之后 去执行sl_start 结果却是不一样的 请问这个sl_start会受到什么影响呢
  • 通常是你的serial flash 有问题,建议你把这个问题发到英文论坛那边。