Temperature monitoring code error


import conf, json, time, math, statistics
from boltiot import Sms, Email, Bolt
def compute_bounds(history_data,frame_size,factor):
if len(history_data)<frame_size :
return None

if len(history_data)>frame_size :
    del history_data[0:len(history_data)-frame_size]
Mn=statistics.mean(history_data)
Variance=0
for data in history_data :
    Variance += math.pow((data-Mn),2)
Zn = factor * math.sqrt(Variance / frame_size)
High_bound = history_data[frame_size-1]+Zn
Low_bound = history_data[frame_size-1]-Zn
return [High_bound,Low_bound]

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer =Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
history_data=[]

while True:
response = mybolt.analogRead(‘A0’)
data = json.loads(response)
if data[‘success’] != 1:
print(“There was an error while retriving the data.”)
print(“This is the error:”+data[‘value’])
time.sleep(10)
continue

sensor_value1 = int(data['value'])
sensor_value1 = sensor_value1/10.24
print ("This is the value "+data['value'])
sensor_value=0
try:
    sensor_value = int(data['value'])
except e:
    print("There was an error while parsing the response: ",e)
    continue

bound = compute_bounds(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
if not bound:
    required_data_count=conf.FRAME_SIZE-len(history_data)
    print("Not enough data to compute Z-score. Need ",required_data_count,"more data points")
    history_data.append(int(data['value']))
    time.sleep(10)
    continue

try:
    if sensor_value > bound[0] :
        sensor_value1 = sensor_value/10.24
        print ("The Temperature level INCREASED suddenly. Sending an SMS.")
        response = sms.send_sms("Someone opened the door", str(sensor_value1))
        response = mailer.sent_email("Alert", "Someone opened the door", str(sensor_value1))
        print("This is the response for SMS ",response)
        print("This is the response sor EMAIL", response1)
    history_data.append(sensor_value);
except Exception as e:
    print ("Error",e)
time.sleep(10)

Give me the some solution.

Capture
Even i am geting the same but i got sms i did get email

1 Like

bro use the response=sms.send_sms(“The temperarure has increased ,someone has opened the door”)

did you find solution to the above error?
because im getting the same error

Hi @nehaanitasingh24,

Please share your code. Also check if you are passing the single argument to send_sms functions.

sms.send_sms("Message to be sent")
1 Like

thank you for replying sir

@nehaanitasingh24

There is an error on the line where you have called send_email function.

You have not closed the function call properly.
Replace str(sensor_val$ with str(sensor_val)) at the end of the line.

thank you responding sir but its +str(sensor_val)) only the $ indicates the continuation as the vmware dont show full even in full screen . And My error is already solved Thank u

1 Like