Saturday, January 7, 2017

Alexa Enabled Terrarium Temperature Monitor

I recently acquired a Hogg Island boa constrictor. An important part about keeping these types of snakes is maintaining a temperature gradient across the enclosure so the snake can thermoregulate. I had a couple TTF-103 thermistors laying around so I thought it would be cool to set up a temperature monitoring system.


I decided to use the Arduino Yun I had on hand to collect the data and make it available on the internet. A quick Google search for "TTF-103 arduino" and I found some code to convert the readings from the thermistor to temperature. I added some code to log readings from two thermistors to the SD card on the Linux side of the Yun.

    File dataFile = FileSystem.open("/mnt/sd/temperature.log", FILE_APPEND);
    if (dataFile) {
         dataFile.println(getTimeStamp()+","+String(ADCPin)+","+String(fTemp,4));
         dataFile.close();

  }




I put the Yun in a Radio Shack project box and attached it to the back of the snake's enclosure with velcro.

I used regular old scotch tape to attach the thermistors inside the enclosure.



Initially I created a page using jpgraph that displays the temperature readings of both sides of the enclosure .

This was working fine, but wouldn't it be cool if I could just ask the terrarium what the temperature was like? Enter Alexa. It was actually easier than I thought to get a custom skill up and running using the Amazon documentation. The biggest issue I had was trying to get Amazon to use a page served from the web server on the Yun. No matter what I did it complained about the security of the SSL certificate I was using. I ended up finding an Amazon Lambda function that acts as a proxy to bypass this security requirement. All that was left was writing a quick page to return the temperature readings in a format that Alexa can understand.

<?php
exec("tail -n 2 /mnt/sd/temperature.log",$lines);
$left = explode(',',$lines[0]);
$right = explode(',',$lines[1]);
$readings = array('left'=>$left[2],'right'=>$right[2]);

$outputSpeech = array("type"=>"PlainText","text"=>"Left side temp ".$readings['left'] ." degrees. Right side temp ".$readings['right'] ." degrees");
$card = array("content"=>"Left: ".$readings['left']." F\nRight: ".$readings['right']." F","title"=>"Temp Readings","type"=>"Simple");
$response = array("version"=>"1.0","response"=>array("outputSpeech"=>$outputSpeech,"card"=>$card,"shouldEndSession"=>true));
header('Content-Type: application/json');
echo json_encode($response,JSON_PRETTY_PRINT);

?>

This produces JSON like this:
{
    "version": "1.0",
    "response": {
        "outputSpeech": {
            "type": "PlainText",
            "text": "Left side temp 76.5225 degrees. Right side temp 81.8562 degrees"
        },
        "card": {
            "content": "Left: 76.5225 F\nRight: 81.8562 F",
            "title": "Temp Readings",
            "type": "Simple"
        },
        "shouldEndSession": true
    }
}




How to Get Free Gogo In Air Internet

On my flight to Phoenix I was having trouble making a decision on wether or not to pay for in air internet access.  I knew I wouldn't be on long but did want to check emails. While I was trying to make up my mind, I browsed the selection of movies offered by Gogo. I decided to rent The Intern and was prompted to download the newest Gogo movie player. When I clicked the link, I was presented with a captcha before being forwarded to the App store. The thought occurred to me that it was probably not limiting access to Apple servers. I fired up Chrome and sure enough I could browse the net and check my email. The unrestricted access lasted about 15 minutes, but it was all I needed at the time.  Throughout the 5 hour flight I was able to use this trick 2 more times for a total access time of around 45 minutes.