I am getting an error from Telegraf when I send information from Particle through the webhook. I publish the following in my Photon’s firmware:
int c=10;
String data=String::format("{ \"tags\" : {\"id\": \"%s\", \"location\": \"%s\"}, \"values\": {\"capacity\": %d}}", "test", "myLoc", c);
Particle.publish("capacity", data, PRIVATE);
This publishes a valid JSON. In the console, I see the photon publishing the following:
{"data":"{ \"tags\" : {\"id\": \"test\", \"location\": \"myLoc\"}, \"values\": {\"capacity\": 10}}","ttl":60,"published_at":"2018-06-21T03:15:15.834Z","coreid":"3c0038000c47363433353735","name":"capacity"}
This is the JSON type I have set up for the webhook:
{
"event": "{{{PARTICLE_EVENT_NAME}}}",
"data": "{{{PARTICLE_EVENT_VALUE}}}",
"coreid": "{{{PARTICLE_DEVICE_ID}}}",
"published_at": "{{{PARTICLE_PUBLISHED_AT}}}",
"measurement": "influxdata_sensors"
}
However, when I run ‘systemctl status telegraf’ in the terminal of my AWS instance, I see an error: “json: cannot unmarshal string into Go struct field event.data of type particle.data”
I’m pretty sure I followed all the necessary steps. I’m not sure why telegraf cannot parse the json that is sent to it. I took a look at the telegraf.go code on github. The event struct and data struct look like this:
type event struct {
Name string `json:"event"`
Data data `json:"data"`
TTL int `json:"ttl"`
PublishedAt string `json:"published_at"`
Database string `json:"measurement"`
}
type data struct {
Tags map[string]string `json:"tags"`
Fields map[string]interface{} `json:"values"`
}
I think telegraf can’t parse the data tag in the json from a string (from the photon) to a map in the data struct.
Please let me know what I can do to fix this. Thanks!