Things used in this project

Hardware components:
R8326274 01
Raspberry Pi 2 Model B
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×1
826 04
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1
12002 04
Breadboard (generic)
×1
Software apps and online services:
Ha 2up iot
Amazon Web Services AWS IoT
Euql3txfwdp9zefpdfp6
Netflix

Schematics

NetflixOnComputer.js
The script you run on the computer
NetflixScriptOnComputer.js
ScriptToRunOnRaspberryPi.js
The script to run on the Raspberry Pi
ScriptToRunOnRaspberryPi.js
ButtonTest.py
To test the button and resolve problems
ButtonTest.py
Button setup
To setup the button and the Raspberry Pi
Schermafbeelding%202016 01 31%20om%2009.43.18

Code

ScriptToRunOnRaspberryPi.jsJavaScript
Script to run on Raspberry Pi
var awsIot = require('aws-iot-device-sdk');
require('shelljs/global');
var myThingName = 'RaspberryPiLed';
var thingShadows = awsIot.thingShadow({
   
//To connect to the AWS IoT service 
  keyPath: '/Path/to/AWS/Key',
  certPath: '/Path/to/AWS/certificate',
  caPath: '/Path/to/the/root-CA.crt',
  clientId: myThingName,
  region: 'Your Region'
});

var object = '{\\"state\\":{\\"reported\\":{\\"Pause\\":\\"true\\"}}}'
thingShadows.register( 'Pause' );

mythingstate = {
  "state": {
    "reported": {
      "Pause": "false"
    }
  }
}

var Gpio = require('onoff').Gpio,
  button = new Gpio(14, 'in', 'both')
button.watch(function(err, value) {
//To handle button input
var Unpause = exec('aws iot-data update-thing-shadow update-thing-shadow --thing-name RaspberryPiLed --payload ' + object)
console.log(mythingstate["state"]["reported"]["Pause"])
  console.log(mythingstate["state"])


});
 delete mythingstate['version']; 
 console.log(mythingstate["state"]["reported"]["Pause"])
  console.log(mythingstate["state"])
  var response = thingShadows.update(myThingName,  mythingstate);
  console.log(response)
var networkInterfaces = require( 'os' ).networkInterfaces( );
// PIR sensor connected to pin 7
// You can use any gpio pin 
// install npm button library first
thingShadows.on('connect', function() {
  console.log("Connected...");
  console.log("Registering...");
  thingShadows.register( myThingName );
  console.log("mythingstate = false")
  setTimeout( function() {
    console.log("Updating my IP address...");
    clientTokenIP = thingShadows.update(myThingName, mythingstate);
    console.log("Update:" + clientTokenIP);
    delete mythingstate['version'];

  }, 2500 );
});
ButtonTest.pyPython
Script to test the button
import RPi.GPIO as GPIO
import time
import random

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
button = 14
GPIO.setup(button, GPIO.IN, GPIO.PUD_UP)
while True:
     if GPIO.input(button) == False:
           print("Button pressed")
GPIO.cleanup()
NetflixScriptOnComputer.jsJavaScript
Script to run on your computer
robot = require('robotjs')
require('shelljs/global'); 
var awsIot = require('aws-iot-device-sdk');

var myThingName = 'RaspberryPiLed';


var thingShadows = awsIot.thingShadow({
   
//To connect to the AWS IoT service 
  keyPath: '/Path/to/AWS/Key',
  certPath: '/Path/to/AWS/certificate',
  caPath: '/Path/to/the/root-CA.crt',
  clientId: myThingName,
  region: 'Your Region'
});


mythingstate ={
    "state": {
        "reported": {
            "Pressed": "true"
        }
    }
}

var object = '{\\"state\\":{\\"reported\\":{\\"Pause\\":\\"false\\"}}}'

var networkInterfaces = require( 'os' ).networkInterfaces( );
function CheckState() {
var CheckPause = exec('aws iot-data get-thing-shadow --thing-name ' +myThingName+ ' output.txt && cat output.txt', function(status, output) {
if (output.indexOf("\"Pause\":\"true\"") > -1){
    robot.keyTap('space')
    //To click space
    console.log("Pause")
    //To check if the button is tapped on the Raspberry Pi
    var Unpause = exec('aws iot-data update-thing-shadow update-thing-shadow --thing-name ' +myThingName+' --payload ' + object)
    //To stop continuing to click space
}
});
}
thingShadows.on('connect', function() {
  CheckState();
  console.log("Connected");
  console.log("Registering");
  thingShadows.register( myThingName );
  // An update right away causes a timeout error, so we wait about 2 seconds
  setTimeout( function() {
    console.log("Updating my IP address...");
    UpdatedIP = thingShadows.update(myThingName, mythingstate);
    console.log("Update:" + UpdatedIP);
    CheckState();
  }, 2500 );


	



});

Credits

06cc9ee85b6ab58117c7951d14ead62e
Jonathan van Vlaanderen
1 project • 0 followers
Tech hobbyist
Contact

Replications

Did you replicate this project? Share it!

I made one

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

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog