-
Notifications
You must be signed in to change notification settings - Fork 74
Expose handler for BSSID, and wi-fi scan handlers for BSSID & channel. #75
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
Conversation
A tl;dr test code.py (assuming ESP32 is behaving): import board
import time
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
from secrets import secrets
spi = board.SPI()
try: # PyPortal, etc.
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
except AttributeError: # Airlift FeatherWing & Bitsy Add-On compatible
esp32_cs = DigitalInOut(board.D13)
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print('Connect... BSSID RSSI SSID')
esp.connect_AP(secrets['ssid'], secrets['password'])
# NEW: bssid
print('{5:02X}:{4:02X}:{3:02X}:{2:02X}:{1:02X}:{0:02X}'.format(*esp.bssid), end='')
print(' {: 4d} {:s}'.format(esp.rssi, str(esp.ssid, 'utf-8')), end='')
print(' ping=%dms (LAN)' % esp.ping(esp.network_data['gateway']))
print()
while True:
print('Scanning... BSSID Ch RSSI SSID')
for ap in esp.scan_networks():
# NEW: bssid, channel
print('{5:02X}:{4:02X}:{3:02X}:{2:02X}:{1:02X}:{0:02X}'.format(*ap['bssid']), end='')
print(' {: 3d} {: 4d} {:s}'.format(ap['channel'], ap['rssi'], str(ap['ssid'], 'utf-8')))
print()
time.sleep(10) A more robust code.py is here. Actual output data matches data from macos
|
@anecdata This are very useful methods - thanks for exposing it within ESP32SPI. I successfully tested against your provided example code and verified against I also tested against ESP32SPI simpletest since it runs a wifi scan to ensure it still works as-expected:
|
Updating https://github.com/adafruit/Adafruit_CircuitPython_APDS9960 to 1.2.5 from 1.2.4: > Merge pull request adafruit/Adafruit_CircuitPython_APDS9960#14 from kattni/fix-up Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306#5 from makermelissa/master Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 2.0.0 from 1.9.3: > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#75 from anecdata/bssid_channel Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1306 to 2.6.6 from 2.6.4: > Merge pull request adafruit/Adafruit_CircuitPython_SSD1306#31 from makermelissa/master > Merge pull request adafruit/Adafruit_CircuitPython_SSD1306#30 from makermelissa/master Updating https://github.com/adafruit/Adafruit_CircuitPython_NTP to 1.0.1 from 1.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_NTP#3 from brentru/fix-overflow
Changes to esp32spi.py to address #74
I'd appreciate @adafruit/circuitpythonlibrarians (don't seem to be able to tag the team) code review (and test). There were good examples in the code to work from, but first time interpreting C types into CP.
Tested on a variety of combinations of M4 and ESP32 hardware. I'll post a test code.py and sample output in the comments.
P.S. BSSID, like MAC, comes in with the first octet in the 6th byte. Depending on the resolution of #66 a helper function could be added or it could be left to examples to illustrate this.