A public spark.function, with no token

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.



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.


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.

Have you seen @wgbartley post about a simple PHP proxy?

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!




Nice! :hand:! Thank you for the hard work and for any code you can share :wink: