1
- """
2
- [x] WiFi AP
3
- [x] HTTP server
4
- [x] HTTP handlers
5
- [x] Get own MAC (BSSID)
6
- [ ] OTA update (from app)
7
- [x] WiFi Scanner
8
- [x] WiFi STA
9
- [x] Set hostname
10
- [ ] Static IP support
11
- [ ] Detect auth failure (wrong password?)
12
- [ ] Save/Load config
13
- [ ] Reset button -> Config mode
14
- [ ] Indicator
15
- [ ] Enter config mode on invalid auth
16
- [ ] Report last error
17
-
18
- PolKit configuration (if necessary)
19
- https://askubuntu.com/questions/668411/failed-to-add-activate-connection-32-insufficient-privileges/752168#752168
20
-
21
- Manual wifi config:
22
- https://unix.stackexchange.com/questions/145366/how-to-connect-to-an-802-1x-wireless-network-via-nmcli
23
- """
24
1
25
2
from http .server import BaseHTTPRequestHandler , HTTPServer
26
3
from urllib .parse import urlparse , parse_qsl
30
7
import json
31
8
import binascii
32
9
33
- import os
34
- os .system ('sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 11080' )
35
-
36
10
def log (* args , ** kwargs ):
37
11
print (* args , file = sys .stderr , ** kwargs )
38
12
@@ -121,29 +95,25 @@ def do_GET(self):
121
95
elif o .path == "/wifi_scan.json" :
122
96
self ._reply_json (self .server .wifi_networks )
123
97
elif o .path == "/config" :
124
- q ["auth" ] = q .pop ("blynk" )
98
+ q ["auth" ] = q .pop ("blynk" )
125
99
q ["server" ] = q .pop ("host" )
100
+ q ["port" ] = int (q .pop ("port" ))
101
+ q ["port_ssl" ] = int (q .pop ("port_ssl" ))
126
102
if "save" in q :
127
103
self ._reply_json ({"status" :"ok" ,"msg" :"Configuration saved" })
128
104
else :
129
105
self ._reply_json ({"status" :"ok" ,"msg" :"Trying to connect..." })
130
106
self .server .blynk_config = q
131
- elif o .path == "/reset" :
132
- self ._reply_json ({"status" :"ok" ,"msg" :"Configuration reset" })
133
- self .server .blynk_config = { "cmd" : "reset" }
134
- elif o .path == "/reboot" :
135
- self ._reply_json ({"status" :"ok" })
136
- self .server .blynk_config = { "cmd" : "reboot" }
137
107
else :
138
108
self .send_error (404 )
139
109
140
- def provision (board , tmpl_id , fw_ver ):
110
+ def provision (board , tmpl_id , fw_ver , prefix = "Blynk" ):
141
111
wifi = WiFi ()
142
112
143
113
wifi_networks = wifi .scan ()
144
114
145
115
suffix = format (binascii .crc32 (wifi .mac_address ().encode () * 4 ) & 0xFFFFF , 'X' )
146
- my_ssid = "Blynk " + board + "-" + suffix
116
+ my_ssid = prefix + " " + board + "-" + suffix
147
117
148
118
config = None
149
119
try :
@@ -161,6 +131,8 @@ def provision(board, tmpl_id, fw_ver):
161
131
}
162
132
httpd .wifi_networks = wifi_networks
163
133
httpd .blynk_config = None
134
+
135
+ log ("Waiting for Blynk App connection..." )
164
136
while httpd .blynk_config is None :
165
137
httpd .handle_request ()
166
138
config = httpd .blynk_config
0 commit comments