Example #1
0
LED1=24
LED2=25
GPIO.setmode(GPIO.BCM)
GPIO.setup(MONITOR, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(LED1, GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(LED2, GPIO.OUT, initial=GPIO.LOW)

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:
    while GPIO.input(MONITOR) == 1:
        time.sleep(1)
        counter = counter + 1

        print(counter)
		
		if counter ==9:
			GPIO.output(LED1, GPIO.HIGH)
			time.sleep(2)
			subprocess.call(["shutdown", "-h", "now"])
Example #2
0
import RPi.GPIO as GPIO
import os
import time
import subprocess
import reset_lib

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

counter = 0
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)
    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:
    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:
Example #3
0
import time
import subprocess
import reset_lib

GPIO.setmode(GPIO.BCM)
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:
    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:
Example #4
0
                pass
            else:
                ap_ssid = line[27:-1]
                if ap_ssid != '':  #save every ESSID that is not an empty string
                    ap_array.append(ap_ssid)

    return ap_array


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:  #check if the APname of the hostapd and the APname of the raspiwifi.conf are the same
    reset_lib.update_hostapd(
        ssid_prefix
    )  #if not, overwrite hostapd to have the same name and reboot the device
    #os.system('reboot')
    os.system('systemctl restart networking.service')

os.system(
    'iwconfig wlan0 mode Managed'
)  #put the wlan0 interface in Managed mode so that is able to scan wifi networks
wifi_ap_array = scan_wifi_networks(
)  #save the output of the scan_wifi_networks as a list
os.system('/etc/init.d/hostapd restart'
          )  #restart the hostapd service so that the AP will be shown


@app.route('/setup')
def login():