Created
December 16, 2020 18:27
-
-
Save anecdata/cc68a0917ca2c7895a216d0fbaff185c to your computer and use it in GitHub Desktop.
ESP32-S2 Wi-Fi set-up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if 'ESP32S2' in os.uname().machine: | |
| print("MAC", ":".join('%x' % x for x in wifi.radio.mac_address)) | |
| # don't proceed w/o any Wi-Fi APs | |
| print("Scanning WiFi...") | |
| while True: | |
| try: | |
| for network in wifi.radio.start_scanning_networks(): | |
| print("{0:02X}:{1:02X}:{2:02X}:{3:02X}:{4:02X}:{5:02X}".format(*network.bssid), | |
| network.channel, | |
| network.rssi, | |
| network.ssid) | |
| wifi.radio.stop_scanning_networks() | |
| break; | |
| except (RuntimeError) as e: | |
| print("AP Scan:", e) | |
| print("Connect...", wifi.radio.connect(secrets['ssid'], secrets['password'])) | |
| print("IP ", wifi.radio.ipv4_address) | |
| pool = socketpool.SocketPool(wifi.radio) | |
| ipv4 = ipaddress.ip_address(pool.getaddrinfo(secrets['host'], 443)[0][4][0]) | |
| print("WAN ping: %s %dms" % (ipv4, wifi.radio.ping(ipv4))) | |
| # Requests | |
| requests = adafruit_requests.Session(pool, ssl.create_default_context()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment