How to Construct a Webhook that Doesn't Send "Event="?


#1

I have pesky a little proble. Using the Webhook Builder I can put together everything I need to send data to my backend of choice (Grovestreams), using a query param of “{{PARTICLE_EVENT_NAME}}”: “{{PARTICLE_EVENT_VALUE}}”,. But Grovestreams likes it’s data in the format a=1&b=2&c=3 and so on. I can bundle up a Particle.publish to include all this. BUT, the Webhook always sends it as Event=a=1&b=2&c=3. That first = naturally confuses Grovestreams. Is there an easy way to avoid the Webhook adding the “Event=” bit? Or can JSON be used to construct it another way? @ctmorrison, I know you are a Grovestream fan, how did you make it work?


#2

@JethroNull, here’s one of my (many) webhooks. Do you also need help with the string I’m publishing?

{
    "event": "grovestreams_d",
    "url": "http://grovestreams.com/api/feed",
    "requestType": "PUT",
    "headers": {
          "Host":"grovestreams.com",
          "X-Forwarded-For": "{{gComponentID}}"
     },
    "query" : {
       "compid" : "{{gComponentID}}",
       "api_key" : "{{gGSAPIkey}}",
       "di1" : "{{di1}}",
       "di2" : "{{di2}}",
       "di3" : "{{di3}}",
       "di4" : "{{di4}}",
       "di5" : "{{di5}}",
       "di6" : "{{di6}}"
    },
    "mydevices": true,
    "noDefaults": true
}

In case it isn’t obvious, I do call to following to publish my data.

Particle.publish("grovestreams_d",gDstring,60,PRIVATE);

#3

Yeah, please, that way I won’t waste too much time asking you silly questions :wink:

Do you use this in the Webhook Builder JSON custom data section or from the CLI?


#4

I created the webhook as a text file and then issued particle webhook create filename.json command via the CLI


#5

This is very simplistic, but here’s an example of how to build the string I publish:

sprintf(gDstring,"{\"gGSAPIkey\":\"%s\",\"gComponentID\":\"%s\",\"di1\":\"%u\",\"di2\":\"%u\",\"di3\":\"%u\",\"di4\":\"%u\",\"di5\":\"%u\",\"di6\":\"%u\"}",gGSAPIkey,gComponentID,digitalRead(di1),digitalRead(di2),digitalRead(di3),digitalRead(di4),digitalRead(di5),digitalRead(di6));

I guess I need to publish an entire example, but due to the issues with webhook reliability, I’ve considered asking the GroveStreams guys to offer MQTT as an interface instead.


#6

Bingo! Thanks @ctmorrison. That’s looking good. I’ll swap it out for my data but I’m getting all the way through to GS now.


#7

Particle & Grovestream = a great combination!

or should that be == :wink:


#8

SO RIGHT :blush:


#9

Great info here for us newbies trying to webhook particle data to Grovestreams .

I’m teaching a college course and want to develop an weather station example that can publish and webhook multiple datapoints to GS (e.g. temp, humidity, pressure, etc.). The students are in the applied natural sciences - are new to this technology.

Here are a few quick questions (you may just refer me to other discussions or links, hope not to waste your time)

I’m real new to dealing with webhooks .

  1. I assume I can just put custom JSON code like ctmorrison showed in the webhook builder (send custom data - JSON) instead of using the CLI, I think that might be easier for the students ? Meanwhile I’ll try learn more about using the “particle webhook create” - seems like it might have some advantages.
  2. I’m a little confused about what the gComponentID and how it should be parameter in the ino file
  3. Is there a good example of something like a weather station program for the particle photon or electron that shows the ino program and corresponding webhook build. Maybe share one of you complete examples or post on github

Any help or suggestions would be appreciated.

Thanks