Skip to content
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

Expose handler for BSSID, and wi-fi scan handlers for BSSID & channel. #75

Merged
merged 1 commit into from
Sep 25, 2019
Merged

Expose handler for BSSID, and wi-fi scan handlers for BSSID & channel. #75

merged 1 commit into from
Sep 25, 2019

Conversation

anecdata
Copy link
Member

@anecdata anecdata commented Sep 21, 2019

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.

@anecdata
Copy link
Member Author

anecdata commented Sep 21, 2019

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 airport -s utility.
Sample output data has been munged for privacy:

code.py output:

ESP Firmware:   1.2.2.
ESP Status:     0
Connecting...   3
            BSSID     RSSI SSID
7C:D1:RE:DA:CT:4A      -51 NotImplemented ping=0ms (LAN)

Scanning... BSSID  Ch RSSI SSID
7C:D1:RE:DA:CT:4A   6  -51 NotImplemented
60:F4:RE:DA:CT:4E   6  -62 NotImplemented
00:1A:RE:DA:CT:02  11  -63 None_optout
00:1A:RE:DA:CT:01  11  -64 Blinka
90:72:RE:DA:CT:18   6  -90 None_optout_nomap
00:1A:RE:DA:CT:82   1  -93 None_nomap
20:C9:RE:DA:CT:FA   6  -95 None_optout_nomap

Scanning... BSSID  Ch RSSI SSID
7C:D1:RE:DA:CT:4A   6  -50 NotImplemented
60:F4:RE:DA:CT:4E   6  -60 NotImplemented
00:1A:RE:DA:CT:01  11  -63 Blinka
00:1A:RE:DA:CT:02  11  -65 None_optout
90:72:RE:DA:CT:18   6  -92 None_optout_nomap
20:C9:RE:DA:CT:FA   6  -94 None_optout_nomap

@brentru brentru requested a review from a team September 25, 2019 14:54
@brentru
Copy link
Member

brentru commented Sep 25, 2019

@anecdata This are very useful methods - thanks for exposing it within ESP32SPI.

I successfully tested against your provided example code and verified against airport -s (not posting result code for privacy reasons).

I also tested against ESP32SPI simpletest since it runs a wifi scan to ensure it still works as-expected:

ESP32 SPI webclient test
ESP32 found and in idle mode
Firmware vers. bytearray(b'1.2.2\x00')
MAC addr: ['0x5d', '0xad', 'snip', '0x33', '0x4f', '0xc4']
	snip		RSSI: -53
	snip		RSSI: -62
	snip		RSSI: -66
	snip		RSSI: -71
	snip		RSSI: -71
	snip		RSSI: -72
	snip		RSSI: -76
	snip		RSSI: -81
	snip		RSSI: -81
	snip		RSSI: -90

@brentru brentru merged commit 83fe4b3 into adafruit:master Sep 25, 2019
@anecdata anecdata deleted the bssid_channel branch September 25, 2019 15:26
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 25, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants