Things used in this project

Hardware components:
Intel.web.720.405
Intel Edison
Uses the Edison breakout board.
×1
Philips hue 431650 bulb single lg. v370602166
Philips hue
Requires the basic kit (Hue Bridge and 1 Bulb)
×1
Adafruit SI1145 UV/IR/Visible Light Sensor
Collects visible light readings measured in Lux.
×1
Software apps and online services:
Ha 2up iot
Amazon Web Services AWS IoT
Reads in the light sensor data from Edison, and only passes data along to SNS if the light reading is above/below a specified level.
Screen%20shot%202015 07 20%20at%206.10.26%20pm
Amazon Web Services AWS Lambda
Reads in light sensor data from SNS and sends a command message over a topic to the IFTT Maker Channel.
Simpleicon sns
Amazon Web Services AWS SNS
Passes along the light sensor data from IoT to Lambda.
Iam logo
Amazon Web Services AWS IAM
Manages the permissions needed to send light sensor data between AWS services.
Q8wtlimqnp04fzhtr9v5
IFTTT Maker service
Receives commands from AWS and tells Hue to turn on/off light.

Schematics

Edison + SI1145
Edison light bb

Code

AWS Lambda CodeJavaScript
This is the code that tells AWS Lambda to send a message to your IFTT event name over the Maker channel.
TO DO:
1. Cut and paste this code under the "Code" tab of an AWS Lambda function.
2. Replace the "iftttMakerSecretKey" value you generated when you set up the IFTT Maker channel in your account.
3. Replace the "iftttMakerEventName" value with the event name you created when setting up the Hue recipe on the IFTT website.
console.log('Loading function');

var https = require('https');
var querystring = require("querystring");

// IFTTT Maker Configuration, see https://ifttt.com/maker for more info
var iftttMakerEventName = 'YOUR_IFTTT_RECIPE_EVENT_NAME' // You can use a different IFTTT Maker EventName here
var iftttMakerSecretKey = 'YOUR_IFTTT_USER_KEY';

var iftttMakerUrl =
    'https://maker.ifttt.com/trigger/'
    + iftttMakerEventName
    + '/with/key/'
    + iftttMakerSecretKey;

exports.handler = function(event, context) {
    var message = event.Records[0].Sns.Message;
    console.log('From SNS:', message);

    // The output to send, you can optionally filter/edit the original SNS message here
    var output = message;
    console.log('Output: ', output);

    // The output is send as 'value1' to IFTTT Maker 
    var params = querystring.stringify({value1: output});

    https.get(encodeURI(iftttMakerUrl) + '?' + params, function(res) {
        console.log("Got response: " + res.statusCode);
        res.setEncoding('utf8');
        res.on('data', function(d) {
            console.log('Body: ' + d);
        });
        context.succeed(res.statusCode);
    }).on('error', function(e) {
        console.log("Got error: " + e.message);
        context.fail(e.message);
    });

};
Intel Edison with Light Sensor CodeJavaScript
Upload this Node.js code to an Intel Edison that is connected to a SI1145 uv/ir/visible light sensor.

TO DO:
Configure the device parameters with your Edison's values:
1. AWS IoT private.pem.key
2. AWS IoT certficate.pem.crt
3. Your Edison's hostname
4. The AWS region you are using AWS IoT
5. SNS topic name to: device.subscribe and device.publish
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */

//* CONFIGURE and DEFINE

var fs = require('fs');
var os = require('os');
var mraa = require('mraa'); //require mraa
var si_lib = require('jsupm_si114x');
var AWS = require('aws-sdk');
var awsIot = require('aws-iot-device-sdk');


// AWS IoT DEVICE
 var device = awsIot.device({
   keyPath: '/home/root/awsCerts/YOUR-AWS-IOT-private.pem.key',
  certPath: '/home/root/awsCerts/YOUR-AWS-IOT-certificate.pem.crt',
    caPath: '/home/root/awsCerts/root-CA.crt',
  clientId: 'YOUR-EDISON-NAME',
    region: 'us-east-1' // fill this in with the AWS region you are using
});

// Connect to AWS IT and publish a test output "testData: 1" to the SNS topic
device
  .on('connect', function() {
    console.log('connect');
    device.subscribe('YOUR-SNS-TOPIC');
    device.publish('YOUR-SNS-TOPIC', JSON.stringify({ testData: 1 }));
    });


// define light sensor and get the Edison's host name
var uv = new si_lib.SI114X(1);
var deviceId = os.hostname();


// initialize sensors and services
uv.setUVCalibration(0,9,5,0);
//uv.setUVCalibration(4,21,2,0);
uv.initialize();

// CALL THE PERIODIC ACTIVITY FUNCTION
periodicActivity(); 



// * Periodic Activity Function - Runs in a loop with wait in between

function periodicActivity() 
{  
    
// get the light sensor reading  
var uv_visible = uv.readWord(0x22); // lux

  
//*** This section is for debugging with XDK console output ***//
/*    
    // get the current date in ISO format
var date = new Date;
var time_now = date.toISOString();
    
    var json = {
        device_id: deviceId,
        time: time_now,
        uv_visible: uv_visible // lux
    };
    
var payload = JSON.stringify(json);    
console.log(payload);
*/


// Publish the light sensor reading to the AWS SNS topic
device.publish('YOUR-SNS-TOPIC', JSON.stringify({uv_visible: uv_visible}));
 

setTimeout(periodicActivity,10000); // run periodicActivity again in 10 seconds
    
}
AWS Lambda Role PolicyPlain text
generated automatically when creating lambda, here for reference.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "arn:aws:logs:*:*:*"
        }
    ]
}
AWS SNS Role PolicyPlain text
{
    "Version": "2012-10-17",
    "Statement": {
        "Effect": "Allow",
        "Action": "sns:Publish",
        "Resource": "arn:aws:sns:us-east-1:973529660983:hue-office-topic"
    }
}
AWS IoT Rule SQL QuerySQL
This is the SQL query that IoT runs against incoming data. The query only selects to ingest data from the SNS hue-office-topic when the uv_visble < 400.
SELECT uv_visible FROM 'hue-office-topic' WHERE uv_visible < 400

Credits

Helicockpit
truthkos

Climate science hacker.

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

RadBit
Intermediate
  • 297
  • 7

FitBit-type bluetooth radiation sensor for tracking radiation exposure (working around X-rays in the hospital, or just life in general).

Quizmo
Intermediate
  • 238
  • 4

Full instructions

A gadget to help your kids practice basic arthematics

Illuminate Me
Intermediate
  • 609
  • 11

Full instructions

Connect your microcontroller to a NeoPixel Ring with Azure to make it light up on new tweet!

Smart 3D printer Filament Counter (FilamentBot)
Intermediate
  • 1,866
  • 10

Full instructions

For 3D makers the worst thing is running out filament in the middle of a hours long print. This device will order for you when it is low!

Voice Control Chip-E With Google Home
Intermediate
  • 267
  • 3

Full instructions

Want to control a robot with your voice? Here's a great place to start with a Google Home, IFTTT, a WiFi enabled microcontroller and Arduino

Arduino-Powered Water Bottle
Intermediate
  • 2,693
  • 22

Full instructions

A water bottle that can keep track of your water intake and reminds you to drink enough water.

ProjectsCommunitiesContestsLiveJobsBetaFree StoreBlogAdd projectSign up / Login
Respect project