Created
August 27, 2016 13:52
-
-
Save Brutt/af95a4f6077dc34ca2288af522c02c79 to your computer and use it in GitHub Desktop.
Send the sms when raspberry registered any movement. For sms sending I use free Twilio trial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
from datetime import datetime | |
def SendSms(msg): | |
from twilio.rest import TwilioRestClient | |
client = TwilioRestClient("Your ACCOUNT SID", | |
"Your AUTH TOKEN") | |
client.messages.create(to="Your number", | |
from_="Your Twilio number", | |
body=msg) | |
#number of GPIO on board | |
sensor = 4 | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(sensor, GPIO.IN) | |
delay_sec = 120 | |
mark_time = 0 | |
cur_state = 0 | |
while True: | |
time.sleep(1) | |
cur_state = GPIO.input(sensor) | |
print(cur_state) | |
if cur_state == 1: | |
if time.time() - mark_time > delay_sec: | |
msg = "Some movement. Time: {0}".format(str(datetime.now())[:-7]) | |
print(msg) | |
SendSms(msg) | |
mark_time = time.time() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment