hey guys!
I am quite new to particle.
I am trying ArduinoJson library.
My goal is to sent in a function a JSON String so i can parse and the arguments in my code as variables. i dont know why but i am losing my data somewhere.
i spent days in this and i am stuck. I saw lots of people with the same problem but i didnt get a working solution to my case.
can anyone please give me a hint?
thanks in advance,
pedro
#include <ArduinoJson.h>
void setup() {
Serial.begin(9600);
//this will trigger the function to make the http request to receive the json
Particle.function("JSON", getJSON);
}
void loop() {
// not used in this example
}
int getJSON(String JsonFile) {
StaticJsonDocument<350> doc;
char jsonString[JsonFile.length() + 1];
JsonFile.toCharArray(jsonString, sizeof(jsonString));
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, jsonString);
// Test if parsing succeeds.
if (error) {
Particle.publish("event", "ERRO");
return -1;
}
const char* sensorChar = doc["sensor"];
Serial.println(sensorChar);
// Publish the value of the "sensor" key as a String object
Particle.publish("event", sensorChar);
return 1;
}