我正在使用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