{"id":51,"date":"2013-02-11T14:51:22","date_gmt":"2013-02-11T14:51:22","guid":{"rendered":"http:\/\/www.nicassio.it\/daniele\/blog\/?p=51"},"modified":"2013-02-11T14:51:22","modified_gmt":"2013-02-11T14:51:22","slug":"raspberry-pi-powered-door-alarm","status":"publish","type":"post","link":"http:\/\/www.nicassio.it\/daniele\/blog\/?p=51","title":{"rendered":"Raspberry PI powered Door Alarm"},"content":{"rendered":"<p>This is my last Raspberry PI project. It&#8217;s a simple alarm driven by a home-made door sensor which plays an alarm sound and sends me a message via twitter.<\/p>\n<p>The video is in italian.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"http:\/\/www.youtube.com\/embed\/CaASJHUXPH4\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>Here&#8217;s the python code which uses the tweepy library:<\/p>\n<p><code><\/p>\n<pre>\n#!\/usr\/bin\/python\n\n# Import modules for CGI handling \nimport cgi, cgitb, time\nimport RPi.GPIO as GPIO\nimport os\nimport tweepy\nimport traceback\n\n#fill these variables with your twitter app data\noauth_token = ** \noauth_token_secret = **\n\nconsumer_key = **\nconsumer_secret = **\n\nauth = tweepy.OAuthHandler(consumer_key, consumer_secret)\nauth.set_access_token(oauth_token, oauth_token_secret)\napi = tweepy.API(auth)\n\ndef send_tweet( api, what ):\n    try:\n        print \"Tweeting '\"+what+\"'..\"\n        now = int(time.time())\n        api.update_status('@danielenick89 '+ str(now) +': '+ what)\n        print \"Tweet id \"+str(now)+ \" sent\"\n    except:\n        print \"Error while sending tweet\"\n        traceback.print_exc()\n\nGPIO.setmode(GPIO.BOARD)\nGPIO.setup(11, GPIO.IN)\nstate = GPIO.input(11)\n#print \"Content-type: text\/htmlnn\";\nwhile not GPIO.input(11):\n    time.sleep(0.3)\n#print \"Activated..\"\nwhile GPIO.input(11):\n    time.sleep(0.3)\n\n\nsend_tweet(api, \"RasPI: Unauthorized door opening detected.\")\nos.system(\"mplayer alarm2\/alarm.mp3\");\n<\/pre>\n<p><\/code><\/p>\n<p>In order to use this code you have to create an application on twitter, and then fill the variables (oauth_token, oauth_token_secret, consumer_key, consumer_secret) with the relative value you can find in the site after creating the app.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is my last Raspberry PI project. It&#8217;s a simple alarm driven by a home-made door sensor which plays an alarm sound and sends me a message via twitter. The video is in italian. Here&#8217;s the python code which uses the tweepy library: #!\/usr\/bin\/python # Import modules for CGI handling import cgi, cgitb, time import &hellip; <a href=\"http:\/\/www.nicassio.it\/daniele\/blog\/?p=51\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Raspberry PI powered Door Alarm<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9,11],"tags":[15,16,20],"_links":{"self":[{"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/posts\/51"}],"collection":[{"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=51"}],"version-history":[{"count":0,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}