Skip to content

Commit

Permalink
Update fona.py
Browse files Browse the repository at this point in the history
removed automated response back to non-authorized phone numbers to prevent spamming loop
  • Loading branch information
mdegrazia authored Oct 24, 2017
1 parent 8dc91a8 commit e2b1519
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/fona.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import time

class fona(object):
"""Class that controls an AC/DC control relay
SERIAL_PORT, BAUDRATE, timeout=.1, rtscts=0
"""Class that send messages with an Adafruit Fona
SERIAL_PORT, BAUDRATE, timeout=.1, rtscts=0
Attributes:
name: Relay name (IE - Heater, Light, etc.
GPIO_PIN: BCM GPIO PIN on rasperry pi that the AC/D control relay is plugged into
unauthorize numbers
"""
def __init__(self,name,ser):
def __init__(self,name,ser,allowednumbers):
self.name = name
self.ser=ser
self.allowednumbers=allowednumbers


#send a command to the modem
Expand Down Expand Up @@ -61,23 +61,19 @@ def getMessages(self,confirmation=True):
#now that we read the message,remove it from the SIM card
#self.sendCommand("AT+CMGD="+str(message_id))
time.sleep(1)
#now delete the messages since the have been read
#now delete the messages since they have been read
for message in messages:
self.sendCommand("AT+CMGD="+str(message[0]))
if confirmation is True:
self.sendMessage(message[1],"Message Received: " + message[2])
phone_number = message[1].replace('"','')
phone_number = phone_number.replace("+",'')
print phone_number
if phone_number in self.allowednumbers:
self.sendMessage(message[1],"Message Received: " + message[2])
return messages

def deleteMessages(self):
messages = self.getMessages(confirmation=False)
return len(messages)

'''
ser=serial.Serial("/dev/ttyUSB0", 9600, timeout=.1, rtscts=0)
#messages = fona.getMessages(confirmation=True)
print "deleting messages"
num = fona.deleteMessages()
print "messages deleted: " + str(num)
'''

0 comments on commit e2b1519

Please sign in to comment.