Skip to content

Fixes for "in Adafruit_CircuitPython_ESP_ATcontrol AT+CWLAP Does not return OK #48" #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 29, 2021
2 changes: 1 addition & 1 deletion examples/esp_atcontrol_aio_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
TX = board.ESP_TX
resetpin = DigitalInOut(board.WIFI_RESET)
rtspin = False
uart = busio.UART(TX, RX, baudrate=11520)
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
esp_boot = DigitalInOut(board.WIFI_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
Expand Down
51 changes: 36 additions & 15 deletions examples/esp_atcontrol_cheerlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,38 @@
print("WiFi secrets are kept in secrets.py, please add them there!")
raise


# With a Particle Argon
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None
# Debug Level
# Change the Debug Flag if you have issues with AT commands
debugflag = False

if board.board_id == "challenger_rp2040_wifi":
RX = board.ESP_RX
TX = board.ESP_TX
resetpin = DigitalInOut(board.WIFI_RESET)
rtspin = False
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
esp_boot = DigitalInOut(board.WIFI_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None
pixel_pin = board.NEOPIXEL
num_pixels = 1
else:
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None
pixel_pin = board.A1
num_pixels = 16

print("ESP AT commands")
esp = adafruit_espatcontrol.ESP_ATcontrol(
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag
)
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light)

Expand All @@ -47,8 +64,8 @@
DATA_LOCATION = ["feeds", 0, "field2"]


# neopixels
pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.3)
# Setup and Clear neopixels
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3)
pixels.fill(0)

# we'll save the value in question
Expand Down Expand Up @@ -77,7 +94,11 @@
green = color >> 8 & 0xFF
blue = color & 0xFF
gamma_corrected = fancy.gamma_adjust(fancy.CRGB(red, green, blue)).pack()

print(
"Setting LED To: G:{0},R:{1},B:{2},Gamma:{3}".format(
green, red, blue, gamma_corrected
)
)
pixels.fill(gamma_corrected)
last_value = value
response = None
Expand Down
87 changes: 62 additions & 25 deletions examples/esp_atcontrol_countviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

# CONFIGURATION
PLAY_SOUND_ON_CHANGE = False
NEOPIXELS_ON_CHANGE = False
NEOPIXELS_ON_CHANGE = True
DISPLAY_ATTACHED = False
TIME_BETWEEN_QUERY = 60 # in seconds

# Some data sources and JSON locations to try out
Expand Down Expand Up @@ -63,17 +64,36 @@
# "screen_names=adafruit"
# DATA_LOCATION = [0, "followers_count"]


# With a Particle Argon
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True

# Debug Level
# Change the Debug Flag if you have issues with AT commands
debugflag = False

if board.board_id == "challenger_rp2040_wifi":
RX = board.ESP_RX
TX = board.ESP_TX
resetpin = DigitalInOut(board.WIFI_RESET)
rtspin = False
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
esp_boot = DigitalInOut(board.WIFI_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None
pixel_pin = board.NEOPIXEL
num_pixels = 1
pixel_type = "RGBW/GRBW"
else:
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None
pixel_pin = board.A1
num_pixels = 16
pixel_type = "RGB/GRB"

# Create the connection to the co-processor and reset
esp = adafruit_espatcontrol.ESP_ATcontrol(
Expand All @@ -82,17 +102,20 @@
esp.hard_reset()

requests.set_socket(socket, esp)

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
# Attach a 7 segment display and display -'s so we know its not live yet
display = segments.Seg7x4(i2c)
display.print("----")
# display
if DISPLAY_ATTACHED:
# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
# Attach a 7 segment display and display -'s so we know its not live yet
display = segments.Seg7x4(i2c)
display.print("----")

# neopixels
if NEOPIXELS_ON_CHANGE:
pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.4, pixel_order=(1, 0, 2, 3))
pixels.fill(0)
pixels = neopixel.NeoPixel(
pixel_pin, num_pixels, brightness=0.4, pixel_order=(1, 0, 2, 3)
)
pixels.fill(20)

# music!
if PLAY_SOUND_ON_CHANGE:
Expand All @@ -111,15 +134,25 @@ def chime_light():
"""Light up LEDs and play a tune"""
if NEOPIXELS_ON_CHANGE:
for i in range(0, 100, 10):
pixels.fill((i, i, i))
if pixel_type == "RGB/GRB":
pixels.fill((i, i, i))
elif pixel_type == "RGBW/GRBW":
pixels.fill((i, i, i, i))
pixels.show()
time.sleep(1)
if PLAY_SOUND_ON_CHANGE:
with audioio.AudioOut(board.A0) as audio:
audio.play(wave)
while audio.playing:
pass
if NEOPIXELS_ON_CHANGE:
for i in range(100, 0, -10):
pixels.fill((i, i, i))
if pixel_type == "RGB/GRB":
pixels.fill((i, i, i))
elif pixel_type == "RGBW/GRBW":
pixels.fill((i, i, i, i))
pixels.show()
time.sleep(1)
pixels.fill(0)


Expand Down Expand Up @@ -148,8 +181,11 @@ def chime_light():
value = value[x]
if not value:
continue
print(times, the_time, "value:", value)
display.print(int(value))
print("Times:{0}. The Time:{1}. Value: {2}".format(times, the_time, value))
if DISPLAY_ATTACHED:
display.print(int(value))
else:
print("INT Value:{0}".format(int(value)))

if last_value != value:
chime_light() # animate the neopixels
Expand All @@ -159,5 +195,6 @@ def chime_light():
# normally we wouldn't have to do this, but we get bad fragments
r = value = None
gc.collect()
print(gc.mem_free()) # pylint: disable=no-member
print("GC MEM:{0}".format(gc.mem_free())) # pylint: disable=no-member
print("Sleeping for: {0} Seconds".format(TIME_BETWEEN_QUERY))
time.sleep(TIME_BETWEEN_QUERY)
45 changes: 31 additions & 14 deletions examples/esp_atcontrol_localtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,38 @@
print("WiFi secrets are kept in secrets.py, please add them there!")
raise


# With a Particle Argon
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None

# Debug Level
# Change the Debug Flag if you have issues with AT commands
debugflag = False

# How Long to sleep between polling
sleep_duration = 5

if board.board_id == "challenger_rp2040_wifi":
RX = board.ESP_RX
TX = board.ESP_TX
resetpin = DigitalInOut(board.WIFI_RESET)
rtspin = False
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
esp_boot = DigitalInOut(board.WIFI_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None

else:
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None

print("ESP AT commands")
esp = adafruit_espatcontrol.ESP_ATcontrol(
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag
)
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light)

Expand Down Expand Up @@ -78,4 +94,5 @@

while True:
print(time.localtime())
time.sleep(1)
print("Sleeping for: {0} Seconds".format(sleep_duration))
time.sleep(sleep_duration)
2 changes: 1 addition & 1 deletion examples/esp_atcontrol_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
TX = board.ESP_TX
resetpin = DigitalInOut(board.WIFI_RESET)
rtspin = False
uart = busio.UART(TX, RX, baudrate=11520)
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
esp_boot = DigitalInOut(board.WIFI_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
Expand Down
40 changes: 28 additions & 12 deletions examples/esp_atcontrol_webclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,37 @@
print("WiFi secrets are kept in secrets.py, please add them there!")
raise

# Debug Level
# Change the Debug Flag if you have issues with AT commands
debugflag = False

# With a Particle Argon
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
# How long between queries
TIME_BETWEEN_QUERY = 60 # in seconds

if board.board_id == "challenger_rp2040_wifi":
RX = board.ESP_RX
TX = board.ESP_TX
resetpin = DigitalInOut(board.WIFI_RESET)
rtspin = False
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
esp_boot = DigitalInOut(board.WIFI_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None
else:
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
status_light = None

print("ESP AT commands")
esp = adafruit_espatcontrol.ESP_ATcontrol(
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag
)

URL = "http://wifitest.adafruit.com/testwifi/index.html"
Expand All @@ -57,8 +73,8 @@
print("Content size:", r.headers["content-length"])
print("Encoding:", r.encoding)
print("Text:", r.text)

time.sleep(60)
print("Sleeping for: {0} Seconds".format(TIME_BETWEEN_QUERY))
time.sleep(TIME_BETWEEN_QUERY)
except (ValueError, RuntimeError, adafruit_espatcontrol.OKError) as e:
print("Failed to get data, retrying\n", e)
continue