How to post a variable location correctly using HTTP and Arduino/ESP32 device
Hi everybody
I´m new on some Arduino/ESP32 with HTTP and TAGO, so thanks in advance for your help
I´m trying to post a variable to TAGO using HTTP Arduino example, a variable with some fixed data and LAT & LGN concatenate to location.
However, every method I've tried return a payload error because I´m sending a String and not an Object.
This is my post string concatenation on Arduino:
- String postData, postStr;
String postData = "variable=serialNumber&value=" + String(serialNumber01)+ "&location=lat:" + String(valueLatitudeNow,8) + "&location=lng:" + String(valueLongitudeNow,8); - postStr = "POST /data HTTP/1.1\n";
- postStr += "Host: api.tago.io\n";
- postStr += "Device-Token: "+apiKey+"\n";
- postStr += "_ssl: false\n";
- postStr += "Content-Type: application/x-www-form-urlencoded\n";
- postStr += "Content-Length: "+String(postData.length())+"\n";
- postStr += "\n";
- postStr += postData;
- client.print(postStr);
And this is what I´m seeing on Device Live Inspector:
19:27:53:
[POST] HTTP Request:
"From: 177.58.233.18 [Unknown] - Content-Type: application/x-www-form-urlencoded - Token Ending: b0e24"
"From: 177.58.233.18 [Unknown] - Content-Type: application/x-www-form-urlencoded - Token Ending: b0e24"
19:27:53:
Raw payload:
{ "variable": "serialNumber", "value": "FMIX5J40-110", "location": [ "lat:-23.48155800", "lng:-46.65259450" ] }
{
"variable": "",
"value": "FMIX5J40-110",
"location": [
"lat:-23.48155800",
"lng:-46.65259450"
]
}
19:27:53:
Connection refused, invalid payload:
{ "zodError": { "location": [ { "message": "Expected object, received array", "path": [ "location" ] } ] } }
{
"zodError": {
"location": [
{
"message": "Expected object, received array",
"path": [
"location"
]
}
]
}
}
I've tried many ways converting to a RAW JSON, reserialize, using the Payload parser, without success.
Someone could help me with an example in how to do that?
Thank you very much in advance!