-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemperatureMeasurement.py
59 lines (44 loc) · 2.05 KB
/
TemperatureMeasurement.py
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
account_sid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Your Twillo Account sid
auth_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Your Twillo Account Token
ph_no = "+XXXXXXXXXX" # From Which you Want to send the message
device_to_contact = "+XXXXXXXXXXX" # To which you want to send the message
api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxx" # API key of the bolt device
device_id = "BOLTXXXXX" # Your Unique Bolt Device ID
chat_id = "@xxxxxx" # Telegram Channel Unique ID where you want to send the message
telegram_id_api = "botxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Telegram bot API key
def send_telegram_message(message):
url = "https://api.telegram.org/" + telegram_id_api + "/sendMessage"
print(url)
response = requests.request(
"POST",
url=url,
params={
"chat_id": chat_id,
"text": message
}
)
return response
import json
import time
import boltiot
import Information
minimum_limit = 15
maximum_limit = 20
bolt_connect = boltiot.Bolt(Information.api_key,Information.device_id)
response = bolt_connect.analogRead('A0')
result = json.loads(response)
sms = boltiot.Sms(Information.account_sid, Information.auth_token, Information.device_to_contact, Information.ph_no)
while True:
response = bolt_connect.analogRead('A0')
result = json.loads(response)
temperature = int(result['value']) / 10.24
print("Current Temperature reading : " + str(temperature) + ' C')
try:
if temperature > maximum_limit or temperature < minimum_limit :
message = "Temperature is not suitable please evacuate" + str(temperature) + ' C'
sms.send_sms(message)
send_telegram_message(message)
except Exception as e:
print("Error has occur :")
print(e)
time.sleep(20)