gpt4 book ai didi

c - Arduino 和 ESP8266 HTTP GET 响应处理

转载 作者:行者123 更新时间:2023-11-30 17:00:01 24 4
gpt4 key购买 nike

我已成功连接服务器,但无法处理响应数据。 esp8266.find("+PID,") 不起作用。我的循环代码如下:

void loop() {
String cmd = "AT+CIPSTART=\"TCP\",\""; //make this command: AT+CPISTART="TCP","192.168.88.35",80
cmd += DST_IP;
cmd += "\",80\r\n";
esp8266.print(cmd);
//wait a little while for 'Linked'
delay(3000);

//This is our HTTP GET Request change to the page and server you want to load.
cmd = "GET /~atolye/wifiModule.php?id=123 HTTP/1.0\r\n";
cmd += "Host: 159.122.115.70\r\n\r\n";
esp8266.print("AT+CIPSEND=63\r\n");
if(esp8266.find(">")) {
//Send our http GET request
Serial.println("SENDING THE REQUEST");
esp8266.print(cmd);
if(esp8266.find("+IPD,")) {
Serial.println("\r\nIPD FOUND");
if(esp8266.find("\"1")) {
int value = esp8266.read()-48;
Serial.println("\r\nVALUE FOUND");
Serial.println(value);
esp8266.println(value);
}
} else {
Serial.println("\r\n!! IPD NOT FOUND");
}
}
else {
Serial.println("\r\nERROR > DOESN'T EXIST");
//Something didn't work...
esp8266.print("AT+CIPCLOSE\r\n");
}

}

这是输出:正如您所注意到的,IPD NOT FOUND 在 RESPONSE 到达之前执行。我应该怎么做才能捕获这些数据?提前致谢。

AT+CIPSTART="TCP","159.122.115.70",80

CONNECT

OK
SENDING THE REQUEST

!! IPD NOT FOUND
START="TCP","159.122.115.70",80

busy s...

Recv 103 bytes

SEND OK

+IPD,205:HTTP/1.1 200 OK
Date: Thu, 16 Jun 2016 08:33:19 GMT
Server: Apache/2.4.16 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4
X-Powered-By: PHP/5.5.30
Connection: close
Content-Type: application/json

"12"CLOSED

最佳答案

问题不在于响应时间。假设有一个通过 AT+CIPSTART 打开的 TCP 连接,以及一个长度为 42 个字符的请求,如下所示:

GET / HTTP/1.0\r\nHost: 77.223.129.195\r\n

在执行之前应将 CIPSEND 设置为字符计数。问题是,\r\n 每个被计为 1 个字节,不应计为 2 个字符。请求由 4 个字符 42-4 = 38 组成。

AT+CIPSEND=38\r\n

排除 2 个字节解决了问题,并在代码检查是否有“+PID”之前成功显示。

关于c - Arduino 和 ESP8266 HTTP GET 响应处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37854125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com