GroveStreams

particle electron example for multiple vars463

micromet private msg quote post Address this user
Could anyone refer me to an example on how to route multiple variables from a particle electron/photon to GS ?

I worked through the simple example - no problem
https://www.grovestreams.com/developers/getting_started_particle_webhook.html

However, now I need to publish and webhook multiple floating point variables (like data from a weather station).

My main issue is correctly formatting the publish command and webhook on the particle side so its compatible with GS.

A good example of something similar would be REALLY useful.

Thanks,
Post 1 IP   flag post
MikeMills private msg quote post Address this user
I see you posted on the Spark Forum too (https://community.particle.io/t/how-to-construct-a-webhook-that-doesnt-send-event/23763).

@ctmorrison 's solution in that thread will work if you are familiar with the Spark command line tool to create the webhook.

Otherwise, I think you could still use the technique in the GS example. The Spark webhook, under the covers, is creating a GS "All on the URL" HTTP Feed PUT call. The URL, with multiple values, would look like this:

http://grovestreams.com:80/api/feed?compTmplId=compTmpl1&compId=comp1&compName=Weather&f=3&g=4&h=4.0&i=sw&api_key=0ccc2159-2697-3dcd-a211-588e9ccbed71

The device lets you push up one value so push up a bunch of data in one shot as a single string like this:

Spark.publish("f", "3&g=4&h=4.0&i=sw" , 60, PRIVATE);


I haven't tried this, but in theory, the webhook parser will plug-in the published string into the URL it generates.
Post 2 IP   flag post
MikeMills private msg quote post Address this user
Just tweaked the code above from "=3&g=4&h=4.0&i=sw" to "3&g=4&h=4.0&i=sw"
Post 3 IP   flag post
micromet private msg quote post Address this user
Thanks Mike,

I was able to get this working using the examples and generous help from @ctmorrison

I used the CLI based approach to create the webhook (described in the links in particle forum ) - I found this much easier than the hook builder in particle - IMO.

https://community.particle.io/t/how-to-construct-a-webhook-that-doesnt-send-event/23763

Did find that using the sprintf command to be a bit tricky - follow @ctmorrison syntax very carefully .

I worked up a nice example to webhook multiple variables to GS for a BME280 sensor (T,RH,P) connected to a particle electron - if anyone is interested.
Post 4 IP   flag post
micromet private msg quote post Address this user
We have run into some problems with the above-mentioned approach when the strings we get very large. For example, we need to upload 23 temperatures to the same time series table on a GS dashboard (via our Particle electrons). I was not able to publish and webhook this large string to Grovestream without getting a webhook error (401). I checked the string published to partitcle io and it looked fine. However, when I broke the data into two strings - half the size (and two webhooks) it worked fine . The problem is the data comes into GS with two different time stamps (not fine -makes a mess on the times series table).

Is there a http limitations on string size comming into GS via a put command ?

Any ideas
Post 5 IP   flag post
MikeMills private msg quote post Address this user
401 usually indicates an authentication error. I wonder if your large string was assembled incorrectly and GS couldn't parse out the api_key.

GS allows for very large strings. Was there an error inside your GS Organization System notifications? If so, can you post it? If not, then GS couldn't extract the api_key from the URL or the URL was corrupt. Email me the api_key and I'll search our logs to see if it even made it to our servers and if so, what the error was.
Post 6 IP   flag post
tokp private msg quote post Address this user
"I worked up a nice example to webhook multiple variables to GS for a BME280 sensor (T,RH,P) connected to a particle electron - if anyone is interested."

I am new to webhooks and GS. Tried to work through their tutorial for particle integration but still getting snagged up.

As I'm trying to publish data from a weather station I am putting together, I'd like to see your example of the webhook.

Thanks,
Post 7 IP   flag post
MikeMills private msg quote post Address this user
Any System Notifications in your Organization (click the envelope)?

Turn on API tracing to see if the calls are even making it to GroveStreams.
Post 8 IP   flag post
tokp private msg quote post Address this user
This is my first attempt at webhooks/Grovestreams and the only thing to go on is the tutorial. It appears to be outdated as some of the screenshots and fields used in the example do not exist or line up with what is in the particle webhook creator.

I am in the process of trying to read up more on webhooks so I can understand what each of the fields and terms mean to see if I can figure out how to integrate with Grovestreams. It's a very slow process.

So in a nutshell, I haven't been able to create the webhook yet.
Post 9 IP   flag post
MikeMills private msg quote post Address this user
Thanks for letting us know about the outdated example. We're taking a look at it.
Post 10 IP   flag post
MikeMills private msg quote post Address this user
Finally got our old particle cellular board running. Had to update the firmware as it's a couple of years old. Took a while to figure out it had an antenna and had to find that and connect it. Our old example webhook is still functioning.

I'm going to try and pass two variables up and modify the example to show that. Stay tuned...
Post 11 IP   flag post
ctmorrison private msg quote post Address this user
Let's see if this helps. I've been sending multiple variables for quite some time, so I'm going to try and copy-paste the info shown on the console for one of my many webhooks. By the way, I now create webhooks via the web console, as it's easier than the command line IMHO.

In my case, I need to send a dozen floating point numbers and a dozen digital status points. In the interest of cutting down data, I've "compressed" the analog values by multiplying them by 100, cut them to 5 characters (the range is -99.00 to 230.00) and simply separating them with a "|" character (not needed, but makes the string easier to read). I simply send the digitals as one long string of 12 one's or zero's. In both cases, I then decompress these via derivations in Grovestreams. I don't know if this is a "smart" way to do it, but it has cut down on data significantly, at the expense of CPU cycles on the server.

So, here's my webhook:
Event Name
The Particle event name that triggers the webhook
gsc
Full URL
The target endpoint that is hit when the webhook is triggered
http://grovestreams.com/api/feed
Request Type
The standard web request method used when the webhook is triggered
PUT
Request Format
How the webhook data will be encoded and passed to the target endpoint
Web Form
Form
Form data that will be sent along with the webhook

{}

Query Parameters
Parameters to append the URL string when hitting the webhook endpoint

{
"compid": "{{c}}",
"a": "{{a}}",
"d": "{{d}}"
}


Headers
HTTP Headers to include when hitting the webhook endpoint

{
"Content-Type": "application/x-www-form-urlencoded",
"X-Forwarded-For": "{{PARTICLE_DEVICE_ID}}",
"Host": "grovestreams.com",
"Cookie": "api_key={{k}}",
"Connection": "close"
}


Enforce SSL
Whether your webhook will will validate the certificate against its certificate authority chain
Yes
-----------------------------------------
And here's just the call in my Particle code:
sprintf(gsString,"{"c":"%s","k":"%s","a":"%s","d":"%s"}",gComponentID,gGSAPIkey,gAI,gDI);
//the gsadc webhook expects the analog and digital inputs to be scrunched together. GS will parse them.
Particle.publish("gsc",gsString,60,PRIVATE);

In essence, I build a JSON string to pass to the webhook. In my case "gAI" is the string I've created with all of the floating points squished together and gDI is simply the string of 1's and 0's showing the status of the inputs.

I don't know if this helps, but conceptually, it should convey how to send 2 variables and sending 20 or 30 would simply just expand upon this approach.
Post 12 IP   flag post
ctmorrison private msg quote post Address this user
By the way, I have an example that doesn't involve "compressing" the variables, if that helps. However, it's very similar in concept to the above -- there are simply more elements in the JSON string and the associated webhook!
Post 13 IP   flag post
MikeMills private msg quote post Address this user
@ctmorrison Derivation to parse the single value was an option I was considering.

I think this is what you're doing:
1) The webhook passes the single delimited value into a single STRING/TEXT GS stream
2) Edit the component (right click on it and choose Edit) and create a stream for each variable in the delimited string
3) For each new Derived stream:
* Set its value type to the correct type (long, float, int, ...)
* Derive it from Expression. Set the effective date to an earlier date to capture any historical data
* Add the delimited stream as a variable
* Set its expression to substring(var1, 0, 5)
** change the second parameter to the location of the variable you want in the delimited string. The third parameter is how many characters you want
** GS will automatically convert the substring to the value type of the derived stream

Using substring forces you to ensure your delimited string variables have a known length. I think GS needs a split(..) function. I thought we had one. Might add it.

@ctmorrison Are you using substring to parse the string or something else?
Post 14 IP   flag post
ctmorrison private msg quote post Address this user
Here's an example of a derivation calculation:
fromBase(mid(var1,0,4),10)/10

This takes 4 characters starting with the first (position 0) and converts it to a floating point stream in base 10.

Actually, above I think I incorrectly said I multiply the floating point by 100, but in reality, I multiple it by 10 and convert it to an integer that I then concatenate into the long string I pass.
Post 15 IP   flag post
MikeMills private msg quote post Address this user
We're still having trouble getting the particle IDE to show the flash button enabled. Might be a version issue.

Anyway, I could open the webhook and look at it. This might help. Change the event name to match yours. Remove the 2 in the x-forwarded-for value:


Post 16 IP   flag post
tokp private msg quote post Address this user
Thanks @ctmorrison and @MikeMills. You have clarified some things and I have set up a webhook.

the error I am getting from particle is "error status 400 from grovestreams.com"

on the Grovestreams side I get the system notification with heading "API Exception: compId url parameter is missing."

I'm getting closer....
Post 17 IP   flag post
MikeMills private msg quote post Address this user
That's a required query parameter. See the screenshot above with compId. Do you have compId set as a query parameter in your webhook?
Post 18 IP   flag post
tokp private msg quote post Address this user
Bingo, I had a space between 'comp' and 'id'. Data is coming through now.

Thanks for your help!
Post 19 IP   flag post
2965 19 19
Log in or sign up to compose a reply.