Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to enter connection details manually #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions enviro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def connect_to_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(wifi_ssid, wifi_password)
if config.wifi_ifconfig is not None:
logging.info(f"> using manual ip config {config.wifi_ifconfig}")
wlan.ifconfig(config.wifi_ifconfig)

start = time.ticks_ms()
while time.ticks_diff(time.ticks_ms(), start) < 30000:
Expand Down
1 change: 1 addition & 0 deletions enviro/config_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# network access details
wifi_ssid = None
wifi_password = None
wifi_ifconfig = None

# how often to wake up and take a reading (in minutes)
reading_frequency = 15
Expand Down
6 changes: 6 additions & 0 deletions enviro/html/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@

#done pre {max-height: 20rem; overflow: scroll; background-color: var(--black); border-radius: var(--input-radius); color: white; padding: 1rem;}

details {user-select: none;}
details>summary span.icon {transition: all 0.5s; margin-left: auto;}
details[open] summary span.icon { transform: rotate(90deg); }
summary {display: flex; cursor: pointer; }
summary::-webkit-details-marker {display: none;}

/* adjustments for viewing on phone rather than tablet or computer */
@media (max-width: 680px) {
#intro {grid-template-columns: 1fr;}
Expand Down
26 changes: 26 additions & 0 deletions enviro/html/provision-step-2-wifi.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@ <h2>Enter your WiFi password so that we can <s>download pictures of cats</s> upl
<fieldset>
<input id="wifi_password" name="wifi_password" type="text" value="{{config.wifi_password}}" placeholder="e.g. Cats4lyfe&lt;3!" autocapitalize="none" autocorrect="off" autocomplete="off" spellcheck="false" />
</fieldset>

<details>
<summary><h2>Advanced configuration</h2>
<span class="icon">➔</span>
</summary>
<p>
<aside>Only fill in the following fields if you know what you're doing. Leaving them empty works best in most cases, and they are generally only required if your Wifi network does not have a DHCP service running.</aside>
<aside>MAC address: {{mac_address}}</aside>
<h2>IPv4 address:</h2>
<fieldset>
<input id="ipv4_address" name="ipv4_address" type="text" value="{{config.wifi_ifconfig[0]}}" placeholder="e.g. 192.168.0.42" autocapitalize="none" autocorrect="off" autocomplete="off" spellcheck="false" />
</fieldset>
<h2>Netmask:</h2>
<fieldset>
<input id="ipv4_netmask" name="ipv4_netmask" type="text" value="{{config.wifi_ifconfig[1]}}" placeholder="e.g. 255.255.255.0" autocapitalize="none" autocorrect="off" autocomplete="off" spellcheck="false" />
</fieldset>
<h2>Gateway:</h2>
<fieldset>
<input id="ipv4_gateway" name="ipv4_gateway" type="text" value="{{config.wifi_ifconfig[2]}}" placeholder="e.g. 255.255.255.1" autocapitalize="none" autocorrect="off" autocomplete="off" spellcheck="false" />
</fieldset>
<h2>DNS server:</h2>
<fieldset>
<input id="dns_server" name="dns_server" type="text" value="{{config.wifi_ifconfig[3]}}" placeholder="e.g. 8.8.8.8" autocapitalize="none" autocorrect="off" autocomplete="off" spellcheck="false" />
</fieldset>
</p>
</details>
</form>

<nav>
Expand Down
15 changes: 14 additions & 1 deletion enviro/provisioning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import network, os, json, time, machine, sys
import network, os, json, time, machine, sys, ubinascii

import enviro.helpers as helpers
import enviro
Expand Down Expand Up @@ -42,6 +42,8 @@ def write_config():
# put board into access point mode
logging.info("> going into access point mode")
ap = access_point(f"Enviro {model[:1].upper()}{model[1:]} Setup")
wlan = network.WLAN(network.AP_IF)
mac_address = ubinascii.hexlify(wlan.config('mac'), ":").decode().upper()
logging.info(" -", ap.ifconfig()[0])


Expand Down Expand Up @@ -82,6 +84,17 @@ def provision_step_2_wifi(request):
if request.method == "POST":
config.wifi_ssid = request.form["wifi_ssid"]
config.wifi_password = request.form["wifi_password"]
ipv4 = request.form["ipv4_address"]
if "." in ipv4: # Something was entered. Save manual config
wifi_ifconfig = [
ipv4,
request.form["ipv4_netmask"],
request.form["ipv4_gateway"],
request.form["dns_server"],
]
config.wifi_ifconfig = tuple(wifi_ifconfig)
else:
config.wifi_ifconfig = None
write_config()
return redirect(f"http://{DOMAIN}/provision-step-3-logging")
else:
Expand Down
4 changes: 2 additions & 2 deletions install-on-device-fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function create_directory {
function copy {
for file in $1
do
echo -n "> copying file $file"
mpremote connect ${DEVICE} cp $file $2 > /dev/null
echo "> copying file $file"
mpremote connect ${DEVICE} cp $file $2$(basename $file)
if [ $? -eq 0 ] ; then
echo " .. done!"
else
Expand Down