-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
85 lines (75 loc) · 2.12 KB
/
code.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import time
import supervisor
import alarm
import json
import wifi
from adafruit_magtag.magtag import MagTag
from secrets import secrets
#Show additional netwwork information: internet IP and MagTag IP
showMoreNetinfo = True
#show the SSID and Password on display.
showSSID = True
showPass = True
magtag = MagTag()
#Put the WiFi info from secrets into a bytearry to made into a QR code.
wifiqrdata = b"WIFI:T:WPA;S:"+secrets['ssid']+";P:"+secrets['password']+";;"
xPos = 120 #so we can have these all line up nicely and move together for tweaks.
#Title/header
magtag.add_text(
text_font="/fonts/Arial-Bold-12.pcf",
text_position=(xPos, 10),
)
#ssid
magtag.add_text(
text_font="/fonts/Arial-12.bdf",
text_position=(xPos, 30),
)
#password
magtag.add_text(
text_font="/fonts/Arial-12.bdf",
text_position=(xPos, 50),
)
#Internet info header
magtag.add_text(
text_font="/fonts/Arial-Bold-12.pcf",
text_position=(xPos, 70),
)
#internet IP
magtag.add_text(
text_font="/fonts/Arial-12.bdf",
text_position=(xPos, 90),
)
#Device IP:
magtag.add_text(
text_font="/fonts/Arial-12.bdf",
text_position=(xPos, 110),
)
if showMoreNetinfo:
magtag.url='http://ifconfig.co/json'
rawData = json.loads(magtag.fetch(auto_refresh=False))
#QR code and wifi info:
magtag.graphics.qrcode(wifiqrdata, qr_size=4, x=4, y=4)
if showSSID or showPass:
magtag.set_text('Wifi Info:',0,False)
else:
magtag.set_text('<-- Scan to join wifi',0,False)
if showSSID:
magtag.set_text('SSID : ' +secrets['ssid'],1,False)
else:
magtag.set_text('',1,False)
if showPass:
magtag.set_text('Pass : ' + secrets['password'],2,False)
else:
magtag.set_text('',2,False)
#extra network info here.
if showMoreNetinfo:
magtag.set_text('Network info:',3,False)
magtag.set_text('inet IP: '+rawData['ip'],4,False)
magtag.set_text('my IP:' + str(wifi.radio.ipv4_address),5,False)
#Update the display.
magtag.refresh()
time.sleep(2) # let screen update
#wait a long time and update.
#really you should just turn the thing off after runs/updates.
#maybe switch to a button alarm to update?
magtag.exit_and_deep_sleep(1000000)