I am trying to decode this payload,
{"age":"\"25\"","bmi":"\"6\"","bp":"\"3\"","dpf":"\"7\"","glucose":"\"2\"","insulin":"\"5\"","preg":"\"1\"","skin":"\"4\""}
But unable to decode it correctly,
void getDataHandler(const char *topic, const char *data) {
// This isn't particularly efficient; there are too many copies of the data floating
// around here, but the data is not very large and it's not kept around long so it
// should be fine.
StaticJsonBuffer<256> jsonBuffer;
char *mutableCopy = strdup(data);
JsonObject& root = jsonBuffer.parseObject(mutableCopy);
free(mutableCopy);
Serial.printlnf("data: %s", data);
// Because of the way the webhooks work, all data, including numbers, are represented as
// strings, so we need to convert them back to their native data type here
int age = atoi(root["age"]);
int bmi = atoi(root["bmi"]);
int bp = atoi(root["bp"]);
int dpf = atoi(root["dpf"]);
int glucose = atoi(root["glucose"]);
int insulin = atoi(root["insulin"]);
int preg = atoi(root["preg"]);
int skin = atoi(root["skin"]);
Serial.printlnf("age=%d bmi=%d bp=%d", age, bmi, bp);
}
it prints age=0 bmi=0 bp=0
I used MIT app inventor to send some number inputs to firebase bucket and using an integration to read those values on Particle device, see integration detail below,
{
"event": "diabetes-get",
"url": "https://srefsssssss-default-rtdb.firebaseio.com/data/data.json",
"requestType": "GET",
"noDefaults": true,
"rejectUnauthorized": false,
"query": {
"auth": "tnwKxxxxxxxxxxxxxxxxxxxxxx"
}
}
I think the payload is not in correct format but after many tries, I found no other ways (MIT app inventor send the data to the firebase in that manner/format only)