> 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 函式庫

### 範例 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

![](/files/08uW6pE19jDyZwjPdz4t)

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

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

![](/files/WJvljaydlntIRbxoFin6)

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

![](/files/YNtvusIUZS5mi6PDPkZK)

若沒有看到訊息的話，可按下 **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 的內容) 如下：

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