Skip to content

Commit c1cc0bd

Browse files
committed
remove debugprint, add webclient demo
1 parent 8e662d4 commit c1cc0bd

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

adafruit_espatcontrol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def send(self, buffer, timeout=1):
179179
while (time.monotonic() - stamp) < timeout:
180180
if self._uart.in_waiting:
181181
prompt += self._uart.read(1)
182-
print(prompt)
182+
#print(prompt)
183183
if prompt[-1:] == b'>':
184184
break
185185
if not prompt or (prompt[-1:] != b'>'):

examples/espatcontrol_webclient.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import time
2+
import board
3+
import busio
4+
from digitalio import DigitalInOut
5+
import adafruit_espatcontrol
6+
7+
MY_SSID = "my ssid"
8+
MY_PASS = "password"
9+
10+
URL = "http://wifitest.adafruit.com/testwifi/index.html"
11+
12+
uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.1)
13+
resetpin = DigitalInOut(board.D5)
14+
15+
print("Get a URL:", URL)
16+
17+
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, reset_pin=resetpin, debug=False)
18+
print("Connected to AT software version", esp.get_version())
19+
20+
while True:
21+
try:
22+
# Connect to WiFi if not already
23+
print("Connected to", esp.remote_AP)
24+
if esp.remote_AP[0] != MY_SSID:
25+
esp.join_AP(MY_SSID, MY_PASS)
26+
print("My IP Address:", esp.local_ip)
27+
# great, lets get the data
28+
print("Retrieving URL...", end='')
29+
header, body = esp.request_url(URL)
30+
print("OK")
31+
except RuntimeError as e:
32+
print("Failed to connect, retrying")
33+
print(e)
34+
continue
35+
36+
print('-'*40)
37+
print(str(body, 'utf-8'))
38+
print('-'*40)
39+
40+
time.sleep(60)

0 commit comments

Comments
 (0)