Created
March 14, 2014 17:26
-
-
Save garethtdavies/9552563 to your computer and use it in GitHub Desktop.
Turning an alarm on with a Spark Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Wensleydale\SparkCore; | |
use Wensleydale\SparkException; | |
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php'; | |
//Get your access token from either the Spark Build site or make a token request | |
$accessToken = 'access_token'; | |
//Create a new Spark instance | |
$core = SparkCore::make($accessToken); | |
//Set the device that you wish to interact with | |
$core->setDeviceId('device_id'); | |
$core->setPin('D0'); | |
$core->setValue('HIGH'); | |
try { | |
$result = $core->digitalWrite(); | |
if($result->return_value) | |
{ | |
//Send an off message to the queue | |
$ironmq = new IronMQ(array( | |
'token' => 'token', | |
'project_id' => 'project_id' | |
)); | |
$ironmq->postMessage("Alarm", "Turn Off", array( | |
'delay' => 120 | |
)); | |
echo "The alarm is on. We will automatically turn it off after 120 seconds if you don't do it before."; | |
} | |
} catch (SparkException $e) { | |
echo "There was an issue with the digital write method"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment