Particle publishing --- how to?

I am testing out some stuff on the Argon and would like to know how to format a string with multiple variables to publish.
I understand the following:

Particle.publish("Vbias",String::format("%0.2f", SensorDataPerCyclePublish.Vbias[current]));

Just not sure how to add (or even if I can) a second variable to this line WITHOUT calling publish a second time. I ask bcz at the moment I am trying to publish 24 events in a 20 second window and it appears (via reading the documentation) that there is a limitation of 4 publishes per second which would mean I would have to get crafty with a SoftwareTimer to break up the publishing into 4’s every second. Not impossible BUT the blocks of data come in 6’s not 4’s. Eventually I am going to use a web-hook to send them to a google spreadsheet.


With one publish statement (event & message), you can send multiple data pairs within the message.
Here is a post you can review for a useful tool:

Here is an example:

char msg128[128];
double averageTempF;
double averageHumidity;
char usbPoweredSzInfo[16] = "no data...";

void formatVariableDataPairs() {
  JSONBufferWriter writer(msg128, sizeof(msg128) - 1);
  writer.beginObject();"tempF").value(averageTempF);"rh").value(averageHumidity);"mains power").value(usbPoweredSzInfo);
  writer.buffer()[std::min(writer.bufferSize(), writer.dataSize())] = 0;

loop() {
  if (Particle.connected()) { //will block if NOT connected
    Particle.publish("stats", msg128);
  delay(10000); // demo only
1 Like

Maybe looking into the reference docs can help

Particularly the supplemental link directing you to printf()

While at it you may also want to look into snprintf() to avoid using String and rather go with old-fashioned C-strings.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.