查看: 3404|回复: 3

【WINC1500-XSTK WiFi】初试wifi

[复制链接]
  • TA的每日心情
    开心
    2020-2-14 12:16
  • 签到天数: 827 天

    连续签到: 1 天

    [LV.10]以坛为家III

    发表于 2016-6-26 10:41:58 | 显示全部楼层 |阅读模式
    分享到:
    接上一篇帖子https://www.cirmall.com/bbs/thread-48019-1-1.html
    关于WINC 1500工程发出的一个问题,一直没有解决,各位前辈帮忙看一下请问atmel_iot_gateway工程路径 - AVR系列专区 - Atmel技术社区 http://atmel.eefocus.com/module/forum/thread-6607-1-1.html参考官网教程,使用“WINC1500_IOT_CLOUD_DEMO1”工程实例,程序介绍如下

    无线部分相关定义
    1. #define MAIN_WLAN_SSID         "DEMO_AP"
    2. *    #define MAIN_WLAN_AUTH         M2M_WIFI_SEC_WPA_PSK
    3. *    #define MAIN_WLAN_PSK          "12345678"
    复制代码
    1. -- WINC1500 AP scan example --
    2. *    -- SAM_XPLAINED_PRO --
    3. *    -- Compiled: xxx xx xxxx xx:xx:xx --
    4. *
    5. *    [1] SSID:DEMO_AP1
    6. *    [2] SSID:DEMO_AP2
    7. *    [3] SSID:DEMO_AP
    8. *    Found DEMO_AP
    9. *    Wi-Fi connected
    10. *    Wi-Fi IP is xxx.xxx.xxx.xxx
    复制代码
    返回wifi信息并更新,switch-case语句
    1. static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
    2. {
    3.         switch (u8MsgType) {
    4.         case M2M_WIFI_RESP_SCAN_DONE:
    5.         {
    6.                 tstrM2mScanDone *pstrInfo = (tstrM2mScanDone *)pvMsg;
    7.                 scan_request_index = 0;
    8.                 if (pstrInfo->u8NumofCh >= 1) {
    9.                         m2m_wifi_req_scan_result(scan_request_index);
    10.                         scan_request_index++;
    11.                 } else {
    12.                         m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
    13.                 }

    14.                 break;
    15.         }
    复制代码
    1. case M2M_WIFI_RESP_SCAN_RESULT:
    2.         {
    3.                 tstrM2mWifiscanResult *pstrScanResult = (tstrM2mWifiscanResult *)pvMsg;
    4.                 uint16_t demo_ssid_len;
    5.                 uint16_t scan_ssid_len = strlen((const char *)pstrScanResult->au8SSID);

    6.                 /* display founded AP. */
    7.                 printf("[%d] SSID:%s\r\n", scan_request_index, pstrScanResult->au8SSID);

    8.                 num_founded_ap = m2m_wifi_get_num_ap_found();
    9.                 if (scan_ssid_len) {
    10.                         /* check same SSID. */
    11.                         demo_ssid_len = strlen((const char *)MAIN_WLAN_SSID);
    12.                         if
    13.                         (
    14.                                 (demo_ssid_len == scan_ssid_len) &&
    15.                                 (!memcmp(pstrScanResult->au8SSID, (uint8_t *)MAIN_WLAN_SSID, demo_ssid_len))
    16.                         ) {
    17.                                 /* A scan result matches an entry in the preferred AP List.
    18.                                  * Initiate a connection request.
    19.                                  */
    20.                                 printf("Found %s \r\n", MAIN_WLAN_SSID);
    21.                                 m2m_wifi_connect((char *)MAIN_WLAN_SSID,
    22.                                                 sizeof(MAIN_WLAN_SSID),
    23.                                                 MAIN_WLAN_AUTH,
    24.                                                 (void *)MAIN_WLAN_PSK,
    25.                                                 M2M_WIFI_CH_ALL);
    26.                                 break;
    27.                         }
    28.                 }

    29.                 if (scan_request_index < num_founded_ap) {
    30.                         m2m_wifi_req_scan_result(scan_request_index);
    31.                         scan_request_index++;
    32.                 } else {
    33.                         printf("can not find AP %s\r\n", MAIN_WLAN_SSID);
    34.                         m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
    35.                 }

    36.                 break;
    37.         }

    38.         case M2M_WIFI_RESP_CON_STATE_CHANGED:
    39.         {
    40.                 tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged *)pvMsg;
    41.                 if (pstrWifiState->u8CurrState == M2M_WIFI_CONNECTED) {
    42.                         m2m_wifi_request_dhcp_client();
    43.                 } else if (pstrWifiState->u8CurrState == M2M_WIFI_DISCONNECTED) {
    44.                         printf("Wi-Fi disconnected\r\n");

    45.                         /* Request scan. */
    46.                         m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
    47.                 }

    48.                 break;
    49.         }

    50.         case M2M_WIFI_REQ_DHCP_CONF:
    51.         {
    52.                 uint8_t *pu8IPAddress = (uint8_t *)pvMsg;
    53.                 printf("Wi-Fi connected\r\n");
    54.                 printf("Wi-Fi IP is %u.%u.%u.%u\r\n",
    55.                                 pu8IPAddress[0], pu8IPAddress[1], pu8IPAddress[2], pu8IPAddress[3]);
    56.                 break;
    57.         }

    58.         default:
    59.         {
    60.                 break;
    61.         }
    62.         }
    63. }
    复制代码
    主函数
    1. int main(void)
    2. {
    3.         tstrWifiInitParam param;
    4.         int8_t ret;
    5.         system_init();
    6.         configure_console();
    7.         printf(STRING_HEADER);
    8.         nm_bsp_init();
    9.         memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam));
    10.         param.pfAppWifiCb = wifi_cb;
    11.         ret = m2m_wifi_init(¶m);
    12.         if (M2M_SUCCESS != ret) {
    13.                 printf("main: m2m_wifi_init call error!(%d)\r\n", ret);
    14.                 while (1) {
    15.                 }
    16.         }

    17.         m2m_wifi_request_scan(M2M_WIFI_CH_ALL);

    18.         while (1) {
    19.                 while (m2m_wifi_handle_events(NULL) != M2M_SUCCESS) {
    20.                 }
    21.         }

    22.         return 0;
    23. }
    复制代码
    在串口助手里面看到如下
    2.JPG
    目前还没找到WINC1500的头文件,需要修改相应的SSID和密码,才可以手机连接,实现京东物联
    回复

    使用道具 举报

  • TA的每日心情

    2021-12-7 12:35
  • 签到天数: 1354 天

    连续签到: 1 天

    [LV.10]以坛为家III

    发表于 2016-6-26 22:51:53 | 显示全部楼层
    编的好,学习和参考了
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2018-11-19 16:39
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]初来乍到

    发表于 2016-6-27 14:54:28 | 显示全部楼层
    我看你的文章还是很不错的,我将这个一并发到经验频道,可以吗?
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2020-2-14 12:16
  • 签到天数: 827 天

    连续签到: 1 天

    [LV.10]以坛为家III

     楼主| 发表于 2016-6-27 22:26:47 | 显示全部楼层
    糖悦之果飞 发表于 2016-6-27 14:54
    我看你的文章还是很不错的,我将这个一并发到经验频道,可以吗?

    不要,就放这里吧。
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-20 22:24 , Processed in 0.131830 second(s), 22 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.