我需要将此数据发布到我的远程服务器:
StaticJsonBuffer<200> jsonBuffer;
DynamicJsonBuffer jBuffer;
JsonObject& root = jsonBuffer.createObject();
root["latitude"]= gps.location.lat(),
root["longitude"]= gps.location.lng();
root.prettyPrintTo(Serial);
我找不到任何有效的教程来做到这一点。我已经连接了我的以太网ENC28J60模块,它工作正常,但是我不知道如何通过该库发送带有标头内容类型application 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
}
}