Hi all,
I am setting up a system in which users can turn on and off some appliances in my home. Using the example posted here: https://community.spark.io/t/tutorial-spark-variable-and-function-on-one-web-page/4181 by @bko , I have it almost working. (that is, I have it working using an offline html file on my laptop)
The final step is putting it all online, which would mean exposing my token. I have read that it should be easy to do using some php-stuff, but to me, the most logic way would be to declare that a given function on the core can be excessed publicly. Is their any way to do this? Otherwise, can people point me to a good tutorial on how to use the example by @bko in a secure way, keeping in mind that this is the first project ever in which I use javascript and have never used php before.
thanks
Rolf
Elijah
July 26, 2014, 10:49pm
2
Here is a project someone just posted that does use PHP, but they have the code on a github repository (look for the “Download in a zip” button).
Hi @Elijah ,
the github repo only contains the firmware part of the project by @jbennett and not the web-php part, unfortunately.
Rolf
Elijah
July 26, 2014, 11:17pm
4
Hi @jbennett would you be willing to post your spark_post.php function (obfuscated of course) with the repository?
@Elijah @RolfHut
Sure. I’ll post the web portion later this evening.
bko
July 27, 2014, 2:16am
6
Have you seen @wgbartley post about a simple PHP proxy?
There’s at least a half dozen PHP proxies/wrappers in the forums already, but I wanted one that was a little more flexible. This one should take whatever GET or POST request you throw at it, append your access token, and then pass it on to the Spark...
Reading time: 4 mins đź•‘
Likes: 19 ❤
@RolfHut
You’re better using the proxy code than looking at my implementation.
I ran into SSL Certificate verification errors though. See this thread: http://community.spark.io/t/php-ssl-certificate-problem-solved-seeking-explanation-why/5984 .
So you may need to add:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
to the proxy code.
If you have issues getting it all working together, I can share my implementation. I looked at it and I’d want to clean it up before posting it to the repo.
This took more time than I like to admit, but I got it working with the php-proxy. Tonight was a crashcourse in both JS and PHP for me.
Now that I have the basic functions working, I’ll “beautify” the project and post it on this forum when done. Thanks all!
Rolf
3 Likes
Elijah
July 27, 2014, 12:48pm
9
@RolfHut
Nice! ! Thank you for the hard work and for any code you can share