0

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?

hardillb
  • 54,545
  • 11
  • 67
  • 105
Hawos
  • 33
  • 6
  • Your code is incomplete. Please edit your post and add your complete sketch so that we can understand what' need to be done. – hcheung Feb 16 '20 at 01:25
  • BTW, your ArduinoJson syntax is based on old version 5. Please see [Migrating from version 5 to 6](https://arduinojson.org/v6/doc/upgrade/) for the new syntax for serialise the json data. – hcheung Feb 16 '20 at 05:07
  • @hcheung I have no code right here. I just want to post this Json via http post from this library or something like this https://github.com/njh/EtherCard/blob/master/src/tcpip.cpp but firstly I have to create the body with this json and I don't know how to do it – Hawos Feb 16 '20 at 20:27
  • I think the thingspeak example on the [github](https://github.com/njh/EtherCard/blob/master/examples/thingspeak/thingspeak.ino) has a post request example that you could modify for your needs. – hcheung Feb 17 '20 at 13:34

1 Answers1

0

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
  }

}

  • While this code may solve the question, [including an explanation](https://meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Brian61354270 Apr 10 '20 at 01:21