adafruit_espatcontrol.adafruit_espatcontrol
¶
Use the ESP AT command sent to communicate with the Interwebs. Its slow, but works to get data into CircuitPython
Command set: https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
Examples: https://www.espressif.com/sites/default/files/documentation/4b-esp8266_at_command_examples_en.pdf
Author(s): ladyada
Implementation Notes¶
Hardware:
Adafruit ESP8266 Huzzah Breakout (Product ID: 2471)
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
- class adafruit_espatcontrol.adafruit_espatcontrol.ESP_ATcontrol(uart: UART, default_baudrate: int, *, run_baudrate: Optional[int] = None, rts_pin: Optional[DigitalInOut] = None, reset_pin: Optional[DigitalInOut] = None, debug: bool = False)¶
A wrapper for AT commands to a connected ESP8266 or ESP32 module to do some very basic internetting. The ESP module must be pre-programmed with AT command firmware, you can use esptool or our CircuitPython miniesptool to upload firmware
- at_response(at_cmd: str, timeout: int = 5, retries: int = 3) bytes ¶
Send an AT command, check that we got an OK response, and then cut out the reply lines to return. We can set a variable timeout (how long we’ll wait for response) and how many times to retry before giving up
- begin() None ¶
Initialize the module by syncing, resetting if necessary, setting up the desired baudrate, turning on single-socket mode, and configuring SSL support. Required before using the module but we dont do in __init__ because this can throw an exception.
- connect(secrets: Dict[str, Union[str, int]]) None ¶
Repeatedly try to connect to an access point with the details in the passed in ‘secrets’ dictionary. Be sure ‘ssid’ and ‘password’ are defined in the secrets dict! If ‘timezone’ is set, we’ll also configure SNTP
- get_version() Optional[str] ¶
Request the AT firmware version string and parse out the version number
- hard_reset() None ¶
Perform a hardware reset by toggling the reset pin, if it was defined in the initialization of this object
- property is_connected: bool¶
Initialize module if not done yet, and check if we’re connected to an access point, returns True or False
- join_AP(ssid: str, password: str) None ¶
Try to join an access point by name and password, will return immediately if we’re already connected and won’t try to reconnect
- property mode: Optional[int]¶
What mode we’re in, can be MODE_STATION, MODE_SOFTAP or MODE_SOFTAPSTATION
- nslookup(host: str) Optional[str] ¶
Return a dotted-quad IP address strings that matches the hostname
- property remote_AP: List[Optional[Union[int, str]]]¶
The name of the access point we’re connected to, as a string
- scan_APs(retries: int = 3) Optional[List[List[bytes]]] ¶
Ask the module to scan for access points and return a list of lists with name, RSSI, MAC addresses, etc
- sntp_config(enable: bool, timezone: Optional[int] = None, server: Optional[str] = None) None ¶
Configure the built in ESP SNTP client with a UTC-offset number (timezone) and server as IP or hostname.
- property sntp_time: Optional[bytes]¶
Return a string with time/date information using SNTP, may return 1970 ‘bad data’ on the first few minutes, without warning!
- socket_connect(conntype: str, remote: str, remote_port: int, *, keepalive: int = 10, retries: int = 1) bool ¶
Open a socket. conntype can be TYPE_TCP, TYPE_UDP, or TYPE_SSL. Remote can be an IP address or DNS (we’ll do the lookup for you. Remote port is integer port on other side. We can’t set the local port
- socket_receive(timeout: int = 5) bytearray ¶
Check for incoming data over the open socket, returns bytes
- socket_send(buffer: bytes, timeout: int = 1) bool ¶
Send data over the already-opened socket, buffer must be bytes
- soft_reset() bool ¶
Perform a software reset by AT command. Returns True if we successfully performed, false if failed to reset
- exception adafruit_espatcontrol.adafruit_espatcontrol.OKError¶
The exception thrown when we didn’t get acknowledgement to an AT command
A ‘socket’ compatible interface thru the ESP AT command set
- adafruit_espatcontrol.adafruit_espatcontrol_socket.getaddrinfo(host: str, port: int, family: int = 0, socktype: int = 0, proto: int = 0, flags: int = 0) List[Tuple[int, int, int, str, Tuple[str, int]]] ¶
Given a hostname and a port name, return a ‘socket.getaddrinfo’ compatible list of tuples. Honestly, we ignore anything but host & port
- adafruit_espatcontrol.adafruit_espatcontrol_socket.set_interface(iface: ESP_ATcontrol) None ¶
Helper to set the global internet interface
- class adafruit_espatcontrol.adafruit_espatcontrol_socket.socket(family: int = 2, type: int = 1, proto: int = 0, fileno: Optional[int] = None)¶
A simplified implementation of the Python ‘socket’ class, for connecting through an interface to a remote device
- connect(address: Tuple[str, int], conntype: Optional[str] = None) None ¶
Connect the socket to the ‘address’ (which should be dotted quad IP). ‘conntype’ is an extra that may indicate SSL or not, depending on the underlying interface