Connection refused, invalid payload. Using C-Curl

Connection refused, invalid payload. Using C-Curl

Hello, I am trying to upload data (json) to TagoIO from a C code using Curl but I got some issue. If I try to upload it through Python the same json file it works properly.

function to upload data to tagoio
void sendJsonFile(const std::string& filePath, const std::string& url, const std::string& deviceToken) {
std::ifstream file(filePath);
if (!file.is_open()) {
std::cerr << "Failed to open file: " << filePath << std::endl;
return;
}


std::stringstream buffer;
buffer << file.rdbuf();
std::string jsonContent = buffer.str();

CURL* curl;
CURLcode res;
std::string response;

curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

cout << jsonContent.c_str() << endl;

if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, (url).c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonContent.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_slist_append(NULL, "Content-Type: application/json"));
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_slist_append(NULL, ("device-token: " + deviceToken).c_str()));


curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);

res = curl_easy_perform(curl);
if(res != CURLE_OK) {
std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
} else {
long http_code = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code == 202) {
std::cout << "File sent successfully: " << filePath << std::endl;
} else {
std::cerr << "Failed to send file: " << filePath << std::endl;
}
}
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}

curl_global_cleanup();
}

The json content:
  1. "{\"variable\": \"ECU\", \"value\": \"A11XXX\", \"group\": \"1711040634\", \"location\": {\"lat\": -25.17523519563604, \"lng\": -42.34364307711733}, \"metadata\": {\"DeviceID\": \"A11R4R\", \"ecu\": {\"SPN169\": 3020996.8125, \"SPN38\": 173604.0, \"SPN7471\": 2170050.0, \"SPN80\": 173604.0, \"SPN95\": 868020.0, \"SPN96\": 62.0, \"SPN99\": 217005.0, \"SPN110\": 70.0, \"SPN174\": 61.0, \"SPN175\": 1774.96875, \"SPN52\": 215.0, \"SPN183\": 0.0, \"SPN184\": 127.998046875, \"PGN129026\": 0.005555555555555556, \"SPN1483\": 255.0, \"SPN1675\": 15.0, \"SPN190\": 0.0, \"SPN2432\": 130.0, \"SPN4154\": 0.0, \"SPN512\": 130.0, \"SPN513\": 1.875, \"SPN899\": 0.0, \"SPN100\": 4.0, \"SPN109\": 510.0, \"SPN111\": 0.0, \"SPN94\": 0.0, \"SPN98\": 102.0, \"SPN1859\": 65535.0, \"SPN1860\": 4294967295.0, \"SPN1861\": 3.0, \"SPN247\": 14290.5, \"SPN249\": 4294967295000.0, \"SPN2872\": 0.0, \"SPN2873\": 0.0, \"SPN2874\": 102.0, \"SPN2875\": 0.0, \"SPN2876\": 0.0, \"SPN2877\": 65535.0, \"SPN1862\": 32.0, \"SPN1863\": 3451.2727272727275, \"SPN1864\": 123.27272727272727, \"SPN1865\": 1.0, \"SPN1866\": 5.0, \"GPSVehicleSpeed\": 0.0, \"VehicleSpeed\": 32.0}, \"ISO11783\": {}}}"
The upload from device is working but on the TAGOIO inspector I got connection refused.

  1. 12:31:45:
    [POST] HTTP Request:
    "From: 177.79.59.90 [Unknown] - Content-Type: application/x-www-form-urlencoded - Token Ending: fc2f4"
    "From: 177.79.59.90 [Unknown] - Content-Type: application/x-www-form-urlencoded - Token Ending: fc2f4"

    12:31:45:
    Raw payload:
    { "\"{\\\"variable\\\": \\\"ECU\\\", \\\"value\\\": \\\"A11R4R\\\", \\\"group\\\": \\\"1711040634\\\", \\\"location\\\": {\\\"lat\\\": -22.4741872, \\\"lng\\\": -51.303259999999995}, \\\"metadata\\\": {\\\"DeviceID\\\": \\\"A11R4R\\\", \\\"ecu\\\": {\\\"SPN169\\\": 3020996.8125, \\\"SPN38\\\": 173604.0, \\\"SPN7471\\\": 2170050.0, \\\"SPN80\\\": 173604.0, \\\"SPN95\\\": 868020.0, \\\"SPN96\\\": 62.0, \\\"SPN99\\\": 217005.0, \\\"SPN110\\\": 70.0, \\\"SPN174\\\": 61.0, \\\"SPN175\\\": 1774.96875, \\\"SPN52\\\": 215.0, \\\"SPN183\\\": 0.0, \\\"SPN184\\\": 127.998046875, \\\"PGN129026\\\": 0.005555555555555556, \\\"SPN1483\\\": 255.0, \\\"SPN1675\\\": 15.0, \\\"SPN190\\\": 0.0, \\\"SPN2432\\\": 130.0, \\\"SPN4154\\\": 0.0, \\\"SPN512\\\": 130.0, \\\"SPN513\\\": 1.875, \\\"SPN899\\\": 0.0, \\\"SPN100\\\": 4.0, \\\"SPN109\\\": 510.0, \\\"SPN111\\\": 0.0, \\\"SPN94\\\": 0.0, \\\"SPN98\\\": 102.0, \\\"SPN1859\\\": 65535.0, \\\"SPN1860\\\": 4294967295.0, \\\"SPN1861\\\": 3.0, \\\"SPN247\\\": 14290.5, \\\"SPN249\\\": 4294967295000.0, \\\"SPN2872\\\": 0.0, \\\"SPN2873\\\": 0.0, \\\"SPN2874\\\": 102.0, \\\"SPN2875\\\": 0.0, \\\"SPN2876\\\": 0.0, \\\"SPN2877\\\": 65535.0, \\\"SPN1862\\\": 32.0, \\\"SPN1863\\\": 3451.2727272727275, \\\"SPN1864\\\": 123.27272727272727, \\\"SPN1865\\\": 1.0, \\\"SPN1866\\\": 5.0, \\\"GPSVehicleSpeed\\\": 0.0, \\\"VehicleSpeed\\\": 32.0}, \\\"ISO11783\\\": {}}}\"": "" }
    { "\"{\\\"variable\\\": \\\"ECU\\\", \\\"value\\\": \\\"A11R4R\\\", \\\"group\\\": \\\"1711040634\\\", \\\"location\\\": {\\\"lat\\\": -22.4741872, \\\"lng\\\": -51.303259999999995}, \\\"metadata\\\": {\\\"DeviceID\\\": \\\"A11R4R\\\", \\\"ecu\\\": {\\\"SPN169\\\": 3020996.8125, \\\"SPN38\\\": 173604.0, \\\"SPN7471\\\": 2170050.0, \\\"SPN80\\\": 173604.0, \\\"SPN95\\\": 868020.0, \\\"SPN96\\\": 62.0, \\\"SPN99\\\": 217005.0, \\\"SPN110\\\": 70.0, \\\"SPN174\\\": 61.0, \\\"SPN175\\\": 1774.96875, \\\"SPN52\\\": 215.0, \\\"SPN183\\\": 0.0, \\\"SPN184\\\": 127.998046875, \\\"PGN129026\\\": 0.005555555555555556, \\\"SPN1483\\\": 255.0, \\\"SPN1675\\\": 15.0, \\\"SPN190\\\": 0.0, \\\"SPN2432\\\": 130.0, \\\"SPN4154\\\": 0.0, \\\"SPN512\\\": 130.0, \\\"SPN513\\\": 1.875, \\\"SPN899\\\": 0.0, \\\"SPN100\\\": 4.0, \\\"SPN109\\\": 510.0, \\\"SPN111\\\": 0.0, \\\"SPN94\\\": 0.0, \\\"SPN98\\\": 102.0, \\\"SPN1859\\\": 65535.0, \\\"SPN1860\\\": 4294967295.0, \\\"SPN1861\\\": 3.0, \\\"SPN247\\\": 14290.5, \\\"SPN249\\\": 4294967295000.0, \\\"SPN2872\\\": 0.0, \\\"SPN2873\\\": 0.0, \\\"SPN2874\\\": 102.0, \\\"SPN2875\\\": 0.0, \\\"SPN2876\\\": 0.0, \\\"SPN2877\\\": 65535.0, \\\"SPN1862\\\": 32.0, \\\"SPN1863\\\": 3451.2727272727275, \\\"SPN1864\\\": 123.27272727272727, \\\"SPN1865\\\": 1.0, \\\"SPN1866\\\": 5.0, \\\"GPSVehicleSpeed\\\": 0.0, \\\"VehicleSpeed\\\": 32.0}, \\\"ISO11783\\\": {}}}\"": "" }

    12:31:45:
    Connection refused, invalid payload:
    "[object Object]"

Can anyone help me resolve this issue?