phpSpark - interacting with the Spark Cloud (spark.io) using PHP

I may or may not have gone overboard attempting to answer a fellow forum member’s question about controlling his Spark Core using PHP but I am here to announce…

phpSpark

Get it while it’s hot!: Github Link

PHP Class for interacting with the Spark Cloud (spark.io)

Installation

  • GIT clone or download a zip of the repo and unzip into your project director
  • Rename phpSpark.config.sample.php to phpSpark.config.php
  • Set your access token and device id in phpSpark.config.php
  • (Optional) Copy and paste the code in spark.firmware.cpp into a new app in the Spark WebIDE & flash it to your core
  • (Optional) Run the example file phpSpark.examples.php

Usage

See phpSpark.examples.php

Implemented Features

  • List Devices
  • Get device info
  • Rename/Set device name
  • Call Spark Function on a device
  • Grab the value of a Spark Variable from a device

To Do

  • Allow for remote firmware uploads

  • Generate a new access token

  • List your access tokens

  • Delete an access token

5 Likes

Hey Harris,

I like some of the features in your class.

Ive been working on something similar for a project im working on
https://github.com/articfox1986/Makerlabs-ACS/blob/master/lib/SparkAPI.php

Very cool. I think I like your curl function a bit more. Interested in collaborating?

Im happy too. I think a mash up of our stuff will put together a really nice php spark library.

Ive sent you a pm

@harrisonhjones

I wonder if you can help me. Just a couple of questions from an absolute beginner with PHP. I see that on Github you are optionally downloading a version of Tinker to work with the PHP class. I hope to use this with my current software to work with the variable and function I have already. Do I need to make any modifications to my code for it to work with your PHP class? I have WAMP server installed on my laptop do I simply copy all your files in to a project directory in my webserver to run this system? I notice that the config file is populated with the codes required for access. If I put this system on to a commercial server should I have any concerns over privacy of the data?
I do hope you can help with my questions and sorry if there are screamingly obvious answers,

Best regards,
Clive

Hey Clive, glad to see someone interested in using the library! Answers to your questions below:

Do I need to make any modifications to my code for it to work with your PHP class?

No. As long as your code uses Spark.variable and Spark.function you are good to go

I have WAMP server installed on my laptop do I simply copy all your files in to a project directory in my webserver to run this system?

Yes sir! Let me know if you run into issues doing this.

I notice that the config file is populated with the codes required for access. If I put this system on to a commercial server should I have any concerns over privacy of the data?

There are definitely some security concerns to be considered. As long as your server does not allow remote users to download the actual PHP source code you should be fine. Ideally the config .php file would fail (die()) if it was accessed directly but that’s a fairly easy change.

Let me know if you have any additional questions. I’m happy to help!

Hi Harrison,

I am very sorry for my slow reply I have been on business trip in China.I cant wait to get this running to see if I can get a system developed. My prototypes are working just great. The functionality has incresed from my original concept but I am nearly ready to launch this to a ready and eager market. I have my system running on MS Access but am looking to move to the WAMP server with a web based system. I am going through a learning curve as I have zero experience with PHP a little experience with mySQL virtually no experience with Apache. I am sure I will be back with questions. Thanks for all the great work you and all the guys put in to this forum.

Best regards,
Clive

1 Like

This API looks great - very easy to understand!

Will this still work for newer products (ie Spark vs Particle) or will I need to modify it to suit?

The only thing that needs to be change (to my knowledge) is that, in the future, we will need to migrate to using the api.particle.io endpoint over the api.spark.io endpoint. Feel free to take a look at the library and shoot me a pull request or post an issue if you encounter a problem!