adafruit_fona
¶
CircuitPython library for the Adafruit FONA cellular module
Author(s): ladyada, Brent Rubell
Implementation Notes¶
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
- class adafruit_fona.adafruit_fona.FONA(uart: UART, rst: DigitalInOut, ri: DigitalInOut | None = None, debug: bool = False)¶
CircuitPython FONA module interface.
- Parameters:
uart (UART) – FONA UART connection.
rst (DigitalInOut) – FONA RST pin.
ri (DigitalInOut) – Optional FONA Ring Interrupt (RI) pin.
debug (bool) – Enable debugging output.
- delete_sms(sms_slot: int) bool ¶
Deletes a SMS message from a storage (internal or sim) slot
- Parameters:
sms_slot (int) – SMS SIM or FONA memory slot number.
- get_host_by_name(hostname: str) str | Literal[False] ¶
Converts a hostname to a packed 4-byte IP address.
- Parameters:
hostname (str) – Destination server.
- num_sms(sim_storage: bool = True) int ¶
Returns the number of SMS messages stored in memory.
- Parameters:
sim_storage (bool) – SMS storage on the SIM, otherwise internal storage on FONA chip.
- pretty_ip(ip: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray) str ¶
Converts a bytearray IP address to a dotted-quad string for printing
- read_sms(sms_slot: int) Tuple[str, str] ¶
Reads and parses SMS messages from FONA device. Returns the SMS sender’s phone number and the message contents as a tuple.
- Parameters:
sms_slot (int) – SMS SIM or FONA memory slot number.
- receive_sms() Tuple[str, str] ¶
Checks for a message notification from the FONA module, replies back with the a tuple containing (sender, message).
- Note:
This method needs to be polled consistently due to the lack of hw-based interrupts in CircuitPython.
- remote_ip(sock_num: int) str ¶
Returns the IP address of the remote server.
- Parameters:
sock_num (int) – Desired socket.
- property rssi: float¶
The received signal strength indicator for the cellular network we are connected to.
- set_gprs(apn: Tuple[str, str | None, str | None] | None = None, enable: bool = True) bool ¶
Configures and brings up GPRS.
- socket_available(sock_num: int) int ¶
Returns the amount of bytes available to be read from the socket.
- Parameters:
sock_num (int) – Desired socket to return bytes available from.
- socket_close(sock_num: int) bool ¶
Close TCP or UDP connection
- Parameters:
sock_num (int) – Desired socket number.
- socket_connect(sock_num: int, dest: str, port: int, conn_mode: int = micropython.const) bool ¶
Connects to a destination IP address or hostname. By default, we use conn_mode TCP_MODE but we may also use UDP_MODE.
- socket_read(sock_num: int, length: int) bytearray ¶
Read data from the network into a buffer. Returns bytes read.
- socket_status(sock_num: int) bool ¶
Returns the socket connection status, False if not connected.
- Parameters:
sock_num (int) – Desired socket number.
adafruit_fona_socket
¶
A socket compatible interface with the Adafruit FONA cellular module.
Author(s): ladyada, Brent Rubell
- adafruit_fona.adafruit_fona_socket.getaddrinfo(host, port: int, family=0, socktype=0, proto=0, flags=0)¶
Translate the host/port argument into a sequence of 5-tuples that contain all the necessary arguments for creating a socket connected to that service.
- adafruit_fona.adafruit_fona_socket.gethostbyname(hostname: str) str ¶
Translate a host name to IPv4 address format. The IPv4 address is returned as a string.
- Parameters:
hostname (str) – Desired hostname.
- adafruit_fona.adafruit_fona_socket.htonl(x: int) int ¶
Convert 32-bit positive integers from host to network byte order.
- adafruit_fona.adafruit_fona_socket.htons(x: int) int ¶
Convert 16-bit positive integers from host to network byte order.
- adafruit_fona.adafruit_fona_socket.set_interface(iface: FONA) None ¶
Helper to set the global internet interface.
- class adafruit_fona.adafruit_fona_socket.socket(family: int = micropython.const, type: int = micropython.const, proto: int = 0, fileno: int | None = None, socknum: int | None = None)¶
A simplified implementation of the Python ‘socket’ class for connecting to a FONA cellular module.
- connect(address: Tuple[str, int], conn_mode: int | None = None) None ¶
Connect to a remote socket at address. (The format of address depends on the address family — see above.)
- gettimeout() int ¶
Return the timeout in seconds (float) associated with socket operations, or None if no timeout is set.
- inet_aton(ip_string: str) bytearray ¶
Convert an IPv4 address from dotted-quad string format.
- Parameters:
ip_string (str) – IP Address, as a dotted-quad string.
- recv(bufsize: int = 0) Sequence[int] ¶
Reads some bytes from the connected remote address.
- Parameters:
bufsize (int) – maximum number of bytes to receive
- send(data: bytes) None ¶
Send data to the socket. The socket must be connected to a remote socket prior to calling this method.
- Parameters:
data (bytes) – Desired data to send to the socket.
adafruit_fona_network
¶
Interface for connecting to and interacting with GSM and CDMA cellular networks.
Author(s): Brent Rubell
- class adafruit_fona.adafruit_fona_network.CELLULAR(fona: FONA, apn: Tuple[str, str | None, str | None])¶
Interface for connecting to and interacting with GSM and CDMA cellular networks.
- Parameters:
- property is_connected¶
Returns if attached to network and an IP Addresss was obtained.
fona_3g
¶
FONA3G cellular module instance.
Author(s): ladyada, Brent Rubell
Implementation Notes¶
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
- class adafruit_fona.fona_3g.FONA3G(uart: UART, rst: DigitalInOut, ri: DigitalInOut | None = None, debug: bool = False)¶
FONA 3G module interface.
- Parameters:
uart (UART) – FONA UART connection.
rst (DigitalInOut) – FONA RST pin.
ri (DigitalInOut) – Optional FONA Ring Interrupt (RI) pin.
debug (bool) – Enable debugging output.
- get_host_by_name(hostname: str) str | Literal[False] ¶
Converts a hostname to a 4-byte IP address.
- Parameters:
hostname (str) – Domain name.
- remote_ip(sock_num: int) str ¶
Returns the IP address of the remote connection.
- Parameters:
sock_num (int) – Desired socket number
- set_gprs(apn: Tuple[str, str | None, str | None] | None = None, enable: bool = True) bool ¶
Configures and brings up GPRS.
- socket_connect(sock_num: int, dest: str, port: int, conn_mode: int = 0) bool ¶
Connects to a destination IP address or hostname. By default, we use conn_mode TCP_MODE but we may also use UDP_MODE.
- socket_status(sock_num: int) bool ¶
Returns socket status, True if connected. False otherwise.
- Parameters:
sock_num (int) – Desired socket number.