Evan Rust
Published © GPL3+

Sudo Make Some Toast

Tweet to a Raspberry Pi and it will start to make toast for you! Choose level of toastiness and maybe the time it should start.

BeginnerFull instructions provided2 hours3,294
Sudo Make Some Toast

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Relay (generic)
×1
Toaster (of course)
×1

Software apps and online services

Twitter
Twitter
Python IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

Schematic

Code

Python Code

Python
Run via sudo on the Raspberry Pi
from twython import Twython
import json
import time
import datetime
import RPi.GPIO as GPIO
#toast for 2 min
#tweet: "sudo make_some_toast -t 5:15"
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.OUT)
GPIO.output(4,GPIO.HIGH)
app_key = "secret"
app_secret = "secret"
oauth_token = "secret"
oauth_token_secret = "secret"
twitter = Twython(app_key,app_secret,oauth_token,oauth_token_secret)
previous = "null"
messageC = "null"
enabled = False
minTill = 0
goalTimeM = 0
goalTimeH = 0

tt = datetime.datetime.now()
tt = tt.timetuple()

prevMin = tt[4]

def getCurrent():
    tt = datetime.datetime.now()
    tt = tt.timetuple()
    hour = int(tt[3])
    minute = int(tt[4])
    return hour, minute
def check_twitter():
    global minTill
    global goalTimeM
    global goalTimeH
    global previous
    global messageC
    global enabled
    json_file = json.dumps(twitter.get_home_timeline()[0])

    data = json.loads(json_file)
    current_message = data["text"]
    messageC = current_message
    print current_message
    if previous != current_message:
        previous = current_message
        current_message = current_message.lower()
        split_message = current_message.split()
        if split_message[0] == "sudo":
            if split_message[2] == "-t":
                timeTill = split_message[3]
                if timeTill == "now":
                    print "Making toast now"
                elif timeTill != "now":
                    split_time = timeTill.split(':')
                    goalTimeH = int(split_time[0])
                    goalTimeM = int(split_time[1])
                    goalTimeM += (goalTimeH * 60)
                    print "Your toast will start in: " + str(goalTimeM) + " minutes."
                    enabled = True
    elif previous == current_message:
        print "Already done." 
    previous = current_message
while 1:
    Chour, Cminute = getCurrent()
    if Cminute != prevMin:
        check_twitter()
        if enabled == True:
            if goalTimeM != 0:
                minTill += 1
                if goalTimeM == minTill:
                    print "Making toast!"
                    GPIO.output(4,GPIO.LOW)
                    time.sleep(2*60) #2 minutes
                    GPIO.output(4,GPIO.HIGH)
                    minTill = 0
                    goalTime = 0
                    enabled = False
    prevMin = Cminute
    time.sleep(1)

Credits

Evan Rust

Evan Rust

122 projects • 1080 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments