Twilio sms code problem


Unable to figure out the solution to this error

Hello @y.soni
cheak your hardware connection and conf.py again

Sir, I have checked the hardware connection and conf.py once again, they are same as described.
Also, I’m facing the same error for Room Light Monitoring Project as well.

@y.soni
Have you imported all the necessary modules?
The ones that you require are: json, time, bolt , conf, sms

I also had this same error.You just check your connection and run many times.It worked for me.I think this will be useful to you.

1 Like

@y.soni
can you share me the whole program that will be helpful for detecting the problem.

Guys, everything is working fine today when I executed the code in the morning. I did not make any changes to my yesterday’s code. What might be the reason for this ?

@y.soni
Let me see your code

@y.soni
I got your concern. Let me explain in full detail. There is a slight mistake in your if statement where you have given the threshold value as,
if sensor_value < maximum_limit and sensor_value >= minimum_limit:
if your criteria is this then this if statement will work only when the sensor value is in between the maximum and minimum limit as you have used AND operator
Example:
Case-1:
Let your sensor value = 350
according to your if statement 350<600 and 350>=300 in this case both the statement is true and it will enter into the if block and execute the instruction inside it.
Case-2:
Let your sensor value = 250
according to your if statement 250<600 and 250>=300 in this case the 1st statement is True and in the 2nd 250 is not greater than 300 so it becomes False. As we know in AND operator will work only when both the statement is True. So it will not enter into the if statement
Case-3:
Let your sensor value = 750
according to your if statement 750<600 and 750>=300 in this case the 1st statement is false and in the 2nd 750 is greater than 300 so it becomes True. As we know AND operator will work only when both the statement are True. So it will not enter into the if statement.
So according to your if statement it will send you an SMS in every 20secs whenever there is the sensor value is within the maximum and minimum limit. and when you run this code it will show you noting because there is no error in this code.
if you want this and operator to function in the if statement then you have to put the body part of if statement in an else statement block to run see the helpful code if you can get it:
if sensor_value < maximum_limit and sensor_value>= minimum_limit:
print("Sensor Value: "+str(sensor_value))
else:
print(“Sensor Value is out of bound”)
print(“Making request to Twilio to send a SMS”)
response = sms.send_sms("Temparature Reached: "+str(sensor_value))
print("Response received from Twilio is: "+str(response))
print("Status of SMS at Twilio is: "+str(response.status))

I think you will now understand it well. If any problem arises let me know.