如何通过POST将JSon发送到带有EtherCard库和Arduino Uno的服务器?

问题描述 投票:0回答:1

我需要将此数据发布到我的远程服务器:

   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数据。你能帮我吗?

post arduino arduino-uno ethercard
1个回答
0
投票

如果您始终搜索,将找到我的解决方案:

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
  }

}

© www.soinside.com 2019 - 2024. All rights reserved.