Error at coding for sending SMS


#1

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.


Project 14 Room Light Monitoring using Z-score analysics
Error in python code in virtual machine evry time ,even i my code is right ,so i am not able to make projects, please help
#2

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.

33%20AM


#3

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


minimum_limit=300
maximum_limit=600

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')
 print("sensor value is:"+str(data['value']))
 data=json.loads(response)
 try:
      sensor_value=int(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))
        response_text=json.loads(response.text)
        print("response received from mailgun is:"+str(response_text['message']))
 except Exception as e:
      print("threshold exceeded:",e)
      continue
 time.sleep(10)

Take a look at this code!!


#4

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


#5


#6

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

For example


print (conf.DEVICE_ID)

#7

how to stop the readings


#8

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)

#9

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


#10

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


#11

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

Check file email_conf.py 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' 

#12

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


#13

@vr905900, Check this link https://stackoverflow.com/questions/2126174/what-is-sandboxing/2126182#2126182 . 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.


#14


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


#15

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


#16

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

Thank you so much for clearing doubts.


#17