如何使用以太卡库和Arduino Uno通过POST将此JSon发送到服务器?
我需要将此数据发布到我的远程服务器:如何使用以太卡库和Arduino Uno通过POST将此JSon发送到服务器?,post,arduino,arduino-uno,ethercard,Post,Arduino,Arduino Uno,Ethercard,我需要将此数据发布到我的远程服务器: StaticJsonBuffer<200> jsonBuffer; DynamicJsonBuffer jBuffer; JsonObject& root = jsonBuffer.createObject(); root["latitude"]= gps.location.lat(), root["longitude"]= gps.location.lng(); root.prettyPrintTo(Seria
StaticJsonBuffer<200> jsonBuffer;
DynamicJsonBuffer jBuffer;
JsonObject& root = jsonBuffer.createObject();
root["latitude"]= gps.location.lat(),
root["longitude"]= gps.location.lng();
root.prettyPrintTo(Serial);
StaticJsonBuffer-jsonBuffer;
动态缓冲区jBuffer;
JsonObject&root=jsonBuffer.createObject();
根[“纬度”]=gps.location.lat(),
根[“经度”]=gps.location.lng();
root.prettyPrintTo(串行);
我找不到任何实用的教程来做这件事。我已经连接了以太网ENC28J60模块,它工作正常,但我不知道如何通过这个库发送带有标题内容类型应用程序json的POST数据。你能帮我吗?如果你一直搜索,你会找到我的解决方案:
static word reponse() {
doc.clear();
doc["Etat"] = "ok";
doc["CodeMp3"] = "00";
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: application/json\r\n"
"Connection: close\r\n"
"Content-Length: $D\r\n"
"\r\n"), measureJson(doc));
serializeJson(doc, bfill);
return bfill.position();
}
void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos){ // check if valid tcp data is received
getMsgSever(pos,len);
ether.httpServerReply(reponse()); // send web page data
}
}
您的代码不完整。请编辑您的帖子并添加完整的草图,以便我们了解需要做什么。顺便说一句,您的ArduinoJson语法基于旧版本5。有关序列化json数据的新语法,请参阅。@hcheung我这里没有代码。我只是想从这个库或类似的东西中通过http post发布这个Json,但首先我必须用这个Json创建主体,我不知道怎么做。我认为上的thingspeak示例有一个post请求示例,您可以根据需要修改。虽然这段代码可以解决这个问题,如何以及为什么解决这个问题将真正有助于提高您的帖子质量,并可能导致更多的投票。请记住,你是在将来回答读者的问题,而不仅仅是现在提问的人。请在回答中添加解释,并说明适用的限制和假设。