How do you 'post' json data?

I'm having a lot of trouble getting this one feature to work. I'm using an MKR WiFi 1010 and the ENV Shield to collect environemental information and I would like to send this data to my server. Ive been hunting down forum threads all day with no solution in sight so hopefully someone knows.

// ArduinoJson - Version: Latest
#include <ArduinoJson.h>
#include <ArduinoJson.hpp>

// ArduinoHttpClient - Version: Latest
#include <ArduinoHttpClient.h>

// Arduino_MKRENV - Version: Latest
#include <Arduino_MKRENV.h>

#include <SPI.h>
#include <WiFiNINA.h>

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the Wifi radio's status

const String lat = "52.52";
const String lon = "13.41";
const String openWeatherMapKey = SECRET_OPENWEATHER;

WiFiClient client;

float temperature;
float humidity;
float pressure;
float illuminance;
float uva;
float uvb;
float uvIndex;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < "1.0.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();

  if (!ENV.begin()) {
    Serial.println("Failed to initialize MKR ENV shield!");
    while (1);
  }

}

void loop() {
  printCurrentNet();

  HttpClient WeatherAPI = HttpClient(client, "api.openweathermap.org", 80);
  HttpClient webServer = HttpClient(client, "192.168.178.22", 80);

  WeatherAPI.get("/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&units=metric&APPID=" + openWeatherMapKey);

  // read the status code and body of the response
  int statusCode = WeatherAPI.responseStatusCode();
  String response = WeatherAPI.responseBody();

  Serial.println("-------------------------------------");
 
  Serial.print("Status code: ");
  Serial.println(statusCode);
  Serial.print("Response: ");
  Serial.println(response);
  
   Serial.println("-------------------------------------");

  DynamicJsonDocument Weather(1024);
  DeserializationError error = deserializeJson(Weather, response);
  if (error)
    return;

  // Extract values

  const float weatherTemp = Weather["main"]["temp"];
  const float weatherPressure = Weather["main"]["pressure"];
  const float weatherHumidity = Weather["main"]["humidity"];
  const float weatherVisibility = Weather["visibility"];
  const String weatherMain = Weather["weather"][0]["main"];

  Serial.println(F("JSON Response:"));
  Serial.println(weatherMain);
  Serial.println(weatherTemp);
  Serial.println(weatherHumidity);
  Serial.println(weatherPressure);

  // read all the sensor values
  temperature = ENV.readTemperature();
  humidity    = ENV.readHumidity();
  pressure    = ENV.readPressure();
  illuminance = ENV.readIlluminance();
  uva         = ENV.readUVA();
  uvb         = ENV.readUVB();
  uvIndex     = ENV.readUVIndex();

  printSensorReadings();
  
  DynamicJsonDocument mimirJSON(1024);

  JsonObject coord = mimirJSON.createNestedObject("coord");
  coord["lon"] = 13.41;
  coord["lat"] = 52.52;

  JsonObject sensor = mimirJSON.createNestedObject("sensor");
  sensor["temperature"] = ENV.readTemperature();
  sensor["humidity"]    = ENV.readHumidity();
  sensor["pressure"]   = ENV.readPressure();
  sensor["illuminance"] = ENV.readIlluminance();
  sensor["uva"]         = ENV.readUVA();
  sensor["uvb"]         = ENV.readUVB();
  sensor["uvIndex"]     = ENV.readUVIndex();
  
  JsonObject weather = mimirJSON.createNestedObject("weather");
  sensor["temperature"] = weatherTemp;
  sensor["pressure"]    = weatherPressure;
  sensor["humidity"]   = weatherHumidity;
  sensor["visibility"] = weatherVisibility;
  sensor["main"]         = weatherMain;


  serializeJson(mimirJSON, Serial);
  
  //Send JSON to server using ARDUINOhttpClient
  int len = measureJson(mimirJSON);
  
  webServer.post("/", "application/json", len, mimirJSON);

  //Send JSON to server using ARDUINOhttpClient

    delay(10000);
}

void printWifiData() {
  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);

  // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  printMacAddress(mac);
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.print("BSSID: ");
  printMacAddress(bssid);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption, HEX);
  Serial.println();
}

void printMacAddress(byte mac[]) {
  for (int i = 5; i >= 0; i--) {
    if (mac[i] < 16) {
      Serial.print("0");
    }
    Serial.print(mac[i], HEX);
    if (i > 0) {
      Serial.print(":");
    }
  }
  Serial.println();
}

void printSensorReadings() {
  // print each of the sensor values
  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity    = ");
  Serial.print(humidity);
  Serial.println(" %");

  Serial.print("Pressure    = ");
  Serial.print(pressure);
  Serial.println(" kPa");

  Serial.print("Illuminance = ");
  Serial.print(illuminance);
  Serial.println(" lx");

  Serial.print("UVA         = ");
  Serial.println(uva);

  Serial.print("UVB         = ");
  Serial.println(uvb);

  Serial.print("UV Index    = ");
  Serial.println(uvIndex);

  // print an empty line
  Serial.println();
}

ERROR CODE:

error: no matching function for call to 'HttpClient::post(const char [2], const char [17], int&, ArduinoJson6113_00000::DynamicJsonDocument&)

There seems to be a problem that the data package when I send it. I'm not sure if its the type, or the some kind of conflict with ArduinoJson, but i'm at the end of my patients for it right now.

If anyone has any ideas I would love to hear them!

Lloydrichards:
but i'm at the end of my patients for it right now.

Try to work towards being like us ----- with unlimited patience. The trick is to not get impatient, and keep working towards the goal ----- gaining more as we go along.

I haven't yet gone down this path of json and arduino. But saw your post, and will likely have a go at it too.

Have you done or followed any basic online tutorials involving this? I usually start from basic tutorials, just to get something basic to come up or work. Eg.... rather than send a whole bunch of data .... just try to get the simplest thing to work first.

Southpark:
Try to work towards being like us ----- with unlimited patience. The trick is to not get impatient, and keep working towards the goal ----- gaining more as we go along.

Thanks for the words of encouragement :smiley: I love the process of coding and learning new things, but there are days when you spend 6+ hours in front of a screen and get absolutely no where... and that can be frustrating.

I had a look at the example you posted and these are some bits of code I haven't tried in there, but the problem I found is that a lot of those examples are based on ArduinoJson5, not 6 which is the current version. and with the current version and the way they use JsonDocument I have not been able to get a plain HTTP post to work.