adafruit_fona

CircuitPython library for the Adafruit FONA cellular module

  • Author(s): ladyada, Brent Rubell

Implementation Notes

Software and Dependencies:

class adafruit_fona.adafruit_fona.FONA(uart, rst, ri=None, debug=False)

CircuitPython FONA module interface. :param ~busio.uart UART: FONA UART connection. :param ~digialio RST: FONA RST pin. :param ~digialio RI: Optional FONA Ring Interrupt (RI) pin. :param bool debug: Enable debugging output.

delete_all_sms()

Deletes all SMS messages on the FONA SIM.

delete_sms(sms_slot)

Deletes a SMS message from a storage (internal or sim) slot :param int sms_slot: SMS SIM or FONA memory slot number.

enable_sms_notification

Checks if SMS notifications are enabled.

factory_reset()

Resets modem to factory configuration.

get_host_by_name(hostname)

Converts a hostname to a packed 4-byte IP address. :param str hostname: Destination server.

get_socket()

Obtains a socket, if available.

gprs

GPRS (General Packet Radio Services) power status.

gps

Module’s GPS status.

iccid

SIM Card’s unique ICCID (Integrated Circuit Card Identifier).

iemi

FONA Module’s IEMI (International Mobile Equipment Identity) number.

local_ip

Module’s local IP address, None if not set.

network_status

The status of the cellular network.

num_sms(sim_storage=True)

Returns the number of SMS messages stored in memory. :param bool sim_storage: SMS storage on the SIM, otherwise internal storage on FONA chip.

pretty_ip(ip)

Converts a bytearray IP address to a dotted-quad string for printing

read_sms(sms_slot)

Reads and parses SMS messages from FONA device. Returns the SMS sender’s phone number and the message contents as a tuple. :param int sms_slot: SMS SIM or FONA memory slot number.

receive_sms()

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)

Returns the IP address of the remote server. :param int sock_num: Desired socket.

reset()

Performs a hardware reset on the modem.

rssi

The received signal strength indicator for the cellular network we are connected to.

send_sms(phone_number, message)

Sends a message SMS to a phone number. :param int phone_number: Destination phone number. :param str message: Message to send to the phone number.

set_gprs(apn=None, enable=True)

Configures and brings up GPRS. :param bool enable: Enables or disables GPRS.

socket_available(sock_num)

Returns the amount of bytes available to be read from the socket. :param int sock_num: Desired socket to return bytes available from.

socket_close(sock_num)

Close TCP or UDP connection :param int sock_num: Desired socket number.

socket_connect(sock_num, dest, port, conn_mode=<sphinx.ext.autodoc.importer._MockObject object>)

Connects to a destination IP address or hostname. By default, we use conn_mode TCP_MODE but we may also use UDP_MODE. :param int sock_num: Desired socket number :param str dest: Destination dest address. :param int port: Destination dest port. :param int conn_mode: Connection mode (TCP/UDP)

socket_read(sock_num, length)

Read data from the network into a buffer. Returns buffer and amount of bytes read. :param int sock_num: Desired socket to read from. :param int length: Desired length to read.

socket_status(sock_num)

Returns the socket connection status, False if not connected. :param int sock_num: Desired socket number.

socket_write(sock_num, buffer, timeout=3000)

Writes bytes to the socket. :param int sock_num: Desired socket number to write to. :param bytes buffer: Bytes to write to socket. :param int timeout: Socket write timeout, in milliseconds.

unpretty_ip(ip)

Converts a dotted-quad string to a bytearray IP address

version

The version of the FONA module. Can be FONA_800_L, FONA_800_H, FONA_808_V1, FONA_808_V2, FONA_3G_A, FONA3G_E.

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, 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)

Translate a host name to IPv4 address format. The IPv4 address is returned as a string. :param str hostname: Desired hostname.

adafruit_fona.adafruit_fona_socket.htonl(x)

Convert 32-bit positive integers from host to network byte order.

adafruit_fona.adafruit_fona_socket.htons(x)

Convert 16-bit positive integers from host to network byte order.

adafruit_fona.adafruit_fona_socket.set_interface(iface)

Helper to set the global internet interface.

class adafruit_fona.adafruit_fona_socket.socket(family=<sphinx.ext.autodoc.importer._MockObject object>, type=<sphinx.ext.autodoc.importer._MockObject object>, proto=0, fileno=None, socknum=None)

A simplified implementation of the Python ‘socket’ class for connecting to a FONA cellular module. :param int family: Socket address (and protocol) family. :param int type: Socket type.

available()

Returns how many bytes are available to be read from the socket.

close()

Closes the socket.

connect(address, conn_mode=None)

Connect to a remote socket at address. (The format of address depends on the address family — see above.) :param tuple address: Remote socket as a (host, port) tuple. :param int conn_mode: Connection mode (TCP/UDP)

connected

Returns whether or not we are connected to the socket.

getpeername()

Return the remote address to which the socket is connected.

gettimeout()

Return the timeout in seconds (float) associated with socket operations, or None if no timeout is set.

inet_aton(ip_string)

Convert an IPv4 address from dotted-quad string format. :param str ip_string: IP Address, as a dotted-quad string.

readline()

Attempt to return as many bytes as we can up to but not including ‘ ‘

recv(bufsize=0)

Reads some bytes from the connected remote address. :param int bufsize: maximum number of bytes to receive

send(data)

Send data to the socket. The socket must be connected to a remote socket prior to calling this method. :param bytes data: Desired data to send to the socket.

settimeout(value)

Sets socket read timeout. :param int value: Socket read timeout, in seconds.

socknum

Returns the socket object’s socket number.