Skip to content

Commit d29e537

Browse files
brentrubrentru
authored andcommitted
add example for esp_at
1 parent 5d1c39c commit d29e537

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""
2+
Usage example of the ESP32 over UART
3+
using the CircuitPython ESP_ATControl library.
4+
5+
Dependencies:
6+
* https://github.com/adafruit/Adafruit_CircuitPython_ESP_ATcontrol
7+
"""
8+
from random import randint
9+
import board
10+
import busio
11+
from digitalio import DigitalInOut
12+
13+
# ESP32 AT
14+
from adafruit_espatcontrol import adafruit_espatcontrol, adafruit_espatcontrol_wifimanager
15+
16+
#Use below for Most Boards
17+
import neopixel
18+
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards
19+
#Uncomment below for ItsyBitsy M4#
20+
#import adafruit_dotstar as dotstar
21+
#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
22+
23+
# Import Adafruit IO REST Client
24+
from adafruit_io.adafruit_io import RESTClient, AdafruitIO_RequestError
25+
26+
# Get wifi details and more from a secrets.py file
27+
try:
28+
from secrets import secrets
29+
except ImportError:
30+
print("WiFi secrets are kept in secrets.py, please add them there!")
31+
raise
32+
33+
# With a Metro or Feather M4
34+
uart = busio.UART(board.TX, board.RX, timeout=0.1)
35+
resetpin = DigitalInOut(board.D5)
36+
rtspin = DigitalInOut(board.D6)
37+
38+
# With a Particle Argon
39+
"""
40+
RX = board.ESP_TX
41+
TX = board.ESP_RX
42+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
43+
rtspin = DigitalInOut(board.ESP_CTS)
44+
uart = busio.UART(TX, RX, timeout=0.1)
45+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
46+
from digitalio import Direction
47+
esp_boot.direction = Direction.OUTPUT
48+
esp_boot.value = True
49+
"""
50+
51+
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200,
52+
reset_pin=resetpin, rts_pin=rtspin, debug=False)
53+
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light)
54+
55+
# Set your Adafruit IO Username and Key in secrets.py
56+
# (visit io.adafruit.com if you need to create an account,
57+
# or if you need your Adafruit IO key.)
58+
ADAFRUIT_IO_USER = secrets['adafruit_io_user']
59+
ADAFRUIT_IO_KEY = secrets['adafruit_io_key']
60+
61+
# Create an instance of the Adafruit IO REST client
62+
io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi)
63+
64+
try:
65+
# Get the 'temperature' feed from Adafruit IO
66+
temperature_feed = io.get_feed('temperature')
67+
except AdafruitIO_RequestError:
68+
# If no 'temperature' feed exists, create one
69+
temperature_feed = io.create_new_feed('temperature')
70+
71+
# Send random integer values to the feed
72+
random_value = randint(0, 50)
73+
print('Sending {0} to temperature feed...'.format(random_value))
74+
io.send_data(temperature_feed['key'], random_value)
75+
print('Data sent!')
76+
77+
# Retrieve data value from the feed
78+
print('Retrieving data from temperature feed...')
79+
received_data = io.receive_data(temperature_feed['key'])
80+
print('Data from temperature feed: ', received_data['value'])

0 commit comments

Comments
 (0)