Skip to content

Commit

Permalink
Make ftp_serv.py autoconnect to wifi with settings.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
bill88t committed Feb 6, 2024
1 parent 5536ae0 commit 17c46c3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions extra/netutils/ftp_serv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@
from supervisor import reload

if not wifi.radio.connected:
print("No wifi")
print("No wifi. Trying to connect via settings.toml")

from cptoml import keys, fetch

stored_networks = keys("IWD")
available_networks = []
for i in wifi.radio.start_scanning_networks():
available_networks.append(i.ssid)
wifi.radio.stop_scanning_networks()
for i in stored_networks:
if i in available_networks:
try:
wifi.radio.connect(i, fetch(i, "IWD"))
if wifi.radio.connected:
print("Successfully connected to " + i)
break
except:
pass

if not wifi.radio.connected:
print("Could not connect to wifi!")
reload()

pool = SocketPool(wifi.radio)
ftps = ftp(pool, str(wifi.radio.ipv4_address))
ftps = ftp(pool, str(wifi.radio.ipv4_address), verbose=True)
print("Starting Ljinux ftp server..")
try:
ftps.serve_till_quit()
Expand Down

0 comments on commit 17c46c3

Please sign in to comment.