> For the complete documentation index, see [llms.txt](https://cavedu.gitbook.io/linkit-7697/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cavedu.gitbook.io/linkit-7697/linkit-7697-arduinoide/kai-fa-zhi-nan/shi-yong-wifi-han-shi-ku.md).

# 使用 Wi-Fi 函式庫

要使用 LinkIt 7697 的 Wi-Fi 功能，可透過 BSP 內的 LWiFi 函式庫達成。LWiFi 函式庫的介面與 Arduino Wi-Fi 函式庫非常相似，因此大多數的 Arduino Wi-Fi 範例都可在不需修改的狀況下直接使用。

### 範例 1：掃描鄰近的 Wi-Fi 網路 <a href="#usingthewifilibrary-fan-li-1-sao-miao-lin-jin-de-wifi-wang-lu" id="usingthewifilibrary-fan-li-1-sao-miao-lin-jin-de-wifi-wang-lu"></a>

1.使用 **File > Examples > LWiFi > ScanNetwork** 範例，讓開發板搜尋鄰近的 Wi-Fi AP

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FmDEmgH23qZNozGfkNhgo%2Fscan_network_example.png?alt=media\&token=9c450221-e436-499b-aed3-02c0dbe683d4)

2.點選 **Upload** 按鈕開始編譯與上傳，直到 **Done Uploading** 訊息顯示為止

3.點選工具列中的 **Serial Monitor** 按鈕 (如圖)：

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FDph2YVNG0fWTBOSW5rzN%2Fserial_monitor.png?alt=media\&token=0b7f80a9-a518-4c9c-85bb-99db704c525f)

4.設定 **Baud rate** 為 **9,600**。接著就會看到開發板所找到的鄰近 Wi-Fi AP 清單：

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FI0S701wi8O7v6J3ujwAr%2Fserial_monitor_baud.png?alt=media\&token=54f358e2-7796-48fe-a2a4-a07ece3ac030)

若沒有看到訊息的話，可按下 **RST** 按鈕重啟 LinkIt 7697 再次進行掃描。使用 **RST** 按鈕時，不需重新開啟 Serial Monitor，因為 **RST** 按鈕僅會重啟 MT7697 SoC、[並不影響 CP2012N 的運作](/linkit-7697/linkit-7697-arduinoide/huan-jing-she-ding/jiang-linkit-7697-lian-jie-dao-dian-nao.md)，因此 Serial Monitor 所連接的 COM 埠不會因 SoC 的重啟而產生影響。

### 範例 2：連接到網頁伺服器 <a href="#usingthewifilibrary-fan-li-2-lian-jie-dao-wang-ye-si-fu-qi" id="usingthewifilibrary-fan-li-2-lian-jie-dao-wang-ye-si-fu-qi"></a>

此範例將展示透過使用 **LWiFi** 函式庫裡的 **WiFiClient** 類別，與網頁伺服器之間建立 TCP 連線。

首先開啟 **File > Examples > LWiFi > WiFiWebClient** 範例，並根據所使用的 Wi-Fi AP，在程式碼裡填入正確的 SSID 與密碼資訊：

```
char ssid[] = "yourNetwork"; // your network SSID (name) 
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
```

此程式會與 [http://download.labs.mediatek.com](http://download.labs.mediatek.com/) 網頁伺服器建立 TCP 連線，並發出取得 `linkit_7697_ascii.txt` TXT 文字檔的要求：

```
// Make a HTTP request: 
client.println("GET /linkit_7697_ascii.txt HTTP/1.0"); 
client.println("Host: download.labs.mediatek.com"); 
client.println("Accept: */*"); 
client.println("Connection: close"); 
client.println();
```

所以當 **LinkIt 7697** 執行這個 sketch 時，開啟 **Serial Monitor** 即可看到網頁伺服器的 HTTP header 回應、以及 LinkIt 7697 字樣的 ASCII art 圖案 (即 linkit\_7697\_ascii.txt 的內容) 如下：

```
  _      _       _    _____ _     ______ __ ___ ______ 
 | |    (_)     | |  |_   _| |   |____  / // _ \____  |
 | |     _ _ __ | | __ | | | |_      / / /| (_) |  / / 
 | |    | | '_ \| |/ / | | | __|    / / '_ \__, | / /  
 | |____| | | | |   < _| |_| |_    / /| (_) |/ / / /   
 |______|_|_| |_|_|\_\_____|\__|  /_/  \___//_/ /_/
```
