Newline in Particle.publish

I am attempting to batch publishing my data. On the backend, I am using the InfluxDB integration. So, when I don't batch, my code works and looks like this:

        String lineProtocolString = String::format("geophoneData,manufacturer=%s,deviceId=%s value=%f %lld\n", manufacturer.c_str(), deviceId.c_str(),, dataPoint.timestamp);
        Particle.publish("influx_data", lineProtocolString);

But, when I batch, my code looks like this:

    String batchedLineProtocolString;
    for (const auto& dataPoint : accumulatedData) {
        String lineProtocolString = String::format("geophoneData,manufacturer=%s,deviceId=%s value=%f %lld\n", manufacturer.c_str(), deviceId.c_str(),, dataPoint.timestamp);
    if (batchedLineProtocolString != "") {
        // TODO: Ensure that the string is not too long to be passed to Particle.publish
        Particle.publish("geophoneData", batchedLineProtocolString);

My issue comes when I try to add the /n at the end of the batches script. When the data is published, the newline character is not parsed in the cloud so it ends up sending invalid line protocol to InfluxDB.

Does Particle.publish support a newline character? If so, what am I doing wrong? If not, any ideas on a workaround?

Hi and welcome to the community!
Not sure if the new line is supported since publishes may only support printable chars, but can you think of another character that can replace at least temporarily the new line?

If the influxDB REALLY requires the new line, one way I would try is to use a different char from the device, and replace it on the cloud side with the Logic feature. I've never done it in the past, but that is what I would try.

Best, and if you get it trouble do not hesitate to post again.

PS: newline chars will not work with Publish:

EDIT: a community member was kind to let me know that the above limitation is FOR THE EVENT NAME, not the data.

It does look like InfluxDB expects the newline character. See: InfluxDB line protocol reference | InfluxDB OSS v1 Documentation

Can you log out the content of your batchedLineProtocolString before publishing?
Just to make sure the problem is not in the string building.

While doing so you could also print out the length of the built string - as outlined in your TODO comment this might also be contributing to the issue.

Also, I would really like to avoid using Logic because of the extra cost. Perhaps my best option is to connect directly to InfluxDB directly from the device?

What does your webhook template look like? Make sure you are using {{{PARTICLE_EVENT_VALUE}}} with triple curly brackets.

If you use the version with only two curly brackets, the output will be HTML escaped, and newline is a special-ish character in HTML.

There is no restriction on newline in the event data, though it doesn't display in the console event stream as a newline.


Adding @Support to follow this closely.