i have an argon and send every couple of seconds some measured data.
at the moment i just use:
$measuredTemp;$measuredHumidity, like: 23;45, meaning: 23°C and 45% Humidity.
This is not so good because i’d like to have now much more values (about 10) and i am very sure ill face some mis-interpretation when i continue in that way, so i thought ill go with json because then i can address every value its own identifier.
but i have some problems understand how big “buf” should be.
when i want to send a string like: {“curTemp”:“30”, “curHum”: “40”}
how big should buf be?
buf from https://docs.particle.io/reference/device-os/firmware/argon/#jsonwriter
do i have to only count the values inside curTemp and curHum (in that case 4 char arrays, means buf = 4) or do i have to add everything meaning 32 chars + \0 ?
edit:
i have now the following code, it works but it feels somehow ugly to define a buf size and not having this dynamic, or is this common practice to do so?
char buf[JSON_BUF_SIZE] = {0};
Measure measure = measureData();
JSONBufferWriter writer(buf, sizeof(buf) - 1);
writer.beginObject();
writer.name("prefTempHigh").value(config.prefTemperatureHigh);
writer.name("prefTempLow").value(config.prefTemperatureLow);
writer.name("prefHumLow").value(config.prefHumidityLow);
writer.name("prefHumHigh").value(config.prefHumidityHigh);
writer.name("curHum").value(measure.humidity);
writer.name("curTemp").value(measure.temperature);
writer.endObject();
writer.buffer()[std::min(writer.bufferSize(), writer.dataSize())] = 0;
Particle.publish("data", String(buf), PRIVATE);