来自Arduino的Web2Py GET请求(ESP8266WiFi)

时间:2018-06-28 16:25:47

标签: arduino get web2py esp8266

我正在使用NodeMCU,并希望将数据记录到本地Web2Py服务器。

请求:“ http://minion.local:8000/ardulog/default/add/6476366/45643”在浏览器中正常工作,并返回记录ID。

我的Arduino可以连接到我的服务器,但是没有收到任何返回数据错误或其他错误,并且我的数据库中没有任何内容。

// This will send the request to the server
samptime = millis();
rpm = (samptime + 333) % 96789;
String request = "10.0.0.244:8000/ardulog/default/add/"+String(samptime)+"/"+String(rpm)+" HTTP/1.1";
Serial.println("\ntrying: ");
Serial.println("GET " + request);
Serial.println("host: minion.local");
client.println("GET " + request);
client.println("host: minion.local");

// if there are incoming bytes available 
// from the server, read them and print them:
while (client.available()) {
  char c = client.read();
  Serial.print(c);
}

Serial.println("closing connection");
client.stop(); 

我尝试了所有我能想到的变体,但只能得到以下内容:

connecting to minion.local
[hostByName] request IP for: minion.local
[hostByName] Host: minion.local IP: 10.0.0.244
Requesting: 
GET 10.0.0.244:8000/ardulog/default/add/112725/16269 HTTP/1.1
host: minion.local
closing connection
wait 5 sec...

为什么我没有读取从服务器重新调整的内容?

1 个答案:

答案 0 :(得分:1)

已解决!尽管我无法成功发布到Google Sheets,但仅将单词从GET更改为POST即可与Web2Py 一起使用,而无需发送任何正文数据:

if(client.connect(host,port))  
  client.println("POST /ardulog/default/add/" + String(samptime)+ "/" + String(rpm) + " HTTP/1.1");

(尽管仍然没有从服务器接收结果页)