Creation repo sue RPi3

This commit is contained in:
Bruno 21
2019-02-04 10:14:50 +01:00
commit fb93c53f4f
31 changed files with 659 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

23
SiriControl/Led_off.py Normal file
View File

@@ -0,0 +1,23 @@
#https://www.deviceplus.com/how-tos/add-siri-control-raspberry-pi-project/
#You can import any modules required here
import RPi.GPIO as GPIO #import GPIO module
import time
#This is name of the module it can be anything you want
moduleName = LED_off
#These are the words you must say for this module to be executed
commandWords = [turn, off, led]
#This is the main function which will be execute when the above command words are said
def execute(command):
LED = 11 # Set LED pin to pin 11
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED, GPIO.OUT) #configure LED as an output
print(\n)
print(LED is off.)
GPIO.output(LED, GPIO.LOW) #turn LED on

22
SiriControl/Led_on.py Normal file
View File

@@ -0,0 +1,22 @@
#https://www.deviceplus.com/how-tos/add-siri-control-raspberry-pi-project/
#You can import any modules required here
import RPi.GPIO as GPIO #import GPIO module
import time
#This is name of the module it can be anything you want
moduleName = LED_on
#These are the words you must say for this module to be executed
commandWords = [turn, on, led]
#This is the main function which will be execute when the above command words are said
def execute(command):
LED = 11 # Set LED pin to pin 11
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED, GPIO.OUT) #configure LED as an output
print(\n)
print(LED is On.)

View File

@@ -0,0 +1,35 @@
import json
import requests
import sys
#https://howchoo.com/g/zdi2zgq2mjb/how-to-use-siri-to-control-anything-from-iftt-to-custom-programs-and-devices
moduleName = 'garage'
commandWords = ['garage', 'door']
GARAGE_HOST = 'http://192.168.1.183'
def execute(command):
try:
action = command.split(' ')[0]
except IndexError:
print('No command passed.')
return
if not action in ['open', 'close']:
print('Invalid action.')
return
response = requests.get('{0}/status'.format(GARAGE_HOST))
status = json.loads(response.text)
if action == 'open' and status.get('open'):
print('Door already open.')
return
if action == 'close' and status.get('close'):
print('Door already closed.')
return
requests.get('{0}/relay'.format(GARAGE_HOST))

Binary file not shown.

View File

@@ -0,0 +1,13 @@
#You can import any modules required here
#This is name of the module - it can be anything you want
moduleName = "life"
#These are the words you must say for this module to be executed
commandWords = ["meaning","life"]
#This is the main function which will be execute when the above command words are said
def execute(command):
print("\n")
print("------------------The meaning of life is 42-------------------")
print("\n")

Binary file not shown.

View File

@@ -0,0 +1,18 @@
#You can import any required modules here
#This can be anything you want
moduleName = "photo"
#All of the words must be heard in order for this module to be executed
commandWords = ["prendre","photo"]
def execute(command):
#Write anything you want to be executed when the commandWords are heard
#The 'command' parameter is the command you speak
#scrot
import subprocess
subprocess.call("scrot")
#subprocess.call("/home/pi/Documents/SiriControl/modules/snapshot.sh")
# scrot '%Y-%m-%d_$wx$h_scrot.png' -e 'mv $f ~/images/shots/'
# "/home/pi/Pictures/scrot.png"
return

Binary file not shown.

View File

@@ -0,0 +1,5 @@
#!/bin/bash
#scrot '/home/pi/Pictures/myscreen.jpg'
#scrot 'scrot.png' -e 'mv $f ~/Pictures'
scrot 'scrot.png' | mv ~/Pictures

View File

@@ -0,0 +1,12 @@
#You can import any required modules here
#This can be anything you want
moduleName = "templateModule"
#All of the words must be heard in order for this module to be executed
commandWords = ["xyz"]
def execute(command):
#Write anything you want to be executed when the commandWords are heard
#The 'command' parameter is the command you speak
return

Binary file not shown.

133
SiriControl/siricontrol.py Executable file
View File

@@ -0,0 +1,133 @@
import time
import imaplib
import email
import os
import pkgutil
##########################################
# Add your gmail username and password here
username = "bp6412615"
password = "vYqqiz-sugqo5-mywbym"
##########################################
class ControlException(Exception):
pass
class Control():
def __init__(self, username, password):
print("------------------------------------------------------")
print("- SIRI CONTROL -")
print("- Created by Sanjeet Chatterjee -")
print("- Website: thereallycoolstuff.wordpress.com -")
print("------------------------------------------------------")
try:
self.last_checked = -1
self.mail = imaplib.IMAP4_SSL("imap.gmail.com", 993)
self.mail.login(username, password)
self.mail.list()
self.mail.select("Notes")
# Gets last Note id to stop last command from executing
result, uidlist = self.mail.search(None, "ALL")
try:
self.last_checked = uidlist[0].split()[-1]
except IndexError:
pass
self.load()
self.handle()
except imaplib.IMAP4.error:
print("Your username and password is incorrect")
print("Or IMAP is not enabled.")
def load(self):
"""Try to load all modules found in the modules folder"""
print("\n")
print("Loading modules...")
self.modules = []
path = os.path.join(os.path.dirname(__file__), "modules")
directory = pkgutil.iter_modules(path=[path])
for finder, name, ispkg in directory:
try:
loader = finder.find_module(name)
module = loader.load_module(name)
if hasattr(module, "commandWords") \
and hasattr(module, "moduleName") \
and hasattr(module, "execute"):
self.modules.append(module)
print("The module '{0}' has been loaded, "
"successfully.".format(name))
else:
print("[ERROR] The module '{0}' is not in the "
"correct format.".format(name))
except:
print("[ERROR] The module '" + name + "' has some errors.")
print("\n")
def fetch_command(self):
"""Retrieve the last Note created if new id found"""
self.mail.list()
self.mail.select("Notes")
result, uidlist = self.mail.search(None, "ALL")
try:
latest_email_id = uidlist[0].split()[-1]
except IndexError:
return
if latest_email_id == self.last_checked:
return
self.last_checked = latest_email_id
result, data = self.mail.fetch(latest_email_id, "(RFC822)")
voice_command = email.message_from_string(data[0][1].decode('utf-8'))
return str(voice_command.get_payload()).lower().strip()
def handle(self):
"""Handle new commands
Poll continuously every second and check for new commands.
"""
print("Fetching commands...")
print("\n")
while True:
try:
command = self.fetch_command()
if not command:
raise ControlException("No command found.")
print("The word(s) '" + command + "' have been said")
for module in self.modules:
foundWords = []
for word in module.commandWords:
if str(word) in command:
foundWords.append(str(word))
if len(foundWords) == len(module.commandWords):
try:
module.execute(command)
print("The module {0} has been executed "
"successfully.".format(module.moduleName))
except:
print("[ERROR] There has been an error "
"when running the {0} module".format(
module.moduleName))
else:
print("\n")
except (TypeError, ControlException):
pass
except Exception as exc:
print("Received an exception while running: {exc}".format(
**locals()))
print("Restarting...")
time.sleep(1)
if __name__ == '__main__':
Control(username, password)