Is there a way to set a PIN to HIGH or send a message to a Photon/Electron ?
I’m trying to place an Electron on a jet ski, however, would only want to have the electron publish the GPS coordinates when I ask it to. The logical place to do this is with a web page containing the access token and device ID. I know web hooks can act on data published with the Particle.publish() function, however, I’m wondering if there is reverse of that from the cloud to the device?
Any and all remote internet based actions, be it from the device to the cloud or otherwise will consume data. How else would you communicate with it via the cloud? The alternative is to send it a text, using a non-Particle SIM, but that’s more expensive, so I wouldn’t recommend that.
The GPS data would only be demanded if lost/stolen, someone didn’t come back to the boat/meeting place on time or to test to make sure everything is working. it would send/publish data in the following format GMT Time, Date, Long, Lat. (about 45 characters).
For a function call you’d need a POST request, rather than the GET request your browser is making. If you want to just test for functionality, you could try this page to test the functions easily: http://jordymoors.nl/interface
If you want to learn how to do it yourself, go with this: Tutorial: Spark Variable and Function on One Web Page
Thanks for the tips. I’ve now decided to move away from the Particle.publish() and Particle.function() approaches. I found Particle.variable() works much better and less overhead for me. The only problem I have now is how to parse what is coming back from the URL. The HTML I have below, won’t do a post (pressing the get! button) returns a 401 unauthorized error in the console. This appears due to the fact that the access_token is not making its way to the GET request. I’m fairly certain, I’m missing something and I hope you can point me in the right direction. I’m fairly certain the access_token being null is my problem. I’m just not sure where to add it. Any help would be greatly appreciated.
Hmm, it seems as though you’re still using the old spark JS library which has since been superseded by the Particle API library. If at all possible, do consider switching. If that’s not possible, then you can check these old docs. You’re missing a login in there (you can use an accesstoken or regular credentials for that). https://github.com/spark/sparkjs/blob/master/examples/node/get-variable.js
I used your code from http://jordymoors.nl/interface/ page, so I’m fairly certain it works. When I login to your page, I get what is shown in the screenshot below.
The URL works, it gives me the data back that I need, but I suspect to do it properly, I will need to execute it from within an HTML document and then capture what comes back for it work like your code below does. If I need to change the JS lib, I have no problem doing that, I was just going with what worked on your page. Also do I have to login if I use both the deviceID and Access_Token?
That’s the important clue.
The login procedure requests an access token which will then be used for the next page.
So in order to have your own page do the same, you need to go through the login process just the same.
If I use this URL (shorten to hid the full deviceID and access_token) and I’m not logged in, I get the results that follows the URL listed below. If I use both do I need to login?
It kinda depends on which library you’re using. The old JS library (the code above, and on my interface) requires you to log in with either credentials or an accesstoken. It’s a requirement for the library to somehow internally store the accesstoken for further use. The new library however allows you to log in using your credentials only after which it gets an accesstoken that it stores/uses in the ‘user code’. Thus, if you know the accesstoken, you can skip the logging in step and just use the accesstoken as-is.
So, if you’re not going to use either library, then just use that fixed URL and handle the data any way you’d like. If you do intent on using a JS library, there are two options:
use the old library -> log in, using the accesstoken or regular credentials.
use the new library -> use an accesstoken directly, or acquire one by logging in with regular credentials.