Temperature_alert via email


why is it showing error
what is wrong in my code?

@dixitupagyya23
Some part of your code is not visible in the screenshot.
Can you please copy paste the entire code instead of sharing the screenshot of the same?

import email_conf
from boltiot import Email, Bolt
import json, time

minimum_limit = 300 #the minimum threshold of light value
maximum_limit = 600 #the maximum threshold of light value

mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)

while True:
print (ā€œReading sensor valueā€)
response = mybolt.analogRead(ā€˜A0ā€™)
data = json.loads(response)
print ("Sensor value is: " + str(data[ā€˜valueā€™]))
try:
sensor_value = int(data[ā€˜valueā€™])
if sensor_value > maximum_limit or sensor_value < minimum_limit:
print(ā€œMaking request to Mailgun to send an emailā€)
response = mailer.send_email(ā€œAlertā€, "The Current temperature sensor value is " +str(sensor_value))
response_text = json.loads(response.text)
print("Response received from Mailgun is: " + str(response_text[ā€˜messageā€™]))
except Exception as e:
print (ā€œError occured: Below are the detailsā€)
print (e)
time.sleep(10)

here it is @yeshwant.naik
please help me to resolve my problem

If the indentation is right, then i guess there could be some error in the conf.py file u have writtenā€¦
As far as the code, it seems rightā€¦

Refer this and check out once again.
https://trainings.boltiot.com/courses/iotandml/lectures/6656783

but it is showing error in json function line.

@dixitupagyya23 Check if you have another file with the name json.py in the same directory as your program. Rename the json.py file and try again.

1 Like

Actually there is an intendation error just be specific with python intendation and your code will run.

check the spelling of mailer.send_emaail in line 23 which is wrong thatā€™s why error is occurring. And your problem is solved. That much you have to do mailer.send_email.

@dixitupagyya23 Thereā€™s a spelling mistake in your code. change your response line "response = mailer.send_email(ā€œAlertā€, ā€œThe Current temperature sensor value is " +str(sensor_value))ā€