我有一块Arduino Uno板子和一台用C++编写的服务器。我使用以下代码成功地将ESP8266连接到我的路由器:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(3, 2);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Started");
// set the data rate for the SoftwareSerial port
esp8266.begin(115200);
esp8266.write("AT\r\n");
}
void loop() {
if (esp8266.available()) {
Serial.write(esp8266.read());
}
if (Serial.available()) {
esp8266.write(Serial.read());
}
}
现在,我希望ESP8266作为客户端连接到同一局域网中的服务器(我有服务器IP)。如何使用SoftwareSerial实现?还有其他方法吗?