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 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.data, dataPoint.timestamp);
batchedLineProtocolString.concat(lineProtocolString);
}
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.
Gustavo.
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?