Hello Particle Community,
I’m trying to get a photon to send a json array to a google sheets endpoint and have created a structure that I save data from a sensor into.
struct pms5003data {
uint16_t framelen;
uint16_t pm10_standard, pm25_standard, pm100_standard;
uint16_t pm10_env, pm25_env, pm100_env;
uint16_t particles_03um, particles_05um, particles_10um, particles_25um, particles_50um, particles_100um;
uint16_t unused;
uint16_t checksum;
};
I then put all that data into an array.
int PMArray[] ={ data.pm10_standard, data.pm25_standard, data.pm100_standard,
data.pm10_env, data.pm25_env, data.pm100_env,
data.particles_03um, data.particles_05um, data.particles_10um, data.particles_25um,
data.particles_50um, data.particles_100um
};
Becuase it apears the Partcle.publish() funtion can only take strings I then convert the int data into char and then to strings.
char PM1_0_S[32];
sprintf(PM1_0_S,"{\"PM1_S\":%d}", PMArray[0]);
char PM25_S[32];
sprintf(PM25_S,"{\"PM2.5_S\":%d}", PMArray[1]);
char PM10_S[32];
sprintf(PM10_S,"{\"PM10_S\":%d}", PMArray[2]);
char PM1_E[32];
sprintf(PM1_E,"{\"PM1_E\":%d}", PMArray[3]);
char PM25_E[32];
sprintf(PM25_E,"{\"PM2.5_E\":%d}", PMArray[4]);
char PM10_E[32];
sprintf(PM10_E,"{\"PM10_E\":%d}", PMArray[5]);
char PM03[32];
sprintf(PM03,"{\"PM0.3\":%d}", PMArray[6]);
char PM05[32];
sprintf(PM05,"{\"PM0.5\":%d}", PMArray[7]);
char PM1[32];
sprintf(PM1,"{\"PM1.0\":%d}", PMArray[8]);
char PM25[32];
sprintf(PM25,"{\"PM2.5\":%d}", PMArray[9]);
char PM5[32];
sprintf(PM5,"{\"PM5.0\":%d}", PMArray[10]);
char PM10[32];
sprintf(PM10,"{\"PM10\":%d}", PMArray[11]);
But I’m stuck on a good way to combine all the strings of data into one string of data that can be sent to the cloud to be used in a webhook. The goal is to only have to use one Particle.publish("jsonData", PM03, 60, PRIVATE);
function to get all the data into a web server for post-processing.
Any recomendation would be appreciated, thanks.