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

**URL:** <https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617>\
**Category:** Project Share\
**Created:** [March 13, 2015, 4:07am UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617 "2015-03-13T04:07:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [March 13, 2015, 4:07am UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/1 "2015-03-13T04:07:57Z")

</div>

_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…_

![](https://community.particle.io/uploads/particle/4863/92fe2a437811901f.png)

# phpSpark

Get it while it’s hot!: [Github Link](https://github.com/harrisonhjones/phpSpark)

PHP Class for interacting with the Spark Cloud ([spark.io](http://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

---

<div class="post-metadata">

**Author:** ![Devin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/devin/32/4796_2.png) [@Devin](https://community.particle.io/u/Devin)\
**Post date:** [March 13, 2015, 8:16am UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/2 "2015-03-13T08:16:15Z")

</div>

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](https://github.com/articfox1986/Makerlabs-ACS/blob/master/lib/SparkAPI.php)

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [March 13, 2015, 8:27pm UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/3 "2015-03-13T20:27:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Devin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/devin/32/4796_2.png) [@Devin](https://community.particle.io/u/Devin)\
**Post date:** [March 15, 2015, 8:03am UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/4 "2015-03-15T08:03:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casm](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/casm/32/4242_2.png) [@casm](https://community.particle.io/u/casm)\
**Post date:** [July 4, 2015, 9:33am UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/5 "2015-07-04T09:33:27Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [July 6, 2015, 11:01pm UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/6 "2015-07-06T23:01:27Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![casm](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/casm/32/4242_2.png) [@casm](https://community.particle.io/u/casm)\
**Post date:** [July 12, 2015, 10:35am UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/7 "2015-07-12T10:35:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johnventions](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/johnventions/32/6622_2.png) [@johnventions](https://community.particle.io/u/johnventions)\
**Post date:** [August 14, 2015, 1:40pm UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/8 "2015-08-14T13:40:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [August 14, 2015, 7:50pm UTC](https://community.particle.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/9 "2015-08-14T19:50:11Z")

</div>

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](http://api.particle.io) endpoint over the [api.spark.io](http://api.spark.io) endpoint. Feel free to take a look at the [library](https://github.com/harrisonhjones/phpSpark) and shoot me a pull request or post an issue if you encounter a problem!
