Error at coding for sending SMS

I type the code as it is in the module which you have shown in the topic. But I am getting unindent error showing that unindent does not match any outer indentation level.

Your code inside the exception block is not indented properly. Add two more spaces before the print statement in exception block. It will be great if you post the code instead of a screenshot of the code. Check the screenshot.


I was getting the same error with my code!! Visit the Indentation topic in the training and you will understand your error!!
First thing is you have to write the “import” lines in your code!!

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


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")
 print("sensor value is:"+str(data['value']))
      if sensor_value>maximum_limit or sensor < minimum_limit:
        print("making request to mailgun to send email")
        response = mailer.send_email("alert","current temp value is"+str(sensor_value))
        print("response received from mailgun is:"+str(response_text['message']))
 except Exception as e:
      print("threshold exceeded:",e)

Take a look at this code!!

1 Like

Ok after solving this I am getting that ‘Device does not exist’

Check the device name in your file. Also, print the device name before while loop.

For example

print (conf.DEVICE_ID)

how to stop the readings

You can comment on all the lines inside while loop using #

import conf, json, time
from boltiot import Sms, Bolt
import json, time

minimum_limit = 300
maximum_limit = 600

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)

print ("device id is")
print (conf.DEVICE_ID)

# 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 Twilio to send a SMS")
#             response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
#             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(10)

Thank you so much for telling all the doubts about which I have asked to you

In this I am getting attribute error.
In the sandbox url I type sandboxf09*******

I think there is typo error in your code. In your file, you must have used SANDBOX_URL but in your code, you are using SANBOX_URL.

Check file file.

MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'This would be test@your SANDBOX_URL'
RECIPIENT_EMAIL = 'Enter your Email ID Here'
API_KEY = 'This is your Bolt Cloud account API key'
DEVICE_ID = 'This is the ID of your Bolt device' 

Can you tell that sandbox url means in which way it is?

@vr905900, Check this link . In your case, Sandbox url is the url provided by the Mailgun to send all the data to Mailgun server. Check the code here bolt-api-python.

In this I type remaining mailgun api key,api key and device id for bolt
tell that whether it is correct or not
I cant write remaining one due the comment is in public

It seems fine to me. What is the error after running your code?

Thank you for telling doubts I solve the problem.
In this the spelling is not same so

Thank you so much for clearing doubts.

1 Like