I’m reading in from Firebase via a webhook. It appears I’m getting the hook response with the firebase read… but I can’t parse it back into number variable formats. Any help would be appreciated.
// This #include statement was automatically added by the Particle IDE.
#include <SparkJson.h>
#include "Particle.h"
//Parameter Variables
int Cycle = 20.0;
double LReadPgm;
double LReadWeb;
double LWritten;
int ReadParametersInterval = 15; // #Freqnency to poll web for new parameters
String deviceName;
const char *CHECK_EVENT_NAME = "ParametersRead";
void setup()
{
Particle.subscribe("spark/", handler);
Particle.publish("spark/device/name");
Particle.subscribe("hook-response/ParametersRead", getDataHandler, MY_DEVICES);
}
void loop()
{
ReadParameters();
}
void ReadParameters()
{
if((Time.now() - LReadWeb) >= ReadParametersInterval)
{
char pREAD[255];
snprintf(pREAD, sizeof(pREAD), "{\"n\":\"%s\"}",deviceName.c_str());
Particle.publish(CHECK_EVENT_NAME, pREAD);
LReadWeb = Time.now();
}
}
void handler(const char *topic, const char *data)
{
deviceName = String(data);
//Particle.publish("Device Name: " + String(deviceName), String(deviceName));
}
void getDataHandler(const char *topic, const char *data)
{
StaticJsonBuffer<256> jsonBuffer;
char *mutableCopy = strdup(data);
JsonObject& root = jsonBuffer.parseObject(mutableCopy);
free(mutableCopy);
//Particle.publish("ParametersREAD: ", String(data), PRIVATE);
// All data, including numbers, are represented as strings, so we need to convert them back to their native data type here
int newCycle = atoi(root["Cycle"]);
double newLReadPgm = atof(root["LReadPgm"]);
double newLReadWeb = atof(root["LReadWeb"]);
double newLWritten = atof(root["LWritten"]);
Particle.publish("New Params:::", (String(newCycle) + "|" + String(newLReadPgm) + "|" + String(newLReadWeb) + "|" + String(newLWritten)), PRIVATE);
delay(3000);
}