Skip to content

Commit

Permalink
added autoconnect wifi fuction and update system fuction
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninoh-FOX committed Sep 25, 2024
1 parent 79cdc4c commit 37ce50b
Show file tree
Hide file tree
Showing 24 changed files with 2,067 additions and 36 deletions.
70 changes: 69 additions & 1 deletion base/.tmp_update/updater
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,70 @@ else
fi
}

update() {

echo "Checking for updater Pico-FOX package"

if [ -f "${SDCARD_PATH}"/.deletes ]; then
while IFS= read -r file_to_delete; do
rm -rf "${file_to_delete}"
done < "${SDCARD_PATH}"/.deletes
rm "${SDCARD_PATH}"/.deletes
fi

if [ -f "${SDCARD_PATH}/"update_pico-fox_*.zip ]; then

echo "update Pico-FOX package found"

for file in `ls "${SDCARD_PATH}"/update_pico-fox_*.zip`; do
unzip -q -o "${file}" ".update_splash.png" -d "${SDCARD_PATH}"
sync

show "${SDCARD_PATH}"/.update_splash.png

unzip -q -o "${file}" ".deletes" -d "${SDCARD_PATH}"

if [ -f "${SDCARD_PATH}"/.deletes ]; then
while IFS= read -r file_to_delete; do
if [ -f "${file_to_delete}" ]; then
rm "${file_to_delete}"
elif [ -d "${file_to_delete}" ]; then
rm -rf "${file_to_delete}"
fi
done < "${SDCARD_PATH}"/.deletes
fi

unzip -q -o "${file}" -d "${SDCARD_PATH}"

rm "${file}"

if [ -f "${SDCARD_PATH}"/.deletes ]; then
rm "${SDCARD_PATH}"/.deletes
fi

if [ -f "${SDCARD_PATH}"/.update_splash.png ]; then
rm "${SDCARD_PATH}"/.update_splash.png
fi

sleep 5s
done

sync
sleep 5s

if [ "$MODEL" == "MMP" ]; then
poweroff
else
reboot
fi

sleep 10s
fi

echo "update Pico-FOX package not found"

}

killprocess() {
pid=`ps | grep $1 | grep -v grep | cut -d' ' -f3`
kill -9 $pid
Expand Down Expand Up @@ -218,6 +282,9 @@ resize
# Charging screen
"${SYSTEM_PATH}"/bin/charging

# Update opportunity
update

# check swap size
if [ -f "${SWAPFILE}" ]; then
SWAPSIZE=`stat -c %s "${SWAPFILE}"`
Expand Down Expand Up @@ -420,7 +487,8 @@ while [ 1 ]; do
fi

if ls "$BBS"* 1> /dev/null 2>&1; then
cp "$BBS"* "$SPLORE"
rm "$BBS"temp-*
cp "$BBS"*.p8.png "$SPLORE"
else
echo "No BBS files found to copy."
fi
Expand Down
1 change: 1 addition & 0 deletions base/App/Wifi/autoconnect_state.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
autoconnect_enabled=False
144 changes: 114 additions & 30 deletions base/App/Wifi/wifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
netconfdir = confdir+"networks/"
sysconfdir = "/appconfigs/"
datadir = "/mnt/SDCARD/App/Wifi/data/"
autoconnect_enabled = False

surface = pygame.display.set_mode((320,240))
selected_key = ''
Expand Down Expand Up @@ -144,6 +145,30 @@ def enableiface(iface):
mac_addresses[iface] = getmac(iface)
return True

def autoconnect(iface):
check = checkinterfacestatus(iface)
if check:
return False

modal("Autoconnecting...")
drawinterfacestatus()
pygame.display.update()

SU.Popen(['/bin/sed', '-i', "s/\"wifi\":\s*[01]/\"wifi\": 1/", '/appconfigs/system.json'], close_fds=True).wait()
SU.Popen(['/customer/app/axp_test', 'wifion'], close_fds=True).wait()
SU.Popen(['sleep', '2'], close_fds=True).wait()
SU.Popen(['pkill', '-9', 'wpa_supplicant'], close_fds=True).wait()
SU.Popen(['pkill', '-9', 'udhcpc'], close_fds=True).wait()
SU.Popen(['pkill', '-9', 'hostapd'], close_fds=True).wait()
SU.Popen(['pkill', '-9', 'dnsmasq'], close_fds=True).wait()
while True:
if SU.Popen(['/sbin/ifconfig', iface, 'up'], close_fds=True).wait() == 0:
break
time.sleep(0.1);
SU.Popen(['/mnt/SDCARD/Koriki/bin/wpa_supplicant', '-B', '-D', 'nl80211', '-i', iface, '-c', '/appconfigs/wpa_supplicant.conf'], close_fds=True).wait()
mac_addresses[iface] = getmac(iface)
return True

def disableiface(iface):
SU.Popen(['pkill', '-9', 'wpa_supplicant'], close_fds=True).wait()
SU.Popen(['pkill', '-9', 'udhcpc'], close_fds=True).wait()
Expand Down Expand Up @@ -455,33 +480,38 @@ def drawstatusbar(): # Set up the status bar
wlan_text.topleft = (2, 225)
surface.blit(wlantext, wlan_text)

def drawinterfacestatus(): # Interface status badge
global colors
wlanstatus = checkinterfacestatus(wlan)
if not wlanstatus:
wlanstatus = wlan+" is off."
else:
wlanstatus = getcurrentssid(wlan)

wlantext = font_mono_small.render(wlanstatus, True, colors['white'], colors['lightbg'])
wlan_text = wlantext.get_rect()
wlan_text.topleft = (2, 225)
surface.blit(wlantext, wlan_text)

# Note that the leading space here is intentional, to more cleanly overdraw any overly-long
# strings written to the screen beneath it (i.e. a very long ESSID)
if checkinterfacestatus(wlan):
text = font_mono_small.render(" "+getip(wlan), True, colors['white'], colors['lightbg'])
interfacestatus_text = text.get_rect()
interfacestatus_text.topright = (317, 225)
surface.blit(text, interfacestatus_text)
else:
mac = mac_addresses.get(wlan) # grabbed by enableiface()
if mac is not None:
text = font_mono_small.render(" "+mac, True, colors['white'], colors['lightbg'])
interfacestatus_text = text.get_rect()
interfacestatus_text.topright = (317, 225)
surface.blit(text, interfacestatus_text)
def drawinterfacestatus(): # Interface status badge
global colors
wlanstatus = checkinterfacestatus(wlan)
if not wlanstatus:
wlanstatus = wlan+" is off."
else:
wlanstatus = getcurrentssid(wlan)

wlantext = font_mono_small.render(wlanstatus, True, colors['white'], colors['lightbg'])
wlan_text = wlantext.get_rect()
wlan_text.topleft = (2, 225)
surface.blit(wlantext, wlan_text)

# Note that the leading space here is intentional, to more cleanly overdraw any overly-long
# strings written to the screen beneath it (i.e. a very long ESSID)
if checkinterfacestatus(wlan):
ip_address = getip(wlan)
if ip_address is None: # Handle case where no IP is assigned
ip_address = " " # Display alternative message if no IP is available
text = font_mono_small.render(" " + ip_address, True, colors['white'], colors['lightbg'])
interfacestatus_text = text.get_rect()
interfacestatus_text.topright = (317, 225)
surface.blit(text, interfacestatus_text)
else:
mac = mac_addresses.get(wlan) # grabbed by enableiface()
if mac is not None:
text = font_mono_small.render(" " + mac, True, colors['white'], colors['lightbg'])
else:
text = font_mono_small.render(" ", True, colors['white'], colors['lightbg']) # Handle no MAC case
interfacestatus_text = text.get_rect()
interfacestatus_text.topright = (317, 225)
surface.blit(text, interfacestatus_text)

def redraw():
global colors
Expand Down Expand Up @@ -596,6 +626,44 @@ def writeconfig(): # Write wireless configuration to disk
f2.write('}\n')
f2.close()

def save_autoconnect_state():
config_file = "/mnt/SDCARD/App/Wifi/autoconnect_state.txt"
with open(config_file, 'w') as f:
f.write("autoconnect_enabled={}\n".format(autoconnect_enabled))

def load_autoconnect_state():
global autoconnect_enabled
config_file = "/mnt/SDCARD/App/Wifi/autoconnect_state.txt"
if os.path.exists(config_file):
with open(config_file, 'r') as f:
for line in f:
key, value = line.strip().split("=")
if key == "autoconnect_enabled":
autoconnect_enabled = value == "True"

def toggle_autoconnect():
global autoconnect_enabled
if autoconnect_enabled:
confirm = modal("Disable Autoconnect?", query=True)
if confirm:
autoconnect_enabled = False
modal("Autoconnect is OFF", wait=True)
redraw()
else:
active_menu = to_menu("main")
redraw()
else:
confirm = modal("Enable Autoconnect?", query=True)
if confirm:
autoconnect_enabled = True
modal("Autoconnect is ON", wait=True)
redraw()
else:
active_menu = to_menu("main")
redraw()

save_autoconnect_state()

## HostAP
def startap():
global wlan
Expand Down Expand Up @@ -1320,11 +1388,11 @@ def mainmenu():
if mac == ap:
elems = ['AP info'] + elems
except:
elems = ['Create ADHOC'] + elems
pass

elems = ["Saved Networks", 'Scan for APs', "Manual Setup"] + elems
elems = ["Saved Networks", 'Scan for APs', "Manual Setup", 'Autoconnect'] + elems

if checkinterfacestatus(wlan):
if checkinterfacestatus(wlan) and getcurrentssid(wlan) is not None:
elems = ['Disconnect'] + elems

menu.init(elems, surface)
Expand Down Expand Up @@ -1478,6 +1546,19 @@ def convert_file_names():
logoBar = LogoBar()

redraw()

load_autoconnect_state()

if autoconnect_enabled:
modal("Autoconnecting...")
autoconnect(wlan)
if not udhcpc_timeout(wlan, 30):
modal('Autoconnect failed!', wait=True)
else:
modal('Autoconnect successful!')
time.sleep(2)
sys.exit()

while True:
time.sleep(0.01)
for event in pygame.event.get():
Expand Down Expand Up @@ -1648,6 +1729,9 @@ def convert_file_names():

elif menu.get_selected() == 'Create ADHOC':
startap()

elif menu.get_selected() == 'Autoconnect':
toggle_autoconnect()

elif menu.get_selected() == 'AP info':
apinfo()
Expand Down
6 changes: 3 additions & 3 deletions base/App/pico/.lexaloffle/pico-8/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

// :: Video Settings

window_size 640 480 // window width, height
screen_size 640 480 // screen width, height (stretched to window)
window_size 320 240 // window width, height
screen_size 320 240 // screen width, height (stretched to window)
show_fps 0 // Draw frames per second in the corner


Expand All @@ -30,7 +30,7 @@ foreground_sleep_ms 1 // number of milliseconds to sleep each frame. Try 10 to c

background_sleep_ms 10 // number of milliseconds to sleep each frame when running in the background

sessions 19 // number of times program has been run
sessions 59 // number of times program has been run

// (scancode) hold this key down and left-click to simulate right-click
rmb_key 0 // 0 for none 226 for LALT
Expand Down
2 changes: 1 addition & 1 deletion base/Koriki/bin/pico.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ set_snd_level "${volume}" &

echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

pico8_dyn -splore -width 640 -height 480 -root_path "/mnt/SDCARD/Roms/PICO/"
pico8_dyn -splore -width 320 -height 240 -root_path "/mnt/SDCARD/Roms/PICO/"

sync

Expand Down
2 changes: 1 addition & 1 deletion base/Koriki/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.3
1.5.4
1 change: 1 addition & 0 deletions src/Wifi/autoconnect_state.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
autoconnect_enabled=False
Binary file added src/Wifi/data/Inconsolata.otf
Binary file not shown.
Binary file added src/Wifi/data/closed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Wifi/data/gcwzero.ttf
Binary file not shown.
Binary file added src/Wifi/data/open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Wifi/data/transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Wifi/data/unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Wifi/data/wifi-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Wifi/data/wifi-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Wifi/data/wifi-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Wifi/data/wifi-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Wifi/data/wifi-connecting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/Wifi/dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface=wlan0
dhcp-range=192.168.4.101,192.168.4.120,255.255.255.0,12h
dhcp-option=3,192.168.4.100
dhcp-leasefile=/appconfigs/dhcp.leases
no-resolv
user=root
15 changes: 15 additions & 0 deletions src/Wifi/hostapd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
interface=wlan0
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
driver=nl80211
ssid=MiyooMini
channel=4
hw_mode=g
macaddr_acl=0
ignore_broadcast_ssid=0
auth_algs=1
wpa=3
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
2 changes: 2 additions & 0 deletions src/Wifi/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
127.0.0.1 localhost
127.0.1.1 Miyoomini
Empty file.
2 changes: 2 additions & 0 deletions src/Wifi/udhcpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
interface wlan0
nohook wpa_supplicant
Loading

0 comments on commit 37ce50b

Please sign in to comment.