我正在使用ESP8266模块,以便在线传感传感数据。我将它设置为thingspeak,并使用简单的GET请求发送值。正确的POST请求从Arduino流式传输数据
现在我试图复制流程与情节数据流服务,但我无法弄清楚我的请求有什么问题。
传统图书馆(Wifi,以太网等)有一个println()方法打印到套接字。由于找不到任何可靠的东西,我不得不实现我自己的ESP库,并且注意到设备在将某些东西发送到套接字后经常处于“忙碌”状态,这阻止了我通过发送请求块块像这样的:
client.println("POST/HTTP/1.1")
client.println("Host: arduino.plot.ly")
client.println("{\"x\":15, \"y\": 3, \"streamtoken\": \"urqcbfmjot\"\"}")
于是,我就一下子写请求。我通过潜入依赖Wifi工作的剧情arduino图书馆员找到了这个请求的参数(这就是为什么我不能和ESP一起使用)。直到现在我还没有推送任何数据。这里是代码reponsible的发送请求块:
void pushData(String temp, String humid, String pres, String lum)
{
bool status = esp8266.openTCPConnection(IP, PORT);
char call[] = "POST/HTTP/1.1\r\n";
strcat(call, "Host: arduino.plot.ly\r\n");
strcat(call, "User-Agent: Arduino\r\n");
strcat(call, "Transfer-Encoding: chunked\r\n");
strcat(call, "Connection: close\r\n");
strcat(call, "\r\n");
strcat(call, "\r\n{\"x\":15, \"y\": 3, \"streamtoken\": \"urqcbfmjot\"\"}\n\r\n");
if (!status) return;
esp8266.send(call);
}
void Esp8266::send(String content)
{
String cmd;
String msg = "Sent : ";
bool status;
printDebug("Writing to TCP connection");
printDebug("Content to write :");
printDebug(content);
cmd = "AT+CIPSEND=" + String(content.length());
espSerial.println(cmd);
printDebug("Sent : " + cmd);
status = checkResponse(">", 10);
if (status)
{
espSerial.print(content);
printDebug("Content sent");
} else {
printDebug("Cursor error");
closeTCPConnection();
}
}
我想补充一点,我已经成功地测试了他们的documentation,卷曲提供的请求,但它在我的实现太失败了。要求是:
POST HTTP/1.1
Host: stream.plot.ly
plotly-streamtoken: urqcbfmjot
{ "x": 10, "y": 2 }
任何帮助将不胜感激。有关参考资料,请参阅我的项目的repository。
随意使用我的图形进行测试。主机是stream.plot.ly(来自doc)或arduino.plot.ly(来自库)。我的流令牌是urqcbfmjot并且这里是the link to the plot