久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: 【零知ESP8266】教程:WiFiScan庫的使用 [打印本頁]

作者: roc2    時間: 2019-6-10 16:42
標題: 【零知ESP8266】教程:WiFiScan庫的使用
本帖最后由 roc2 于 2019-6-19 10:55 編輯

概述:
無線網絡提供的WiFi熱點,大部分都開放了SSID廣播(記得之前博主講過WiFi熱點也可以隱藏的),Scan WiFi的功能就是掃描出所有附近的WiFi熱點的SSID信息,這樣一來,客戶端就可以根據需要選擇不同的SSID連入對應的無線網絡中。
Scan WiFi庫提供了兩種方式實現掃描過程:
同步掃描:通過單個函數在一次運行中完成,需要等待完成所有操作才能繼續運行下面的操作。
異步掃描:把上面的過程分成幾個步驟,每個步驟由一個單獨函數完成,我們可以在掃描過程中執行其他任務。
ESP8266WiFiScan庫
ESP8266WiFiScan庫,大家使用的時候只需要引入
  1. #include<ESP8266WiFi.h>
復制代碼
掃描操作方法1.scanNetworks —— 同步掃描周邊有效wifi網絡函數說明:
  1. /**
  2. * Start scan WiFi networks available
  3. * @param async         run in async mode(是否啟動異步掃描)
  4. * @param show_hidden   show hidden networks(是否掃描隱藏網絡)
  5. * @param channel       scan only this channel (0 for all channels)(是否掃描特定通道)
  6. * @param ssid*         scan for only this ssid (NULL for all ssid's)(是否掃描特定的SSID)
  7. * @return Number of discovered networks
  8. */int8_t scanNetworks(bool async = false, bool show_hidden = false, uint8 channel = 0, uint8* ssid = NULL);
復制代碼
2.scanNetworks(async ) —— 異步掃描周邊有效wifi網絡
函數說明:
  1. /**
  2. * Start scan WiFi networks available
  3. * @param async         run in async mode(是否啟動異步掃描)
  4. * @param show_hidden   show hidden networks(是否掃描隱藏網絡)
  5. * @param channel       scan only this channel (0 for all channels)(是否掃描特定通道)
  6. * @param ssid*         scan for only this ssid (NULL for all ssid's)(是否掃描特定的SSID)
  7. * @return Number of discovered networks
  8. */int8_t scanNetworks(bool async = false, bool show_hidden = false, uint8 channel = 0, uint8* ssid = NULL);
復制代碼
3.scanNetworksAsync —— 異步掃描周邊wifi網絡,并回調結果
函數說明:
  1. /**
  2. * Starts scanning WiFi networks available in async mode
  3. * @param onComplete    the event handler executed when the scan is done
  4. * @param show_hidden   show hidden networks
  5.   */void scanNetworksAsync(std::function<void(int)> onComplete, bool show_hidden = false);
復制代碼
4. scanComplete —— 檢測異步掃描的結果
函數說明:
  1. /**
  2. * called to get the scan state in Async mode(異步掃描的結果函數)
  3. * @return scan result or status
  4. *          -1 if scan not find
  5. *          -2 if scan not triggered
  6. */
  7. int8_t scanComplete();
復制代碼
5.scanDelete —— 從內存中刪掉最近掃描結果
函數說明:
  1. /**
  2. * delete last scan result from RAM(從內存中刪除最近的掃描結果)
  3. */void scanDelete();
復制代碼
掃描結果方法1. SSID —— 獲取wifi網絡名字
函數說明:
  1. /**
  2. * Return the SSID discovered during the network scan.
  3. * @param i     specify from which network item want to get the information
  4. * @return       ssid string of the specified item on the networks scanned list
  5. */String SSID(uint8_t networkItem);
復制代碼
2.RSSI —— 獲取wifi網絡信號強度
函數說明:
  1. /**
  2. * Return the RSSI of the networks discovered during the scanNetworks(信號強度)
  3. * @param i specify from which network item want to get the information
  4. * @return  signed value of RSSI of the specified item on the networks scanned list
  5. */int32_t RSSI(uint8_t networkItem);
復制代碼
3. encryptionType —— 獲取wifi網絡加密方式
函數說明:
  1. /**
  2. * Return the encryption type of the networks discovered during the scanNetworks(加密方式)
  3. * @param i specify from which network item want to get the information
  4. * @return  encryption type (enum wl_enc_type) of the specified item on the networks scanned list
  5. * ............ Values map to 802.11 encryption suites.....................
  6. *    AUTH_OPEN          ---->     ENC_TYPE_WEP  = 5,
  7. *    AUTH_WEP           ---->     ENC_TYPE_TKIP = 2,
  8. *    AUTH_WPA_PSK       ---->     ENC_TYPE_CCMP = 4,
  9. * ........... except these two, 7 and 8 are reserved in 802.11-2007.......
  10. *    AUTH_WPA2_PSK      ---->     ENC_TYPE_NONE = 7,
  11. *    AUTH_WPA_WPA2_PSK  ---->     ENC_TYPE_AUTO = 8
  12. */uint8_t encryptionType(uint8_t networkItem);
復制代碼
4. BSSID —— 獲取wifi網絡mac地址
函數說明:
  1. /**
  2. * return MAC / BSSID of scanned wifi (物理地址)
  3. * @param i specify from which network item want to get the information
  4. * @return uint8_t * MAC / BSSID of scanned wifi
  5. */uint8_t * BSSID(uint8_t networkItem);
  6. /**
  7. * return MAC / BSSID of scanned wifi (物理地址)
  8. * @param i specify from which network item want to get the information
  9. * @return uint8_t * MAC / BSSID of scanned wifi
  10. */String BSSIDstr(uint8_t networkItem);
復制代碼
5.getNetworkInfo —— 獲取整體網絡信息,名字,信號強度等
函數說明:
  1. /**
  2. * loads all infos from a scanned wifi in to the ptr parameters
  3. * @param networkItem uint8_t
  4. * @param ssid  const char**
  5. * @param encryptionType uint8_t *
  6. * @param RSSI int32_t *
  7. * @param BSSID uint8_t **
  8. * @param channel int32_t *
  9. * @param isHidden bool *
  10. * @return (true if ok)
  11. */        bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
復制代碼
6. channel —— 獲取wifi網絡通道號
函數說明:
  1. /**
  2. * return channel of scanned wifi(通道號)
  3. */int32_t channel(uint8_t networkItem);
復制代碼
7. isHidden —— 判斷wifi網絡是否是隱藏網絡
函數說明:
  1. /**
  2. * return if the scanned wifi is Hidden (no SSID)(判斷掃描到的wifi是否是隱藏wifi)
  3. * @param networkItem specify from which network item want to get the information
  4. * @return bool (true == hidden)
  5. */bool isHidden(uint8_t networkItem);
復制代碼
動手操作
多說不宜,實驗是檢驗真理的唯一標準,下面我們就來實際操作一下吧。
打開零知開源開發工具,新建一個項目,輸入以下代碼,驗證,上傳。

測試demo:
  1. /**
  2. * Demo:
  3. *    STA模式下,演示同步掃描Scan wifi功能
  4. * @author 云上上云
  5. * @date 2019/06/01
  6. */#include <ESP8266WiFi.h>
  7. //以下三個定義為調試定義#define DebugBegin(baud_rate)    Serial.begin(baud_rate)#define DebugPrintln(message)    Serial.println(message)#define DebugPrint(message)    Serial.print(message)
  8. void setup() {  //設置串口波特率,以便打印信息
  9.   DebugBegin(115200);  //延時5s 為了演示效果
  10.   delay(5000);  // 我不想別人連接我,只想做個站點
  11.   WiFi.mode(WIFI_STA);  //斷開連接
  12.   WiFi.disconnect();
  13.   delay(100);
  14.   DebugPrintln("Setup done");
  15. }
  16. void loop() {
  17.   DebugPrintln("scan start");  // 同步掃描,等待返回結果
  18.   int n = WiFi.scanNetworks();
  19.   DebugPrintln("scan done");  if (n == 0){
  20.     DebugPrintln("no networks found");
  21.   }else{
  22.     DebugPrint(n);
  23.     DebugPrintln(" networks found");    for (int i = 0; i < n; ++i){
  24.       DebugPrint(i + 1);
  25.       DebugPrint(": ");      //打印wifi賬號
  26.       DebugPrint(WiFi.SSID(i));
  27.       DebugPrint(",");
  28.       DebugPrint(String("Ch:")+WiFi.channel(i));
  29.       DebugPrint(",");
  30.       DebugPrint(WiFi.isHidden(i)?"hide":"show");
  31.       DebugPrint(" (");      //打印wifi信號強度
  32.       DebugPrint(WiFi.RSSI(i));
  33.       DebugPrint("dBm");
  34.       DebugPrint(")");      //打印wifi加密方式
  35.       DebugPrintln((WiFi.encryptionType(i) == ENC_TYPE_NONE)?"open":"*");
  36.       delay(10);
  37.     }
  38.   }
  39.   DebugPrintln("");  // 延時5s之后再次掃描
  40.   delay(5000);
  41. }
復制代碼
測試結果(附近潛在的WiFi熱點):它可以掃描完附件所有WiFi。
更多詳細資料可到零知實驗室官網免費獲取。












歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 欧美视频一区二区三区 | 久久高清免费视频 | 欧美一级欧美一级在线播放 | 超级碰在线| 成人性生交大片 | 欧美高清视频在线观看 | 精品久久久久久久久久久 | 久久99精品国产自在现线小黄鸭 | 岛国视频 | 久草欧美视频 | 毛片区 | 国产视频第一页 | 国产精品久久视频 | 日韩一二区 | 亚洲精品一区二区 | 二区中文 | 中文字幕 亚洲一区 | 国产精品一区二区久久 | 中国美女av| 一区二区三区欧美 | 一级毛片在线播放 | 精品一区二区三区视频在线观看 | 日韩精品一区二区三区中文在线 | 粉嫩一区二区三区国产精品 | 国产不卡视频 | 欧美一级片在线看 | 欧美9999| 91在线精品一区二区 | 亚洲成人精品视频 | 久久成人综合 | 在线观看黄视频 | 免费一级片 | 欧美日韩在线一区二区 | 亚洲精品乱码久久久久久蜜桃 | 日本国产高清 | 国产精品久久久久久久久久免费 | 在线观看中文字幕 | 久久精品成人热国产成 | 在线看免费的a | 久久国产高清视频 | www.性色 |