【发布时间】:2017-03-19 13:11:34
【问题描述】:
我正在创建一个人员计数器,只需简单地计算房间内的进出数,然后将其上传到我的数据库中,我使用 Arduino MEGA2560 和 ESP8266 作为我服务器的通信器。
但是当我在我的服务器上发送 HTTP GET 请求时遇到了问题。一旦我发送 HTTP GET 请求,我的计数器功能在 HTTP GET 请求完成之前将无法工作,只是想知道 Arduino 中是否有诸如易于使用和理解的异步功能,或者有使用 HTTP GET 请求的正确方法
这是我的代码:
void loop{
counter(); // let's assume that this function is just counting in and out person in the room
// changing the value of variable count
uint8_t buffer[1024] = {0};
if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
Serial.print("create tcp ok\r\n");
} else {
Serial.print("create tcp err\r\n");
}
char hello[];
strcpy(hello, "GET /vbus/insert.php?coount=");
strcat(hello, count);
strcat(hello," HTTP/1.1\r\nHost: www.test.com\r\nConnection:close\r\n\r\n");
wifi.send((const uint8_t*)hello, strlen(hello));
wifi.send((const uint8_t*)hello, strlen(hello));
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
}
}
PS:我上面说的发送 HTTP GET 请求没有任何问题。
【问题讨论】:
-
你在 esp8266 中使用 arduino fw 吗?您的问题中有 arduino-esp8266 标签。
-
我正在使用 arduino 和 esp8266,如果我的标签不正确,请纠正我 :)
-
不,没问题。只是想弄清楚你在 esp8266 上使用 arduino fw
-
只要您使用串行库进行连接,您将不够灵活,无法在此类问题上获得支持。 ESP8266 Arduino 固件有一个异步 HTTP 库,仅供参考。
-
@cagdas 你能告诉我什么是 fw,我只是一个初学者请原谅我:),所以如果我使用 serial.write AT 命令,你告诉我会更好吗?