从ESP8266 Arduino连接到我的服务器
Connect to my server from ESP8266 Arduino
我有一个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("ATrn");
}
void loop() {
if (esp8266.available()) {
Serial.write(esp8266.read());
}
if (Serial.available()) {
esp8266.write(Serial.read());
}
}
现在,我希望ESP8266作为同一局域网中的客户端连接到我的服务器(我有服务器IP)。如何使用SoftwareSerial?还有别的办法吗?
您必须向它发送AT命令才能创建HTTP请求。这将连接到端口80 上192.168.88.35的服务器
// Connect to the server
esp8266.write("AT+CIPSTART="TCP","192.168.88.35",80rn"); //make this command: AT+CPISTART="TCP","192.168.88.35",80
//wait a little while for 'Linked'
delay(300);
//This is our HTTP GET Request change to the page and server you want to load.
String cmd = "GET /status.html HTTP/1.0rn";
cmd += "Host: 192.168.88.35rnrn";
//The ESP8266 needs to know the size of the GET request
esp8266.write("AT+CIPSEND=");
esp8266.write(cmd.length());
esp8266.write("rn");
esp8266.write(cmd);
esp8266.write("AT+CIPCLOSErn");
如果您需要更多详细信息,此链接将有所帮助:http://blog.huntgang.com/2015/01/20/arduino-esp8266-tutorial-web-server-monitor-example/
相关文章:
- 为什么创建服务器后C++ httplib 库阻塞了我的主线程?
- 将静态 IP 分配给我的 ESP32 服务器后不再响应
- 为什么io_context在我的boost asio协同程序服务器中丢失
- 为什么我的客户端无法连接到服务器?
- 如何在不使用tensorflow的情况下构建tfsensor并将其提供给我的docker服务器
- 浏览器将随机HTTP消息正文发送到我的boost.asio服务器.我可以更改此设置吗?
- 试图在我的服务器上使用线程
- 我无法在用C++编写的服务器和用 C# 编写的客户端之间建立 UDP 连接
- 我怎么知道我的服务器是否在一段时间内没有连接
- 为什么我的服务器没有等待接收来自客户端的回复
- 为什么BOOST创建的JSON字符串与我的服务器所需的不同
- 为什么我的服务器没有向我的客户端发送任何内容
- 从ESP8266 Arduino连接到我的服务器
- 如何使我的服务器多线程
- SIGPROF在使用谷歌perftools时杀死了我的服务器
- 这是我的服务器
- 如何得到一个距离矩阵的计算正在离线上我的服务器
- 我的服务器退出代码137
- QTcpClient成功连接,但未连接到我的服务器.它在哪里连接
- 将我的服务器响应char数组转换为wchar_t数组是处理客户端收到的服务器消息的正确方法吗?