Skip to content

Instantly share code, notes, and snippets.

@garethtdavies
Created March 14, 2014 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethtdavies/9552563 to your computer and use it in GitHub Desktop.
Save garethtdavies/9552563 to your computer and use it in GitHub Desktop.
Turning an alarm on with a Spark Core
<?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