Skip to content

Commit 45cf5c1

Browse files
author
Matt Costi
committed
- Can now create AP w/out passphrase
- channel needed to be in hex byte format. - Add begining of a server example example program. - TODO: figure out why cannot create AP w/ passphrase
1 parent b9befbf commit 45cf5c1

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,14 @@ def wifi_set_ap_network(self, ssid, channel):
416416
resp = self._send_command_get_response(_SET_AP_NET_CMD, [ssid, channel])
417417
if resp[0][0] != 1:
418418
raise RuntimeError("Failed to setup AP network")
419-
419+
420420
def wifi_set_ap_passphrase(self, ssid, passphrase, channel):
421421
"""TODO Docs"""
422+
""" TODO: Why does this command refuse to work? creating AP w/out password works fine"""
422423
resp = self._send_command_get_response(_SET_AP_PASSPHRASE_CMD, [ssid, passphrase, channel])
423424
if resp[0][0] != 1:
424-
raise RuntimeError("Failed to setup AP network")
425-
425+
raise RuntimeError("Failed to setup AP password")
426+
426427
@property
427428
def ssid(self):
428429
"""The name of the access point we're connected to"""
@@ -496,7 +497,7 @@ def connect_AP(self, ssid, password): # pylint: disable=invalid-name
496497
raise RuntimeError("No such ssid", ssid)
497498
raise RuntimeError("Unknown error 0x%02X" % stat)
498499

499-
def create_AP(self, ssid, password, channel=1):
500+
def create_AP(self, ssid, password, channel=b'\x01'):
500501
"""Create an access point with the given name and password."""
501502
if isinstance(ssid, str):
502503
ssid = bytes(ssid, 'utf-8')

adafruit_esp32spi/adafruit_esp32spi_wifimanager.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ESPSPI_WiFiManager:
3939
"""
4040
A class to help manage the Wifi connection
4141
"""
42-
def __init__(self, esp, secrets, status_pixel=None, attempts=2):
42+
def __init__(self, esp, secrets, status_pixel=None, attempts=2, debug=False):
4343
"""
4444
:param ESP_SPIcontrol esp: The ESP object we are using
4545
:param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
@@ -50,9 +50,9 @@ def __init__(self, esp, secrets, status_pixel=None, attempts=2):
5050
"""
5151
# Read the settings
5252
self._esp = esp
53-
self.debug = False
53+
self.debug = debug
5454
self.ssid = secrets['ssid']
55-
self.password = secrets['password']
55+
self.password = secrets.get('password', None)
5656
self.attempts = attempts
5757
requests.set_interface(self._esp)
5858
self.statuspix = status_pixel
@@ -99,12 +99,16 @@ def create_ap(self):
9999
Attempt to initialize in Access Point (AP) mode.
100100
Other WiFi devices will be able to connect to the created Access Point
101101
"""
102+
failure_count = 0
102103
while not self._esp.ap_listening:
103104
try:
104105
if self.debug:
105106
print("Waiting for AP to be initialized...")
106107
self.pixel_status((100,0,0))
107-
self._esp.create_AP(bytes.ssid, 'utf-8'), bytes(self.password, 'utf-8')
108+
if(self.password):
109+
self._esp.create_AP(bytes(self.ssid, 'utf-8'), bytes(self.password, 'utf-8'))
110+
else:
111+
self._esp.create_AP(bytes(self.ssid, 'utf-8'), None)
108112
failure_count = 0
109113
self.pixel_status((0,100,0))
110114
except (ValueError, RuntimeError) as error:
@@ -114,6 +118,7 @@ def create_ap(self):
114118
failure_count = 0
115119
self.reset()
116120
continue
121+
print("Access Point created! Connect to ssid: {}".format(self.ssid))
117122

118123
def get(self, url, **kw):
119124
"""

examples/esp32spi_server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import board
2+
import busio
3+
from digitalio import DigitalInOut
4+
from secrets import secrets
5+
6+
from adafruit_esp32spi import adafruit_esp32spi
7+
import adafruit_esp32spi.adafruit_esp32spi_requests as requests
8+
import adafruit_esp32spi.adafruit_esp32spi_wifimanager as wifimanager
9+
10+
print("ESP32 SPI web server test!!!!!!")
11+
12+
esp32_cs = DigitalInOut(board.D10)
13+
esp32_ready = DigitalInOut(board.D9)
14+
esp32_reset = DigitalInOut(board.D7)
15+
16+
17+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
18+
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, debug=True)
19+
20+
wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, debug=True)
21+
22+
wifi.create_ap();
23+
24+
print("done!")

0 commit comments

Comments
 (0)