HTTP - 從 Internet 檢索 HTTP 網站

材料準備

  • AmebaD [AMB21 / AMB22 / AMB23 / BW16] x 1

範例説明

In this example, the HttpClient library is used to retrieve a webpage using the HTTP protocol. First, make sure that the correct Ameba development board is selected in “Tools” → “Board” Then open “File” “Examples” “AmebaHttp” “SimpleHttpExample”

1

在示例代碼中,修改高亮的部分,輸入連接WiFi網絡所需的信息(ssid、密碼、密鑰索引)。

2

上傳代碼並在上傳完成後按下Ameba上的reset按鈕。在Arduino IDE中打開串行監視器,我們可以看到從網站檢索到的信息。

3

程式碼説明

Use WiFi.begin() to establish WiFi connection: https://www.arduino.cc/en/Reference/WiFiBegin

To get the information of a WiFi connection: Use WiFi.SSID() to get SSID of the current connected network. https://www.arduino.cc/en/Reference/WiFiSSID

Use WiFi.RSSI() to get the signal strength of the connection. https://www.arduino.cc/en/Reference/WiFiRSSI

Use WiFi.localIP() to get the IP address of Ameba. https://www.arduino.cc/en/Reference/WiFiLocalIP

Use WiFiClient to create a client to handle the WiFi connection. https://www.arduino.cc/en/Reference/WiFiClient

使用HTTPClient創建一個客戶端來處理HTTP連接

使用http.get()向網站發送GET請求