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, default_baudrate, *, run_baudrate=None, rts_pin=None, reset_pin=None, debug=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, timeout=5, retries=3)¶ 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
-
baudrate
¶ The baudrate of our UART connection
-
begin
()¶ 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.
-
cipmux
¶ The IP socket multiplexing setting. 0 for one socket, 1 for multi-socket
-
connect
(secrets)¶ 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
-
echo
(echo)¶ Set AT command echo on or off
-
factory_reset
()¶ Perform a hard reset, then send factory restore settings request
-
get_version
()¶ Request the AT firmware version string and parse out the version number
-
hard_reset
()¶ Perform a hardware reset by toggling the reset pin, if it was defined in the initialization of this object
-
hw_flow
(flag)¶ Turn on HW flow control (if available) on to allow data, or off to stop
-
is_connected
¶ Initialize module if not done yet, and check if we’re connected to an access point, returns True or False
-
join_AP
(ssid, password)¶ Try to join an access point by name and password, will return immediately if we’re already connected and won’t try to reconnect
-
local_ip
¶ Our local IP address as a dotted-quad string
-
mode
¶ What mode we’re in, can be MODE_STATION, MODE_SOFTAP or MODE_SOFTAPSTATION
-
nslookup
(host)¶ Return a dotted-quad IP address strings that matches the hostname
-
ping
(host)¶ Ping the IP or hostname given, returns ms time or None on failure
-
remote_AP
¶ The name of the access point we’re connected to, as a string
-
scan_APs
(retries=3)¶ Ask the module to scan for access points and return a list of lists with name, RSSI, MAC addresses, etc
-
sntp_config
(enable, timezone=None, server=None)¶ Configure the built in ESP SNTP client with a UTC-offset number (timezone) and server as IP or hostname.
-
sntp_time
¶ Return a string with time/date information using SNTP, may return 1970 ‘bad data’ on the first few minutes, without warning!
-
socket_connect
(conntype, remote, remote_port, *, keepalive=10, retries=1)¶ 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_disconnect
()¶ Close any open socket, if there is one
-
socket_receive
(timeout=5)¶ Check for incoming data over the open socket, returns bytes
-
socket_send
(buffer, timeout=1)¶ Send data over the already-opened socket, buffer must be bytes
-
soft_reset
()¶ Perform a software reset by AT command. Returns True if we successfully performed, false if failed to reset
-
status
¶ The IP connection status number (see AT+CIPSTATUS datasheet for meaning)
-
sync
()¶ Check if we have AT commmand sync by sending plain ATs
-
version
¶ The cached version string retrieved via the AT+GMR command
-
-
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, port, family=0, socktype=0, proto=0, flags=0)¶ 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)¶ Helper to set the global internet interface
-
class
adafruit_espatcontrol.adafruit_espatcontrol_socket.
socket
(family=2, type=1, proto=0, fileno=None)¶ A simplified implementation of the Python ‘socket’ class, for connecting through an interface to a remote device
-
close
()¶ Close the socket, after reading whatever remains
-
connect
(address, conntype=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
-
readline
()¶ Attempt to return as many bytes as we can up to but not including ‘ ‘
-
recv
(num=0)¶ Read up to ‘num’ bytes from the socket, this may be buffered internally! If ‘num’ isnt specified, return everything in the buffer.
-
send
(data)¶ Send some data to the socket
-
settimeout
(value)¶ Set the read timeout for sockets, if value is 0 it will block
-