SMS problem in Project 14

I’m receiving no sms from Twilio when requesting. Have a look at the below screenshots:
Output of code:-

The code:-


Please help.

First try sending direct message fro twilio,you will get basic idea about working pocedure.
Now,
1.Login into the putty by entering the IP address of your digital ocean droplet.
2. create a file named with extwnsion .py which will store all the credentials related to Twilio. To create a new file type sudo nano fiename.py in the terminal. After that write below code to save all the credentials in a single file.
**SID = ‘You can find SID in your Twilio Dashboard’ **
**AUTH_TOKEN = ‘You can find on your Twilio Dashboard’ **
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard’
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning’
API_KEY = 'This is your Bolt Cloud accout API key’
DEVICE_ID = 'This is the ID of your Bolt device
Create one more file.py
Use the below code
import conf
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)

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)
You will get the output as:-

i’ve done this already and it’s working

@khandenathparth Thats great :+1: :+1:

I mean the code you sent is already working, I’m still not getting SMS in “project 14” !

@khandenathparth Add one line of code after the statement which is printing the response , to see the status of your sms .the code is :-
print("Status of SMS at Twilio is : "+str(response.status))
and check the error you are facing try to solve that.

as you can see the status says: queued
and this is what is expected, it’s correct, but I don’t receive SMS.
The temperature alert system with SMS is still working very well but in this project 14, I’m not receiving any sms.

hey , could you please cross check for the account_sid and sid

checked the account ssid but no help !! :sleepy:

Hi @khandenathparth ,
It shall be conf.SID and not conf.SSID. Make this change and let me know if it works.

@raghav.srivastava no…because I have saved it as SSID only in the conf.py file as well

@khandenathparth Apologies for the delayed response. Can you please share your entire code as text? (Don’t share the conf.py file).

@raghav.srivastava

import conf, json, time, math, statistics
from boltiot import Sms, 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)
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

    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(5)
        continue

    try:
        if sensor_value > bound[0] :
            print ("The light level increased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone turned on the lights")
            print("This is the response ",str(response))
            print("Status of sms:",str(response.status))
        elif sensor_value < bound[1]:
            print ("The light level decreased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone turned off the lights")
            print("This is the response ",str(response))
            print("Status of sms:",str(response.status))
        history_data.append(sensor_value);
    except Exception as e:
        print ("Error",e)
    time.sleep(10)

@khandenathparth Apologies for the delayed response. We are looking into your code and will get back to you shortly.

I have the same issue too, the status is coming as queued but not receiving any SMS, the same goes for the sending email too

Hi @khandenathparth @mikusarangi ,
Apologies for the delayed response. Kindly run the code given below and check if you receive a Sms.

import conf
from boltiot import Sms
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
response = sms.send_sms("The Current temperature sensor value is " +"void")
print("Status of SMS at Twilio is :" + str(response.status))

The error seems to be with your Twilio account, check if you have free credits left. Also, add +91 before your number.

@raghav.srivastava
The project is working now, without doing any changes it has started working now. Probably, there was a temporary problem in the Twilio account.
Thanks

Hi @khandenathparth ,
That’s great. Do let me know if you need any other help.

1 Like

Check whether your phone is not in “do not disturb”, Clear cache and check again.