Last active
July 3, 2021 03:02
-
-
Save Neradoc/469fe2918083c2a4bc3d584e481079c2 to your computer and use it in GitHub Desktop.
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
import wifi | |
import socketpool | |
import ssl | |
import secrets | |
import sys | |
SSL = False | |
try: | |
from secrets import secrets | |
except ImportError: | |
print("WiFi secrets are kept in secrets.py, please add them there!") | |
sys.exit() | |
print("CONNECT WIFI") | |
wifi.radio.connect(secrets['ssid'],secrets['password']) | |
pool = socketpool.SocketPool(wifi.radio) | |
ssl_context = ssl.create_default_context() | |
hostname = "echo.websocket.org" | |
if SSL: | |
port = 443 | |
else: | |
port = 80 | |
addr_info = pool.getaddrinfo( | |
hostname, port, 0, pool.SOCK_STREAM | |
)[0] | |
sock = pool.socket( | |
addr_info[0], addr_info[1], addr_info[2] | |
) | |
connect_host = addr_info[-1][0] | |
if SSL: | |
sock = ssl_context.wrap_socket(sock,server_hostname = hostname) | |
connect_host = hostname | |
r = sock.connect((connect_host,port)) | |
print("FIN") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment