How to send this JSon via POST to server with EtherCard library and Arduino Uno?

1.1k Views Asked by At

I need to post this data to my remote server:

   StaticJsonBuffer<200> jsonBuffer;
  DynamicJsonBuffer jBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["latitude"]= gps.location.lat(),
  root["longitude"]= gps.location.lng();
  root.prettyPrintTo(Serial);

I can't find any working tutorial to do it. I've connected my ethernet ENC28J60 module and it works fine but I don't know how to send POST data with header content type application json via this library. Can you help me?

1

There are 1 best solutions below

1
On

if you search alway you will find my solution :

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
  }

}