So my second spark project (I wish i got more than one core as a beta tester!)
I decided to create a ripoff of this awesome costume (http://youtu.be/GkBDRUO8hAo)
But with a little spark magic! I hooked up the LEDs to a relay board, and then connected the spark to the board. We carried 12v batteries in a bag hooked to our belts.
So here is the basic video:
http://youtu.be/Nb61sPq-2sE
When anyone texted the word “Where is the devil?” to a phone number, my eye turned red and the pitch fork and/or eyes lit up. (i was carrying a 4g hotspot)
I was also able to control the full suit from a series of SMS code words. If i sent “White off” or “White on” the LED would turn on or off. Same went for the red. I absolutely could have done that all with hard buttons, but using code and a cell phone is so much more fun!
This was all done with a bit of twilio magic, and this hacked together PHP script
<?php
// now greet the sender
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$key = 'XXXXXXXXXXXXXXXXXXXXXX';
//D0 -- eyes
// D1 -- pants
// D2 -- upper
// D3 -- staff
if($_REQUEST['Body'] == "White off")
{
changeWhite($key, "HIGH"); // turn OFF white
}
else if($_REQUEST['Body'] == "Red off")
{
changeRed($key, "HIGH"); // turn OFF red
}
else if($_REQUEST['Body'] == "Red on")
{
changeRed($key, "LOW"); // turn ON red
}
else if($_REQUEST['Body'] == "White on")
{
changeWhite($key, "LOW"); // turn ON white
}
else if(strpos($_REQUEST['Body'] ,'devil') !== false)
{
changeRed($key, "LOW"); // turn ON red
sleep(5);
changeRed($key, "HIGH"); // turn OFF red
}
else if(strpos($_REQUEST['Body'] ,'Devil') !== false)
{
changeRed($key, "LOW"); // turn ON red
sleep(5);
changeRed($key, "HIGH"); // turn OFF red
}
function changeRed($key, $pin_level)
{
$pin = "D3";
$result = hitTheSpark($key, $pin, $pin_level);
$pin = "D0";
$result = hitTheSpark($key, $pin, $pin_level);
}
function changeWhite($key, $pin_level)
{
$pin = "D2";
$result = hitTheSpark($key, $pin, $pin_level);
$pin = "D1";
$result = hitTheSpark($key, $pin, $pin_level);
}
function hitTheSpark($key, $pin, $pin_level)
{
$post_data = "access_token=$key&pin=$pin&level=$pin_level";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sprk.io/v1/devices/avidan');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//var_dump($ch);
$result = curl_exec($ch);
$response = curl_getinfo( $ch );
return $result;
}
?>
<Response>
<Message>Thanks <?php echo "Happy Halloween!"; ?></Message>
</Response>