# Javascript turn on led

**URL:** <https://community.particle.io/t/javascript-turn-on-led/10589>\
**Category:** Cloud\
**Created:** [March 12, 2015, 7:10pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589 "2015-03-12T19:10:20Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![rbbahia](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rbbahia](https://community.particle.io/u/rbbahia)\
**Post date:** [March 12, 2015, 9:49pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/21 "2015-03-12T21:49:40Z")

</div>

Now receive it:

Program Start  
Executing Curl Operation  
Curl Result: ''  
Program End

---

<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 12, 2015, 9:53pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/22 "2015-03-12T21:53:21Z")

</div>

How about you change your access token and device ID to dummy values and change the `$url = …" to

`$url = 'http://requestb.in/11fj1ll1' . $deviceID . '/' + $deviceFunction ;`

Run it and then let me know so I can look at the request?

---

<div class="post-metadata">

**Author:** ![rbbahia](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rbbahia](https://community.particle.io/u/rbbahia)\
**Post date:** [March 12, 2015, 9:56pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/23 "2015-03-12T21:56:38Z")

</div>

crazy, nothing received

---

<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 12, 2015, 9:58pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/24 "2015-03-12T21:58:04Z")

</div>

How about something simple, like this:

```
<?php
$result = file_get_contents('http://requestb.in/11fj1ll1');
echo $result;
?>

```

Perhaps curl is disabled on your server?

---

<div class="post-metadata">

**Author:** ![rbbahia](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rbbahia](https://community.particle.io/u/rbbahia)\
**Post date:** [March 12, 2015, 10:05pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/25 "2015-03-12T22:05:16Z")

</div>

An OK message received

---

<div class="post-metadata">

**Author:** ![rbbahia](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rbbahia](https://community.particle.io/u/rbbahia)\
**Post date:** [March 12, 2015, 10:07pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/26 "2015-03-12T22:07:29Z")

</div>

I found that curl code working in my computer, but it get an information from spark

```cpp
    $url = 'https://api.spark.io/v1/devices/aaaaaa/result/?access_token=aaaaaaaa';
    // Initiate curl
    $ch = curl_init();
    // Disable SSL verification
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // Will return the response, if false it print the response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Set the url
    curl_setopt($ch, CURLOPT_URL,$url);
    // Execute
    $result=curl_exec($ch);
    // Closing
    curl_close($ch);

```

---

<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 12, 2015, 10:13pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/27 "2015-03-12T22:13:16Z")

</div>

Ah, I was thinking that perhaps it didn’t like the SSL part. I updated the gist. Give that a try

---

<div class="post-metadata">

**Author:** ![rbbahia](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rbbahia](https://community.particle.io/u/rbbahia)\
**Post date:** [March 12, 2015, 10:19pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/28 "2015-03-12T22:19:41Z")

</div>

made the test, nothing yet

---

<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 12, 2015, 10:24pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/29 "2015-03-12T22:24:08Z")

</div>

Well, I do apologize. I will test this when I get home and get it working. I’ll reply when I do

[Edit] Should be free in about 2 to 3 hours

---

<div class="post-metadata">

**Author:** ![rbbahia](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rbbahia](https://community.particle.io/u/rbbahia)\
**Post date:** [March 12, 2015, 10:24pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/30 "2015-03-12T22:24:58Z")

</div>

Ok thank you very much, I’m waiting for your answer.

---

<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:10am UTC](https://community.particle.io/t/javascript-turn-on-led/10589/31 "2015-03-13T04:10:50Z")

</div>

Sorry for the late response. I got… distracted ( [http://community.spark.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/1](http://community.spark.io/t/phpspark-interacting-with-the-spark-cloud-spark-io-using-php/10617/1) )

This should work for you (modify as your see fit)

```
<?php
// Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example
if((@include 'phpSpark.class.php') === false) die("Unable to load phpSpark class");
if((@include 'phpSpark.config.php') === false) die("Unable to load phpSpark configuration file");

// Grab a new instance of our phpSpark object
$spark = new phpSpark();

// Set the internal debug to false. Note, calls made to $spark->debug(...) by you ignore this line and display always
$spark->setDebug(false);
// Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here
$spark->setDebugType("HTML");

// Set our access token (set in the phpConfig.config.php file)
$spark->setAccessToken($accessToken);

// Call a Spark Function
$spark->debug("Spark Function");
if($spark->doFunction($deviceID, "led", "l,HIGH") == true)
{
    $spark->debug_r($spark->getResult());
}
else
{
    $spark->debug("Error: " . $spark->getError());
    $spark->debug("Error Source" . $spark->getErrorSource());
}
?>
```

---

<div class="post-metadata">

**Author:** ![rbbahia](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@rbbahia](https://community.particle.io/u/rbbahia)\
**Post date:** [March 13, 2015, 8:44am UTC](https://community.particle.io/t/javascript-turn-on-led/10589/32 "2015-03-13T08:44:52Z")

</div>

Hello,

I received this messages::

Spark Function

Notice: Undefined property: phpSpark::$disableSSL in …\phpSpark.class.php on line 406

Error: Unable to parse JSON. Json error = 0. See [http://php.net/manual/en/function.json-last-error.php](http://php.net/manual/en/function.json-last-error.php) for more information. Raw response from Spark Cloud = ‘’

Error SourcedoFunction

---

<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:25pm UTC](https://community.particle.io/t/javascript-turn-on-led/10589/33 "2015-03-13T16:25:32Z")

</div>

Thanks for catching that. You have your PHP enviroment set quite strict (which is good). I pushed an update to the repo. Let me know if that doesn’t fix the problem for you.

[Previous page](https://community.particle.io/t/javascript-turn-on-led/10589.md?page=1)
