Sibi Sankar
Published © GPL3+

Summon the Chef

Automating the daily hiring of a chef based on the availability of people in an apartment using Raspberry Pi2, PIR sensor and AWS IOT.

BeginnerFull instructions provided2,083
Summon the Chef

Things used in this project

Story

Read more

Custom parts and enclosures

Component Model

A simple enclosure modelled in sketchup.

Schematics

PIR Motion

RPI 2 and PIR sensor wiring using fritzing.

Wiring Diagram.

Connect the Vcc and ground of the PIR sensor to the RPI 2 and sensor input to a digital pin.

Code

MQTT Client.

Python
After assembling the various certificates from AWS IOT run the python file to start the mqtt client.
# Library Imports

import paho.mqtt.client as mqtt
import ssl
import time
import thread
import RPi.GPIO as GPIO
from time import gmtime, strftime

# Pin Definition
PIR_PIN = 11


GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIR_PIN,GPIO.in)


def on_connect(client, userdata, flags, rc):
    print "Connected Successfully"


#defining topics
pir_topic    = "topics/pir"

client = mqtt.Client()
client.on_connect = on_connect
client.tls_set(ca_certs='./auth/rootCA.pem', certfile='./auth/XXXXXXXXXXX-certificate.pem.crt', keyfile='./auth/XXXXXXXXXX-private.pem.key', tls_version=ssl.PROTOCOL_SSLv23)
client.tls_insecure_set(True)
client.connect("xxxxxxxxxxxxxx.iot.us-west-2.amazonaws.com", 8883, 60) #Taken from REST API endpoint



#Main Loop
#Publishing Analog Values to AWS
def publishHireMe(Variable):
    while (1):
        hour = int(strftime("%H", gmtime()))
        if hour >= 7 and hour <= 8:
            i=GPIO.input(11)
            if i:
                client.publish(pir_topic, payload="You are hired for tday :)")
        # Sampling is done every 5 minutes between 7 and 8
        time.sleep(5*60)


thread.start_new_thread(publishHireMe,("publishHireMe",))

client.loop_forever() #MQTT's will never end

Credits

Sibi Sankar

Sibi Sankar

2 projects • 7 followers
I live by the maxim 'made made dane' (you still have a long way to go).

Comments