-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_code
More file actions
40 lines (34 loc) · 1.25 KB
/
python_code
File metadata and controls
40 lines (34 loc) · 1.25 KB
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
from boltiot import Sms, Bolt
import json, time,conf
minval=8
maxval=18
mybolt = Bolt(conf.API_KEY,conf.DEVICE_ID)
sms = Sms(conf.SSID,conf.AUTH_TOKEN,conf.TO_NUMBER,conf.FROM_NUMBER)
while True:
print ("Reading sensor value")
response = mybolt.serialRead('3')
data = json.loads(response)
j=data['value']
charsLen=len(j)
def strToNumber(numStr):
num = 0
for i, c in enumerate(reversed(numStr)):
num += j.index(c) * (charsLen ** i)
return(num)
b=strToNumber(j)
print(b)
try:
if b <=minval:
print("Making request to Twilio to send a SMS")
response = sms.send_sms("The tank is full please swith off the motor ")
print("Response received from Twilio is: " + str(response))
print("Status of SMS at Twilio is :" + str(response.status))
if b >=maxval:
print("Making request to Twilio to send a SMS")
response = sms.send_sms("The tank is empty please swith on the motor ")
print("Response received from Twilio is: " + str(response))
print("Status of SMS at Twilio is :" + str(response.status))
except Exception as e:
print ("Error occured: Below are the details")
print (e)
time.sleep(5)