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请求