Satyavrat Wagle
Published

IoT Twitter Sentry Ward Using Intel Edison

A Security system which sends you an image of an intruder over Twitter!

IntermediateFull instructions provided6 hours1,171
IoT Twitter Sentry Ward Using Intel Edison

Things used in this project

Hardware components

Android device
Android device
×1
Photo resistor
Photo resistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Twitter
Twitter

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Photoresistor configuration

Code

tweetpic.py

Python
Testing the Sentry ward
import tweepy
import cv2
import urllib
import time

consumer_key = *YOUR KEY HERE*
consumer_secret = *YOUR KEY HERE*
access_token = *YOUR TOKEN HERE*
access_token_secret = *YOUR TOKEN HERE*
your_handle = *ENTER YOUR TWITTER HANDLE HERE*

camip = *YOUR CAMERA IP HERE*
chk_old=0

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
imag = urllib.URLopener()

while 1:
	tweet = tweepy.Cursor(api.search, q = your_handle, lang = 'en')
	count = 0
	for tweet in tweet.items():
		print (tweet.text, tweet.author.screen_name,tweet.id)
		txt = tweet.text
		hand = tweet.author.screen_name
		chk = tweet.id
		cond = chk_old!=chk
		print cond
		count += 1
		if count > 0:
			break
	if txt == your_handle + ' Click!':  
		if cond:
			imag.retrieve('http://'+camip+':8080/shot.jpg','shot.jpg')
			img = cv2.imread('shot.jpg')
			time.sleep(3)
			this = '/home/root/shot.jpg'
			psts = '@'+hand+' This is what I can see!'
			api.update_with_media(filename=this, in_reply_to_status_id=chk, status=psts)
			chk_old = chk
			print chk_old
			print 'done'
	time.sleep(11)

tweetint.py

Python
Final code for integration with light sensors
import tweepy
import cv2
import urllib
import time
import mraa

consumer_key = *YOUR KEY HERE*
consumer_secret = *YOUR KEY HERE*
access_token = *YOUR TOKEN HERE*
access_token_secret = *YOUR TOKEN HERE*
your_handle = *ENTER YOUR TWITTER HANDLE HERE*
camip = *YOUR CAMERA IP HERE*

chk_old=0

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
imag = urllib.URLopener()
light = mraa.Aio(0)

tweet = tweepy.Cursor(api.search, q = your_handle , lang = 'en')
count = 0
for tweet in tweet.items():
	print (tweet.text, tweet.author.screen_name,tweet.id)
	txt = tweet.text
	hand = tweet.author.screen_name
	chk = tweet.id
	cond = chk_old!=chk
	print cond
	break
if txt== your_handle + ' Start!':
	print('Security System Started!')
	while count<1:
		tweet = tweepy.Cursor(api.search, q = '@satyasiot', lang = 'en')
		count = 2
		val = float(light.read())
		print val
		if val > 500:  
			if cond:
				imag.retrieve('http://'+camip+':8080/shot.jpg','shot.jpg')
				img = cv2.imread('shot.jpg')
				time.sleep(3)
				this = '/home/root/shot.jpg'
				psts = '@satyasiot Intruder Alert!'
				api.update_with_media(filename=this, in_reply_to_status_id=chk, status=psts)
				chk_old = chk
				print chk_old
				print 'done'
		time.sleep(11)
		for tweet in tweet.items():
			txt = tweet.text
			hand = tweet.author.screen_name
			chk = tweet.id
if txt=='@satyasiot Stop!':
	while 1:

Credits

Satyavrat Wagle

Satyavrat Wagle

6 projects • 63 followers
I have an active interest in IoT, Wireless Sensor Networks, Single Board Computing Implementations, Embedded Systems, and Robotics.

Comments