I am sending sensor data from an argon via mqtt to telegraf, then on to a postgresql database. It only works when I have a small number of metrics I send across. Anything else, I begin to get this errror:
[inputs.mqtt_consumer]: Error in plugin: unexpected end of JSON input
I have tried different formatting of the data being pushed to telegraf. I suspect I am not setting this up right on my end.
On my argon, I have tried this:
char data[512];
float temp_F = (sample.temperature* 9) /5 + 32;
int readtime = Time.now(); //Unix Format
snprintf(data, sizeof(data), "{\"readtime\":%ld000,\"deviceID\":\"%s\",\"location\":\"%s\",\"name\":\"%s\",\"type\":\"%s\",\"temp_F\":%.2f,\"temp_C\":%.2f,\"humid\":%.2f,\"absHumid\":%.2f,\"voc\":%.2f,\"co2\":%.2f,\"eco2_base\":%u,\"tvoc_base\":%u,\"pm1\":%.2f,\"pm2\":%.2f,\"pm4\":%.2f,\"pm10\":%.2f,\"nc0\":%.2f,\"nc1\":%.2f,\"nc2\":%.2f,\"nc4\":%.2f,\"nc10\":%.2f,\"typical_particle_size\":%.2f}",readtime,(const char*)System.deviceID(),deviceLocation,deviceName,deviceType,temp_F,sample.temperature,sample.humidity,sample.absoluteHumidity,sample.voc,sample.co2,sample.eco2_base,sample.tvoc_base,sps30.GetMassPM1(),sps30.GetMassPM2(),sps30.GetMassPM4(),sps30.GetMassPM10(),sps30.GetNumPM0(),sps30.GetNumPM1(),sps30.GetNumPM2(),sps30.GetNumPM4(),sps30.GetNumPM10(),sps30.GetPartSize());
and this:
float temp_F = (sample.temperature* 9) /5 + 32;
int readtime = Time.now(); //Unix Format
String data = String::format( "{\"readtime\":%ld000,\"deviceID\":\"%s\",\"location\":\"%s\",\"name\":\"%s\",\"type\":\"%s\",\"temp_F\":%.2f,\"temp_C\":%.2f,\"humid\":%.2f,\"voc\":%.2f,\"co2\":%.2f,\"absHumid\":%.2f,\"eco2_base\":%u,\"tvoc_base\":%u}",readtime,(const char*)System.deviceID(),deviceLocation,deviceName,deviceType,temp_F,sample.temperature,sample.humidity,sample.voc,sample.co2,sample.absoluteHumidity,sample.eco2_base,sample.tvoc_base);
the string data option was working until I added the readtime.
Here is my mqtt setup on telegraf.
[[inputs.mqtt_consumer]]
name_override = "airquality"
servers = ["tcp://xx.xx.xx.xx:1883"]
qos = 0
connection_timeout = 30
topics = [
"airmonitor/#",
]
persistent_session = true
client_id = "airmonitor-telegraf"
data_format = "json"
json_time_key = "readtime"
json_time_format = "unix_ms"
json_timezone = "America/New_York"
tag_keys = [
"deviceID",
"location",
"name",
"type"
]
Thanks