Creation repo sue RPi3
This commit is contained in:
19
Camera/camera.py
Normal file
19
Camera/camera.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from picamera import PiCamera
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
camera = PiCamera()
|
||||||
|
|
||||||
|
#camera.rotation = 180
|
||||||
|
camera.start_preview()
|
||||||
|
#camera.start_preview(alpha=200)
|
||||||
|
# 2s mini pour le capteur
|
||||||
|
sleep(3)
|
||||||
|
camera.capture('/home/pi/Desktop/image.jpg')
|
||||||
|
camera.stop_preview()
|
||||||
|
|
||||||
|
# mode rafale
|
||||||
|
camera.start_preview()
|
||||||
|
for i in range(5):
|
||||||
|
sleep(2)
|
||||||
|
camera.capture('/home/pi/Desktop/image%s.jpg' % i)
|
||||||
|
camera.stop_preview()
|
||||||
9
Camera/camera_2.py
Normal file
9
Camera/camera_2.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import time
|
||||||
|
import picamera
|
||||||
|
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
camera.resolution = (1024, 768)
|
||||||
|
camera.start_preview()
|
||||||
|
# Camera warm-up time
|
||||||
|
time.sleep(2)
|
||||||
|
camera.capture('/home/pi/Desktop/foo.jpg', resize=(320, 240))
|
||||||
21
Camera/camera_low_light.py
Normal file
21
Camera/camera_low_light.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# https://picamera.readthedocs.io/en/release-1.10/recipes1.html#capturing-in-low-light
|
||||||
|
|
||||||
|
import picamera
|
||||||
|
from time import sleep
|
||||||
|
from fractions import Fraction
|
||||||
|
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
camera.resolution = (1280, 720)
|
||||||
|
# Set a framerate of 1/6fps, then set shutter
|
||||||
|
# speed to 6s and ISO to 800
|
||||||
|
camera.framerate = Fraction(1, 6)
|
||||||
|
camera.shutter_speed = 6000000
|
||||||
|
camera.exposure_mode = 'off'
|
||||||
|
camera.iso = 800
|
||||||
|
# Give the camera a good long time to measure AWB
|
||||||
|
# (you may wish to use fixed AWB instead)
|
||||||
|
sleep(10)
|
||||||
|
# Finally, capture an image with a 6s exposure. Due
|
||||||
|
# to mode switching on the still port, this will take
|
||||||
|
# longer than 6 seconds
|
||||||
|
camera.capture('/home/pi/Desktop/dark.jpg')
|
||||||
14
Camera/camera_overlay_text.py
Normal file
14
Camera/camera_overlay_text.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import picamera
|
||||||
|
import time
|
||||||
|
import itertools
|
||||||
|
|
||||||
|
s = "This message would be far too long to display normally..."
|
||||||
|
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
camera.resolution = (640, 480)
|
||||||
|
camera.framerate = 24
|
||||||
|
camera.start_preview()
|
||||||
|
camera.annotate_text = ' ' * 31
|
||||||
|
for c in itertools.cycle(s):
|
||||||
|
camera.annotate_text = camera.annotate_text[1:31] + c
|
||||||
|
time.sleep(0.1)
|
||||||
18
Camera/camera_sequence.py
Normal file
18
Camera/camera_sequence.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# https://picamera.readthedocs.io/en/release-1.10/recipes1.html#capturing-consistent-images
|
||||||
|
|
||||||
|
import time
|
||||||
|
import picamera
|
||||||
|
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
camera.resolution = (1280, 720)
|
||||||
|
camera.framerate = 30
|
||||||
|
# Wait for the automatic gain control to settle
|
||||||
|
time.sleep(2)
|
||||||
|
# Now fix the values
|
||||||
|
camera.shutter_speed = camera.exposure_speed
|
||||||
|
camera.exposure_mode = 'off'
|
||||||
|
g = camera.awb_gains
|
||||||
|
camera.awb_mode = 'off'
|
||||||
|
camera.awb_gains = g
|
||||||
|
# Finally, take several photos with the fixed settings
|
||||||
|
camera.capture_sequence(['/home/pi/Desktop/image%02d.jpg' % i for i in range(10)])
|
||||||
11
Camera/camera_timelapse.py
Normal file
11
Camera/camera_timelapse.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# https://picamera.readthedocs.io/en/release-1.10/recipes1.html#capturing-timelapse-sequences
|
||||||
|
|
||||||
|
import time
|
||||||
|
import picamera
|
||||||
|
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
camera.start_preview()
|
||||||
|
time.sleep(2)
|
||||||
|
for filename in camera.capture_continuous('img{counter:03d}.jpg'):
|
||||||
|
print('Captured %s' % filename)
|
||||||
|
time.sleep(300) # wait 5 minutes
|
||||||
19
Camera/video.py
Normal file
19
Camera/video.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from picamera import PiCamera
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
camera = PiCamera()
|
||||||
|
|
||||||
|
|
||||||
|
camera.resolution = (640, 480)
|
||||||
|
|
||||||
|
#camera.start_preview()
|
||||||
|
|
||||||
|
print()
|
||||||
|
camera.start_recording('/home/pi/Desktop/video.h264')
|
||||||
|
|
||||||
|
camera.wait_recording(5)
|
||||||
|
|
||||||
|
camera.stop_recording()
|
||||||
|
camera.close()
|
||||||
|
|
||||||
|
print("video recording stopped")
|
||||||
9
Camera/video_2.py
Normal file
9
Camera/video_2.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# https://picamera.readthedocs.io/en/release-1.10/recipes1.html#recording-video-to-a-file
|
||||||
|
|
||||||
|
import picamera
|
||||||
|
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
camera.resolution = (640, 480)
|
||||||
|
camera.start_recording('/home/pi/Desktop/my_video.h264')
|
||||||
|
camera.wait_recording(10)
|
||||||
|
camera.stop_recording()
|
||||||
49
RPi_info.sh
Executable file
49
RPi_info.sh
Executable file
@@ -0,0 +1,49 @@
|
|||||||
|
#/bin/bash
|
||||||
|
|
||||||
|
echo -e "\033[1;31mMy Raspberry...\033[0m"
|
||||||
|
echo
|
||||||
|
echo $(date)
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -e "\033[1;93mVersion of Debian:\033[0m"
|
||||||
|
cat /etc/debian_version
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo -e "\033[1;93mOS Release Notes:\033[0m"
|
||||||
|
cat /etc/os-release
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo -e "\033[1;93mKernel version:\033[0m"
|
||||||
|
uname -a
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo -e "\033[1;93mHarware version:\033[0m"
|
||||||
|
cat /proc/cpuinfo
|
||||||
|
echo
|
||||||
|
# Ajout de tr sinon avertissement :command substitution: ignored null byte in input
|
||||||
|
model=$(cat /proc/device-tree/model | tr '\0' '\n')
|
||||||
|
if [ -n "$model" ]; then
|
||||||
|
echo -e "\033[1m$model\033[0m"
|
||||||
|
else
|
||||||
|
revision=$(cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//')
|
||||||
|
echo "Revision: $revision"
|
||||||
|
echo "Voir https://elinux.org/RPi_HardwareHistory pour connaitre le modele."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
if [ -x "$(command -v pinout)" ]; then
|
||||||
|
pinout
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo -e "\033[1;93mCurrent firmware version:\033[0m"
|
||||||
|
vcgencmd version
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [ -x "$(command -v rpi-update)" ]; then
|
||||||
|
echo -e "\033[1;93mCommints since last update (available update ?):\033[0m"
|
||||||
|
sudo JUST_CHECK=1 rpi-update
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ./RPi_info.sh > RPi_DietPi_info_`date +%d-%m-%Y`.txt
|
||||||
38
Send mail/mail_attach_test.py
Normal file
38
Send mail/mail_attach_test.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import smtplib
|
||||||
|
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
from email import encoders
|
||||||
|
|
||||||
|
# Renseigner le compte Gmail et le destinataire
|
||||||
|
fromaddr = "bp6412615@gmail.com"
|
||||||
|
frompasswd = "vYqqiz-sugqo5-mywbym"
|
||||||
|
toaddr = "bruno@clicclac.info"
|
||||||
|
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = fromaddr
|
||||||
|
msg['To'] = toaddr
|
||||||
|
msg['Subject'] = "Test Python send email"
|
||||||
|
body = 'This is an extended email test'
|
||||||
|
msg.attach(MIMEText(body, 'plain'))
|
||||||
|
|
||||||
|
# Renseigner la PJ
|
||||||
|
filename = "image.jpg"
|
||||||
|
attachment = open("/home/pi/image.jpg", "rb")
|
||||||
|
|
||||||
|
part = MIMEBase('application', 'octet-stream')
|
||||||
|
part.set_payload((attachment).read())
|
||||||
|
encoders.encode_base64(part)
|
||||||
|
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
|
||||||
|
msg.attach(part)
|
||||||
|
|
||||||
|
server = smtplib.SMTP('smtp.gmail.com', 587)
|
||||||
|
#server.ehlo
|
||||||
|
server.starttls()
|
||||||
|
server.login(fromaddr, frompasswd)
|
||||||
|
text = msg.as_string()
|
||||||
|
server.sendmail(fromaddr, toaddr, text)
|
||||||
|
server.quit()
|
||||||
39
Send mail/mail_extend_body.py
Normal file
39
Send mail/mail_extend_body.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import smtplib
|
||||||
|
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
from email import encoders
|
||||||
|
|
||||||
|
# Renseigner le compte Gmail et le destinataire
|
||||||
|
fromaddr = "bp6412615@gmail.com"
|
||||||
|
frompasswd = "vYqqiz-sugqo5-mywbym"
|
||||||
|
toaddr = "bruno@clicclac.info"
|
||||||
|
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = fromaddr
|
||||||
|
msg['To'] = toaddr
|
||||||
|
msg['Subject'] = "Test Python send email"
|
||||||
|
f = open("/home/pi/mail_template.txt")
|
||||||
|
body = f.read()
|
||||||
|
msg.attach(MIMEText(body, 'plain'))
|
||||||
|
|
||||||
|
# Renseigner la PJ
|
||||||
|
filename = "image.jpg"
|
||||||
|
attachment = open("/home/pi/image.jpg", "rb")
|
||||||
|
|
||||||
|
part = MIMEBase('application', 'octet-stream')
|
||||||
|
part.set_payload((attachment).read())
|
||||||
|
encoders.encode_base64(part)
|
||||||
|
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
|
||||||
|
msg.attach(part)
|
||||||
|
|
||||||
|
server = smtplib.SMTP('smtp.gmail.com', 587)
|
||||||
|
#server.ehlo
|
||||||
|
server.starttls()
|
||||||
|
server.login(fromaddr, frompasswd)
|
||||||
|
text = msg.as_string()
|
||||||
|
server.sendmail(fromaddr, toaddr, text)
|
||||||
|
server.quit()
|
||||||
40
Send mail/mail_multiples_dest.py
Normal file
40
Send mail/mail_multiples_dest.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import smtplib
|
||||||
|
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
from email import encoders
|
||||||
|
|
||||||
|
# Renseigner le compte Gmail
|
||||||
|
fromaddr = "bp6412615@gmail.com"
|
||||||
|
frompasswd = "vYqqiz-sugqo5-mywbym"
|
||||||
|
# Renseigner le ou les destinataire(s)
|
||||||
|
toaddr = "bruno@clicclac.info,bruno.pesenti@orange.fr"
|
||||||
|
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = fromaddr
|
||||||
|
msg['To'] = toaddr
|
||||||
|
msg['Subject'] = "Test Python send email"
|
||||||
|
f = open("/home/pi/mail_template.txt")
|
||||||
|
body = f.read()
|
||||||
|
msg.attach(MIMEText(body, 'plain'))
|
||||||
|
|
||||||
|
# Renseigner la PJ
|
||||||
|
filename = "image.jpg"
|
||||||
|
attachment = open("/home/pi/image.jpg", "rb")
|
||||||
|
|
||||||
|
part = MIMEBase('application', 'octet-stream')
|
||||||
|
part.set_payload((attachment).read())
|
||||||
|
encoders.encode_base64(part)
|
||||||
|
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
|
||||||
|
msg.attach(part)
|
||||||
|
|
||||||
|
server = smtplib.SMTP('smtp.gmail.com', 587)
|
||||||
|
#server.ehlo
|
||||||
|
server.starttls()
|
||||||
|
server.login(fromaddr, frompasswd)
|
||||||
|
text = msg.as_string()
|
||||||
|
server.sendmail(fromaddr, toaddr, text)
|
||||||
|
server.quit()
|
||||||
9
Send mail/mailtest.php
Normal file
9
Send mail/mailtest.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
$to = "bruno@clicclac.info";
|
||||||
|
$subject = "PHP Test mail";
|
||||||
|
$message = "This is a test email";
|
||||||
|
$from = "bp6412615@gmail.com";
|
||||||
|
$headers = "From:" . $from;
|
||||||
|
mail($to,$subject,$message,$headers);
|
||||||
|
echo "Mail Sent.";
|
||||||
|
?>
|
||||||
25
Send mail/mailtest.py
Normal file
25
Send mail/mailtest.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import smtplib
|
||||||
|
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
|
fromaddr = "bp6412615@gmail.com"
|
||||||
|
frompasswd = "vYqqiz-sugqo5-mywbym"
|
||||||
|
toaddr = "bruno@clicclac.info"
|
||||||
|
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = fromaddr
|
||||||
|
msg['To'] = toaddr
|
||||||
|
msg['Subject'] = "Test Python send email"
|
||||||
|
body = 'This is an extended email test'
|
||||||
|
msg.attach(MIMEText(body, 'plain'))
|
||||||
|
|
||||||
|
server = smtplib.SMTP('smtp.gmail.com', 587)
|
||||||
|
server.ehlo
|
||||||
|
server.starttls()
|
||||||
|
server.login(fromaddr, frompasswd)
|
||||||
|
text = msg.as_string()
|
||||||
|
server.sendmail(fromaddr, toaddr, text)
|
||||||
|
server.quit()
|
||||||
BIN
SiriControl/2019-01-23-170922_1920x1200_scrot.png
Normal file
BIN
SiriControl/2019-01-23-170922_1920x1200_scrot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
BIN
SiriControl/2019-01-23-171201_1920x1200_scrot.png
Normal file
BIN
SiriControl/2019-01-23-171201_1920x1200_scrot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
BIN
SiriControl/2019-01-23-171315_1920x1200_scrot.png
Normal file
BIN
SiriControl/2019-01-23-171315_1920x1200_scrot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
23
SiriControl/Led_off.py
Normal file
23
SiriControl/Led_off.py
Normal 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
22
SiriControl/Led_on.py
Normal 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.”)
|
||||||
|
|
||||||
35
SiriControl/modules/garage.py
Normal file
35
SiriControl/modules/garage.py
Normal 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))
|
||||||
|
|
||||||
BIN
SiriControl/modules/garage.pyc
Normal file
BIN
SiriControl/modules/garage.pyc
Normal file
Binary file not shown.
13
SiriControl/modules/life.py
Normal file
13
SiriControl/modules/life.py
Normal 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")
|
||||||
BIN
SiriControl/modules/life.pyc
Normal file
BIN
SiriControl/modules/life.pyc
Normal file
Binary file not shown.
18
SiriControl/modules/photo.py
Normal file
18
SiriControl/modules/photo.py
Normal 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
|
||||||
BIN
SiriControl/modules/photo.pyc
Normal file
BIN
SiriControl/modules/photo.pyc
Normal file
Binary file not shown.
5
SiriControl/modules/snapshot.sh
Executable file
5
SiriControl/modules/snapshot.sh
Executable 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
|
||||||
12
SiriControl/modules/templateModule.py
Normal file
12
SiriControl/modules/templateModule.py
Normal 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
|
||||||
BIN
SiriControl/modules/templateModule.pyc
Normal file
BIN
SiriControl/modules/templateModule.pyc
Normal file
Binary file not shown.
133
SiriControl/siricontrol.py
Executable file
133
SiriControl/siricontrol.py
Executable 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)
|
||||||
35
pir/pir.py
Executable file
35
pir/pir.py
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
# MBTechWorks.com 2017
|
||||||
|
# Use an HC-SR501 PIR to detect motion (infrared)
|
||||||
|
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BOARD) #Set GPIO to pin numbering
|
||||||
|
pir = 8 #Assign pin 8 to PIR
|
||||||
|
led = 10 #Assign pin 10 to LED
|
||||||
|
GPIO.setup(pir, GPIO.IN) #Setup GPIO pin PIR as input
|
||||||
|
GPIO.setup(led, GPIO.OUT) #Setup GPIO pin for LED as output
|
||||||
|
print ("Sensor initializing . . .")
|
||||||
|
time.sleep(2) #Give sensor time to startup
|
||||||
|
print ("Active")
|
||||||
|
print ("Press Ctrl+c to end program")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
if GPIO.input(pir) == True: #If PIR pin goes high, motion is detected
|
||||||
|
print ("Motion Detected!")
|
||||||
|
GPIO.output(led, True) #Turn on LED
|
||||||
|
time.sleep(4) #Keep LED on for 4 seconds
|
||||||
|
GPIO.output(led, False) #Turn off LED
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
except KeyboardInterrupt: #Ctrl+c
|
||||||
|
pass #Do nothing, continue to finally
|
||||||
|
|
||||||
|
finally:
|
||||||
|
GPIO.output(led, False) #Turn off LED in case left on
|
||||||
|
GPIO.cleanup() #reset all GPIO
|
||||||
|
print ("Program ended")
|
||||||
|
|
||||||
43
pir/pir2.py
Normal file
43
pir/pir2.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# MBTechWorks.com 2017
|
||||||
|
# Use an HC-SR501 PIR to detect motion (infrared)
|
||||||
|
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time, datetime
|
||||||
|
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BOARD) #Set GPIO to pin numbering
|
||||||
|
pir = 8 #Assign pin 8 to PIR
|
||||||
|
led = 10 #Assign pin 10 to LED
|
||||||
|
GPIO.setup(pir, GPIO.IN) #Setup GPIO pin PIR as input
|
||||||
|
GPIO.setup(led, GPIO.OUT) #Setup GPIO pin for LED as output
|
||||||
|
print ("Sensor initializing . . .")
|
||||||
|
time.sleep(2) #Give sensor time to startup
|
||||||
|
print ("Active")
|
||||||
|
print ("Press Ctrl+c to end program")
|
||||||
|
|
||||||
|
# Function to create new Filename from date and time
|
||||||
|
def getFileName():
|
||||||
|
return datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.jpg")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
if GPIO.input(pir) == True: #If PIR pin goes high, motion is detected
|
||||||
|
print ("Motion Detected!")
|
||||||
|
GPIO.output(led, True) #Turn on LED
|
||||||
|
time.sleep(4) #Keep LED on for 4 seconds
|
||||||
|
GPIO.output(led, False) #Turn off LED
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
filename = getFileName()
|
||||||
|
print(filename)
|
||||||
|
|
||||||
|
except KeyboardInterrupt: #Ctrl+c
|
||||||
|
pass #Do nothing, continue to finally
|
||||||
|
|
||||||
|
finally:
|
||||||
|
GPIO.output(led, False) #Turn off LED in case left on
|
||||||
|
GPIO.cleanup() #reset all GPIO
|
||||||
|
print ("Program ended")
|
||||||
|
|
||||||
Reference in New Issue
Block a user