Spark Core/Photon Integration Idea

@AndyRawson Resurrecting a old post here… sorry.
I’m working on improving the blind project mentioned above by adding a local potentiometer control and some temperature, luminance, humidity sensors.
Local control and reading on the Photon are working fine but my challenge is to have the Photon send those data back to Smartthings.

I saw your code and I was very exited to use some parts of it.

Where I am:

First on ST side:
Creating a Smartapp, basic, I was able to run in a simulator, and manually call the function using Curl, worked fine.

Then on the Photon side:
Long story short… I ended up using Webhook that you create in the CLI; it allowed me to PUT some commands/values with particle.publish in the Photon’s firmware. (in theory at least, I’m not there yet).
I had to create a JSON file with the header containing the Authorisation Bearer and send the HTTPS PUT to Smarthings containing the API Endpoint and the Token I had from the simulator, and it worked fine too.

BUT that works only with the Simulator, I have the impression that the Photon need to call some sort of authorization URL at Smartthings to get a proper Endpoint and/or Token… this concept is still very blurry to me.

So I have a couple of question for you… I know it’s been a year… but:
-In the Photon CLI, did you use any JSON file to create Webhooks?
-In Smartthing, How do we get the Endpoint and/or Token, can we get it and configure manually in the Photon, or is it changing on a regular basis?

I’m not a programmer in no means, I use bits I found useful, try to decipher and understand them and modify them to match my needs… so I’m learning a lot, but this Webhook, OAuth part, I’m very very confused…

Can you point me to the right direction?

I started making a more basic Particle.io smartapp device manager to hopefully make it easier to use and understand. I have only simplified and updated the smartapp part so far, I still need to make a simplified Particle sketch to go with it. This smartapp will take your Particle.io username and password and use that to create a particle auth token and then list all your particle devices so you can pick which one to use. Once that is done it creates the webhook and is ready to both send and receive data from the particle device. I will try and get the rest done soon but feel free to look though it and ask questions too. Just copy the code to a new smartapp and save it then go to the app settings and enable OAUTH for it.

Wow, that’s great!
I was trying to reverse engineering yesterday your code and also tried to come with something simpler too to integrate into my Smartapp.
But in the Simulator, I ended up with the same issue that I have with the code you just put together, I get:
java.lang.NullPointerException: Cannot invoke method getAt() on null object @ line 58

But in the ST App itself, I first get the Error logging in to Particle.io (Check Username and password) and log says:
error: java.lang.NullPointerException: Cannot get property ‘authorities’ on null object

If I click next and then back, I got the Success logging in to Particle.io, and Next will show me my Partcile device, so it’s working.
I mean that could be some timing issue, it seems like the ST platform is not really fully operational and experience slow down.

Anyways, I’ll take a look at the code tonight and see where I can go from there.

Did you enable the OAUTH on the smartapp? Usually that is the nullpointer problem if I remember right.

Yes I did, but there is still an issue within the Simulator… not a big deal…
I’m still working on trying to understand your Device Manager to hopefully be able to modify it for my needs.
This OAuth concept is still very blurry to me, I originally intended to initiate the OAuth from the Photon, but that’s because of my lack of understanding of the process.

Now I can see your App I see how you actually do it, and that’s a step forward to help me… but I still struggle big time with Groovy and the way the Device Handler is supposed to be integrated and to talk to the Device Manager… but I will still spend some time on it, haven’t gave up yet…

But a question though, Is it on purpose there is no Mapping section on your Device Manager? Isn’t it something mandatory to define the Endpoints?

Yeah, I never bother with the simulator. It has always been more trouble than it was worth for me.

There is a mappings section but it is down a bit before the commands section.

// api mappings for the Particle.io API to talk to the SmartThings API mappings { path("/stdata/:webhookName/:pin/:data") { action: [ GET: "setDeviceState" ] } }

I am working on the example particle sketch which will hopefully help show how that side works.

2 Likes

What code is the photon running to send/receive data with the webhooks?

I am trying to bridge the gap between them by having my photon “push” data updates to the smart things

what i have setup is a pot slider the gives me variables into the photon, now i want to set a dimmer to match the variable level whenever the photon detects that it has changed at all.

Very new to all this so any help is much appreciated!

Awesome work Andy! I studied your code and really like the work you did. I am trying to build a motion sensor (only to get up to speed with the system) from the Spark side that is pushing the event to the ST rather than the ST polling it. I see you have solved the oAuth in the particle-io-device.groovy SmartApp code and it runs nicely. What I am wondering is, can I also use the bulk of this code to build a device handler so that the motion sensor shows app under ST. Do you have any inside to share?

What I have done is created new simulated devices from the IDE and then used the smartapp to chage their state when the particle device sends an update. I was going for one particle device could be multiple different simulated devices in SmartThings since I started with replacing an old alarm system that has wired sensors.
You should be able to make a particle device type and a smartapp to manage them but I haven’t had time to spend on that to look into it more. Sounds like a good idea, let me know if you start working on it.

I’m attempting to get some virtual sensors setup to push the status of my alarm system to ST. I know this thread is pretty old so if this is no longer a good way of going about what I want any information would help.

I have the app setup and it authenticates. After then when I try to intialize the sensors I get an error when it tries to send the config file. Uncertain whether or not I have the latest app code as it doesn’t seem like the ‘configSpark’ httpPost call is sending the necessary data.

Log Error:
groovyx.net.http.HttpResponseException: Not Found

Contents of ‘configSpark’:
httpPost(“https://api.spark.io/v1/devices/${sparkDevice}/config?access_token=${state.sparkToken}","”,)

Any help would be greatly appreciated.

Hi, I am not sure I can "help but I have been also working with particle and ST.

I at one point i had particle sending events to ST, but am not currently using that. I am no sure i like the configuration setup, so I started to rewrite that but never finished.

Right now I am just using particle functions to get the status by using a smart app to poll the functions. Not as good but MUCH easier to get working.

Ultimately I want to get back to having particle send events to ST but I need to rethink this a bit.

Sorry for being so late the this conversation. This is some great information. Thank you.

I open sourced the Patriot particle.io code that I’ve been using for automating my Photon based devices with Alexa and iOS support.

Recently I reached a point where I want to get more sophisticated in my conditional control logic. I decided to stop trying to do everything myself and leverage an existing home automation system, and have decided to integrate Patriot with SmartThings.

The architecture diagram and description by pprovost at the very top of this thread looks like what is needed, but it doesn’t appear to have actually been implemented. Unless I’m mistaken, the good work done by a few others in this thread are mostly prototypes that integrate the particle.io login logic directly into a device handler instead of implementing a Service Manager. Is that correct, and if so has anyone gotten a Service Manager working with Particle.io?