Skip to content

Commit aa77f0a

Browse files
author
brentru
committed
add delete_all
1 parent 77db2dc commit aa77f0a

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

adafruit_fona/adafruit_fona.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,7 @@ def num_sms(self, sim_storage=True):
542542
return False
543543

544544
# ask how many SMS are stored
545-
if sim_storage:
546-
if not self._send_parse_reply(b"AT+CPMS?", FONA_SMS_STORAGE_SIM + b",", idx=1):
547-
return False
548-
else:
549-
if not self._send_parse_reply(b"AT+CPMS?", FONA_SMS_STORAGE_INTERNAL + b",", idx=1):
550-
return False
545+
# TODO: look @ this again!
551546
if not self._send_parse_reply(b"AT+CPMS?", b"\"SM\",", idx=1):
552547
return False
553548
if not self._send_parse_reply(b"AT+CPMS?", b"\"SM_P\",", idx=1):
@@ -556,11 +551,43 @@ def num_sms(self, sim_storage=True):
556551
self._uart.reset_input_buffer()
557552
return self._buf
558553

559-
def read_sms(self, sms_slot=None):
554+
def delete_all_sms(self):
555+
"""Deletes all SMS messages on the FONA SIM."""
556+
# text mode
557+
if not self._send_check_reply(b"AT+CMGF=1", reply=REPLY_OK):
558+
return False
559+
560+
if not self._send_check_reply(b"AT+CMGDA=\"DEL ALL\"", reply=REPLY_OK, timeout=25000):
561+
return False
562+
return True
563+
564+
def delete_sms(self, sms_slot):
565+
"""Deletes a SMS message in the provided SMS slot.
566+
:param int sms_slot: SMS SIM or FONA memory slot number
567+
568+
"""
569+
if not self._send_check_reply(b"AT+CMGF=1", reply=REPLY_OK):
570+
return False
571+
572+
573+
sendbuff = b"AT+CMGD=";
574+
s2 = (sms_slot / 100) + 0
575+
576+
sms_slot %= 100;
577+
s3 = (sms_slot / 10) + 0
578+
579+
sms_slot %= 10;
580+
s4 = sms_slot + 0
581+
582+
print(sendbuff, s2, s3, s4)
583+
584+
self._send_check_reply(sendbuff, reply=REPLY_OK, timeout=2000)
585+
586+
587+
def read_sms(self, sms_slot):
560588
"""Reads and parses SMS messages from FONA device. Returns the SMS
561-
(sender, data) as a tuple.
562-
If no sms_slot is selected, read_sms returns all sms messages on the device.
563-
:param int sms_slot: SMS memory slot number.
589+
sender's phone number and the message contents as a tuple.
590+
:param int sms_slot: SMS SIM or FONA memory slot number
564591
565592
"""
566593
self._read_line()
@@ -579,7 +606,7 @@ def read_sms(self, sms_slot=None):
579606
# get sender
580607
if not self._parse_reply(b"+CMGR:", idx=1):
581608
return False
582-
sender = self._buf
609+
sender = self._buf.strip('"')
583610

584611
# get sms length
585612
self._buf = resp
@@ -594,7 +621,6 @@ def read_sms(self, sms_slot=None):
594621
# discard unread chars in buffer
595622
self._uart.reset_input_buffer()
596623

597-
598624
return sender, bytes(self._buf).decode()
599625

600626

0 commit comments

Comments
 (0)