“Bekarlık Sultanlıktır” Projesi – ITUGnu IoT Eğitimi
İstanbul Teknik Üniversitesi Özgür Yazılım Kulübü çatısı altında düzenlemiş olduğunuz internet of things eğitiminin son hafta workshop’ının sonunda, katılımcılarımız arasında bulunan Çağatay Tanyıldız ve Seçkin Bostancı’nın geliştirmiş olduğu “Bekarlık Sultanlıktır” projesi. Projede Intel Galileo Gen2 board ile birlikte Wyliodrin üzerinden programlanarak SMS API, IFTTT ve Twitter API kullanılmıştır.
Proje adı: Bekarlık Sultanlıktır
Proje ekibi:
Çağatay Tanyıldız – tanyildizcagatay@gmail.com – Yıldız Teknik Üniversitesi
Seçkin Bostancı – seckinbostanci@icloud.com – İstanbul Aydın Üniversitesi
Projede kullanılan servis ve hizmetler: SMS API, Twitter API, IFTTT
Proje detayı:
2 odalı bir evde tek başına kalan biri için hırsızlık, yangın gibi durumlarda SMS ile uyarı veriyor.
Evden çıkınca arkadaşlara haber için tweet atıyor.
IFTTT ile evden çıkılması durumunu anlayınca belirli bir hashtag ile tweet atıyor. Galileo bunu okuyup evde insan olup olmaması durumunu kontrol ederek herhangi bir kişi varsa SMS ile kişiye hırsızlık uyarısı veriyor.
Proje yazılımı kaynak kodu:
* Yazılım python ile wyliodrin üzerinde kodlanmıştır ve çalıştırılmıştır. Orjinal Intel Galileo Gen2 linux imajı üzerine extra kütüphaneler kurulmuştur, kodu çalıştırdığınızda hatalar alırsanız, hata mesajındaki paketi linux shell üzerinden yüklemeniz gerekir. Gerekli tüm paketleri yüklediğinizde de yazılım sorunsuz şekilde çalışacaktır.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
try: from wyliodrin import * except: from wiringpi2 import * wiringPiSetup() import tweepy import time import os import math import urllib, urllib2 import json import ntplib import base64 from random import randint #Intel Galileo has to update its time because of usage Twitter API client = ntplib.NTPClient() response = client.request('pool.ntp.org') os.system('date ' + time.strftime('%m%d%H%M%Y.%S',time.localtime(response.tx_time))) #Twitter API Settings consumer_key = '' consumer_secret = '' access_token = '' access_token_secret = '' auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) #When we search on twitter timeline we don't want to see same tweet everytime #Because of that we will save last tweet id file = open('last_id.txt', 'a') file.close() #We will use json file for using web-panel json_connect = urllib2.urlopen('http://yourdomainhere/options.json') json_data = json_connect.read() json_options = json.loads(json_data) #It converts temperature sensor value to Celcius def analogTemp(nowreading): resistance = (float)(1023-nowreading)*10000/nowreading temperature = (int)(1/(math.log(resistance/10000)/3975+1/298.15)-273.15) return temperature #Lets prepare our sensors and leds lSensorKitchen = 3 lSensorRoom = 2 tempPin = 1 touchKitchen = 7 touchRoom = 6 ledKitchen = 8 #Blue ledRoom = 5 #Green buzzer = 0 #It means these are output pin pinMode(ledKitchen, 1) pinMode(ledRoom, 1) pinMode(buzzer, 1) while True: file = open('last_id.txt', 'r') last_id = file.read() file.close() InKitchen = digitalRead(touchKitchen) InRoom = digitalRead(touchRoom) temperature = analogTemp(analogRead(tempPin)) KitchenLBrigth = analogRead(lSensorKitchen) RoomLBrigth = analogRead(lSensorRoom) # 1: I'm in. 0: I'm out. print "Room:" + str (InRoom) print "Kitchen:" + str (InKitchen) if (temperature > 45): digitalWrite(buzzer, 1) delay(500) digitalWrite(buzzer, 0) delay(200) digitalWrite(buzzer, 1) delay(500) digitalWrite(buzzer, 0) #This is for sending message #I'm using Plivo service for it. method = "POST" handler = urllib2.HTTPHandler() opener = urllib2.build_opener(handler) request = urllib2.Request("https://api.plivo.com/v1/Account/"+str(json_options['plivo_auth_id'])+"/Message/", data='{"src":"'+str(json_options['plivo_src'])+'","dst":"'+str(json_options['plivo_dst'])+'","text":"'+str(json_options['plivo_sms'])+' '+str(sicaklik)+'"}' ) request.add_header("Content-Type",'application/json') base64string = base64.encodestring('%s:%s' % (str(json_options['plivo_auth_id']), str(json_options['plivo_auth_token']))).replace('\n', '') request.add_header("Authorization", "Basic %s" % base64string) request.get_method = lambda: method try: connection = opener.open(request) except urllib2.HTTPError,e: connection = e print connection.read() if not InRoom and not InKitchen: #On twitter you cant send same tweet #Randint is for it we will import it from Random api.update_status("#Imnothome!" + str(randint(0,100000))) digitalWrite(ledRoom, 0) digitalWrite(ledKitchen, 0) else: if not InKitchen: #print "I'm in room" digitalWrite(ledKitchen, 0) if RoomLBrigth < 300: digitalWrite(ledRoom, 1) else: print "I'm kitchen" digitalWrite(ledRoom, 0) if KitchenLBrigth < 300: digitalWrite(ledMutfak, 1) #We will use IFTTT for sending tweet #IFTTT sends tweet when you exit the specific area. #Then we will search this exact tweet search = api.search(q='#RoomControl', count='1', since=last_id) for tweet in search: #print tweet.text.encode("UTF-8") if digitalRead(ledOda) or digitalRead(ledMutfak): #Plivo Settings method = "POST" handler = urllib2.HTTPHandler() opener = urllib2.build_opener(handler) request = urllib2.Request("https://api.plivo.com/v1/Account/"+str(json_options['plivo_auth_id'])+"/Message/", data='{"src":"'+str(json_options['plivo_src'])+'","dst":"'+str(json_options['plivo_src'])+'","text":"Evde hirsiz var '+str(sicaklik)+'"}' ) request.add_header("Content-Type",'application/json') base64string = base64.encodestring('%s:%s' % (str(json_options['plivo_auth_id']), str(json_options['plivo_auth_token']))).replace('\n', '') request.add_header("Authorization", "Basic %s" % base64string) request.get_method = lambda: method try: connection = opener.open(request) except urllib2.HTTPError,e: connection = e print connection.read() file = open('last_id.txt', 'w') file.write(str(tweet.id)) file.close() delay(10000) |
Proje ile alakalı ekstra bir fikriniz ya da söylemek istedikleriniz varsa, yorumlar kısmından iletebilir ya da proje ekibinin vermiş olduğu iletişim bilgilerinden kendilerine ulaşabilirsiniz.
İTÜ Özgür Yazılım Kulübü Internet of Things eğitimi ile alakalı tüm detayları, kaynakları ve güncellemeleri bu bağlantı üzerinden takip edebilirsiniz. Diğer final projelerine ise bu bağlantı üzerinden ulaşabilirsiniz.