Skip to content

Commit 5a1e39e

Browse files
author
brentru
committed
add send_sms
1 parent 679b7ed commit 5a1e39e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

adafruit_fona/adafruit_fona.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,26 @@ def unpretty_ip(self, ip): # pylint: disable=no-self-use, invalid-name
488488
octets = [int(x) for x in ip.split(".")]
489489
return bytes(octets)
490490

491+
### SMS ###
492+
493+
def send_sms(self, phone_number, message):
494+
"""Sends a message SMS to a phone number.
495+
:param int phone_number: Destination phone number.
496+
:param str message: Message to send to the phone number.
497+
498+
"""
499+
# select SMS message format, text mode (4.2.2)
500+
if not self._send_check_reply(b"AT+CMGF=1", reply=REPLY_OK):
501+
return False
502+
503+
self.uart_write(b"AT+CMGS" + b"+\'" + str(phone_number).encode() + b"'")
504+
# <CR><CR><LF>><Space>
505+
self._uart.write(b"\r\r\n> ")
506+
self._uart.write(b"\n")
507+
self._read_line(30000)
508+
509+
510+
491511
### Socket API (TCP, UDP) ###
492512

493513
def get_socket(self):

0 commit comments

Comments
 (0)