-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWiFi.py
38 lines (29 loc) · 852 Bytes
/
WiFi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import network
import urequests
import time
import binascii
SSID = 'ASK4 Wireless'
PASS = ''
TEST_SITE = 'https://jsonplaceholder.typicode.com/todos/1'
def connect():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('connecting to network...')
wlan.connect(SSID, PASS)
while not wlan.isconnected():
pass
print('network config:', wlan.ifconfig())
line = binascii.hexlify(wlan.config('mac')).decode('utf-8')
# Get MAC
l = [line[i:i+2] for i in range(0, len(line), 2)]
# Convert into 6 hex digits
mac=""
for i,value in enumerate(l):
mac += value
if i+1 < len(l):
mac +=":"
print('Device MAC:', mac)
def testConnectivity():
r = urequests.get(url=TEST_SITE)
print(r.json()['id'])