-
Notifications
You must be signed in to change notification settings - Fork 0
/
raspiwifi_reset.py
56 lines (42 loc) · 1.41 KB
/
raspiwifi_reset.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
"""
file version change to check for a specific flag file rather than a GPIO state
copy to RaspiWifi directory: /usr/lib/raspiwifi/reset_device/reset.py
"""
flagpath = "/home/pi/Refiller/wifi_conf_flag"
# original: import RPi.GPIO as GPIO
import os
import time
import subprocess
import reset_lib
# original: GPIO.setmode(GPIO.BCM)
# original: GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
counter = 0
serial_last_four = subprocess.check_output(['cat', '/proc/cpuinfo'])[-5:-1].decode('utf-8')
config_hash = reset_lib.config_file_hash()
ssid_prefix = config_hash['ssid_prefix'] + " "
hostapd_reset_required = reset_lib.hostapd_reset_check(ssid_prefix)
if hostapd_reset_required == True:
reset_lib.update_hostapd(ssid_prefix, serial_last_four)
os.system('reboot')
# This is the main logic loop waiting for a button to be pressed on GPIO 18 for 10 seconds.
# If that happens the device will reset to its AP Host mode allowing for reconfiguration on a new network.
while True:
try:
os.remove()
reset_lib.reset_to_host_mode(flagpath)
except FileNotFoundError:
continue
time.sleep(2)
"""
#original:
while GPIO.input(18) == 1:
time.sleep(1)
counter = counter + 1
print(counter)
if counter == 9:
reset_lib.reset_to_host_mode()
if GPIO.input(18) == 0:
counter = 0
break
time.sleep(1)
"""