WiFiClient()
描述
创建一个用户端,用来与指定的 IP 位址与埠编号连线。(使用 client.connect() 指定伺服端的 IP 位址与埠编号)
语法
WiFiClient client;
参数
无参数
范例
#include <WiFi.h> char ssid[] = "myNetwork"; // 无线网路的 SSID char pass[] = "myPassword"; // WPA 的密码 int status = WL_IDLE_STATUS; IPAddress server(74,125,115,105); // Google // 初始化 WiFiClient 类别 WiFiClient client; void setup() { Serial.begin(9600); Serial.println("Attempting to connect to WPA network..."); Serial.print("SSID: "); Serial.println(ssid); status = WiFi.begin(ssid, pass); if ( status != WL_CONNECTED) { Serial.println("Couldn't get a wifi connection"); while(true); } else { Serial.println("Connected to wifi"); Serial.println("\nStarting connection..."); // 如果成功连线,透过序列埠印出讯息 if (client.connect(server, 80)) { Serial.println("connected"); // 传送 HTTP 封包 client.println("GET /search?q=arduino HTTP/1.0"); client.println(); } } } void loop() { }
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.