Connect Particle and InfluxDB with a webhook

Hi community,

I read many topics here about InfluxDB but there is no current solution. Are there any news? My use case is the following:

I want to stream data from a electron to my influxDB via webhooks. In general I want to execute something like this:

curl -i -XPOST 'http://myIPaddress:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server02 value=0.67 1422568543702900257
cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257
cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257'

The problem is, that InfluxDB doesn’t accept json anymore. It has its own line protocol syntax.
I managed that the event value is the whole string in the single quotes after --data-binary. I tried to put the method as POST, the url as http://myIPaddress:8086/write?db=mydb and the query parameter “data.binary”. This failed because Particel transfer everything as json and a parsing error appears.

Did anyone solve this? :innocent:

Niklas

I find it’s easiest to write a python script that receives the stream of particle events via server side events (SSE) and then posts to InfluxDB via the InfluxDB python module.

So I should configure the webhook to send the events to a python script on my server (for example running on a flask webserver)? Then this python script transform the data and stream it to the python interface of InfluxDB.

Or what do you mean with SSE? Is there are smarter way than the way described above?

EDIT: I searched a little bit in docs and find a possible smarter way. I will try it and post my solution here. I use the python library sseclient and the docs from here: https://docs.particle.io/reference/api/#get-a-stream-of-events

Here my code:

from sseclient import SSEClient
import json

messages = SSEClient('https://api.particle.io/v1/devices/events?access_token=[token get in settings in build section]')
for msg in messages:
    if(msg.event == "yourEventName"):
       print("New custom event arrived: " + msg.data)
       eventContent = json.loads(msg.data)
       print(eventContent["data"])

Then you have to process the data with the InfluxDB Python interface. If someone needs help, please contact me.