{"id":204,"date":"2014-12-02T04:48:17","date_gmt":"2014-12-02T04:48:17","guid":{"rendered":"http:\/\/guceret.com\/wp\/?p=204"},"modified":"2014-12-02T05:17:48","modified_gmt":"2014-12-02T05:17:48","slug":"thermometer-using-twilio-api-for-sms","status":"publish","type":"post","link":"https:\/\/guceret.com\/wp\/?p=204","title":{"rendered":"Thermometer using Twilio API for SMS"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>First, install the DS18B20 termometer following the in instruction in   <a title=\"DS18B20\" href=\"http:\/\/robogoby.blogspot.com.au\/2014\/05\/beaglebone-and-ds18b20-temp-sensor.html\" target=\"_blank\">DS18B20 here<\/a>.<\/p>\n<p>Next, create a Twilio account and then install Twilio API in your Beaglebone Black with following commands.  <\/p>\n<p>install -y python-dev libmysqlclient-dev<br \/>\npip install twilio<\/p>\n<p><!--more--><\/p>\n<p>Then. connect the DS18B20 output \u00a0to\u00a0\u00a0&#8220;P9_22&#8221;, \u00a0GND to \u00a0&#8220;P9_46&#8221;, and Vdd to &#8220;P9_3&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p>Code in python<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/python\r\nimport datetime\r\nimport time\r\nimport os, glob\r\nimport math\r\nfrom contextlib import closing\r\nfrom twilio.rest import TwilioRestClient\r\n\r\n \r\n# VARIABLES\r\n# CHANGE ACCORDING TO YOU\r\n\r\n# Insert your own account's SID and auth_token from Twilio's account page\r\ntwilio_account_sid = &quot;your_account_sid&quot;\r\ntwilio_auth_token =  &quot;your_account_token&quot;\r\n# The phone number you purchased from Twilio\r\nsTwilioNumber = &quot;your_twilio_number&quot;\r\n# The phone number of the receiver \r\nsSMSSender = &quot;receiver_number&quot;\r\n\r\nTwilioClient = TwilioRestClient(twilio_account_sid, twilio_auth_token)\r\nn=0\r\n\r\n# This function sends an SMS message, wrapped in some error handling\r\ndef SendSMS(sMsg):\r\n  try:\r\n    sms = TwilioClient.sms.messages.create(body=&quot;{0}&quot;.format(sMsg),to=&quot;{0}&quot;.format(sSMSSender),from_=&quot;{0}&quot;.format(sTwilioNumber))\r\n  except:\r\n    print &quot;Error inside function SendSMS&quot;\r\n    pass\r\n\r\n\r\n\r\n# Taking value from one-wire temperature sensor \r\n#w1=&quot;\/sys\/bus\/w1\/devices\/28-00000254e003\/w1_slave&quot;\r\nw1=&quot;\/sys\/bus\/w1\/devices\/28-0000052196d6\/w1_slave&quot;\r\nvalore =  27\r\nwhile True: \r\n   raw = open(w1, &quot;r&quot;).read()\r\n   print &quot;Temperature is &quot;+str(float(raw.split(&quot;t=&quot;)&#x5B;-1])\/1000)+&quot; degrees&quot;\r\n   \r\n   if  (float(raw.split(&quot;t=&quot;)&#x5B;-1])\/1000) &gt; valore :  # Checking Temperature Value, to triggger Alarm\r\n      SendSMS(&quot;Test from Home&quot;)   \r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; First, install the DS18B20 termometer following the in instruction in DS18B20 here. Next, create a Twilio account and then install Twilio API in your Beaglebone Black with following commands. install -y python-dev libmysqlclient-dev pip install twilio<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-beaglebone-black"],"_links":{"self":[{"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=204"}],"version-history":[{"count":4,"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":218,"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions\/218"}],"wp:attachment":[{"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guceret.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}