Things used in this project

Hardware components:
R8326274 01
Raspberry Pi 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

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

Similar projects you might like

Physical Computing - Scratch 2.0 for Raspberry Pi
Easy
  • 141
  • 5

Full instructions

This is my 3rd tutorial with a focus on Scratch and Physical Computing using RPi. Here we will explore the new version of Scratch, the 2.0.

Break your heart - IoT Project - IoT Blocky
Easy
  • 53
  • 2

Full instructions

Using this project to control the LEDs on the Raspberry Pi Sense HAT

Break your heart - IoT Project - Blinky - 2 LEDs
Easy
  • 18
  • 1

Full instructions

The Blinky project with two leds

Hey Mycroft, Where Is the International Space Station?
Easy
  • 1,899
  • 37

Full instructions

Developing my first skill with the Mycroft.ai open source voice assistant on a Raspberry Pi 3 - aka Picroft!

Break your heart - IoT Project - Hello World
Easy
  • 31
  • 1

Full instructions

Hello World sample

Distance Sensor
Easy
  • 37
  • 1

Full instructions

Using the distance sensor

Sign up / LoginProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlog