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
Then. connect the DS18B20 output to “P9_22”, GND to “P9_46”, and Vdd to “P9_3”
Code in python
#!/usr/bin/python
import datetime
import time
import os, glob
import math
from contextlib import closing
from twilio.rest import TwilioRestClient
# VARIABLES
# CHANGE ACCORDING TO YOU
# Insert your own account's SID and auth_token from Twilio's account page
twilio_account_sid = "your_account_sid"
twilio_auth_token = "your_account_token"
# The phone number you purchased from Twilio
sTwilioNumber = "your_twilio_number"
# The phone number of the receiver
sSMSSender = "receiver_number"
TwilioClient = TwilioRestClient(twilio_account_sid, twilio_auth_token)
n=0
# This function sends an SMS message, wrapped in some error handling
def SendSMS(sMsg):
try:
sms = TwilioClient.sms.messages.create(body="{0}".format(sMsg),to="{0}".format(sSMSSender),from_="{0}".format(sTwilioNumber))
except:
print "Error inside function SendSMS"
pass
# Taking value from one-wire temperature sensor
#w1="/sys/bus/w1/devices/28-00000254e003/w1_slave"
w1="/sys/bus/w1/devices/28-0000052196d6/w1_slave"
valore = 27
while True:
raw = open(w1, "r").read()
print "Temperature is "+str(float(raw.split("t=")[-1])/1000)+" degrees"
if (float(raw.split("t=")[-1])/1000) > valore : # Checking Temperature Value, to triggger Alarm
SendSMS("Test from Home")