def syncButtonEvent(channel): """ Manually syncs the Pi/Resets the wifi """ global syncRiseTime, executor, syncLEDPin if gpio.input(channel): if ((datetime.now() - syncRiseTime).seconds >= 10): # reset the device only if button was pressed for 10 seconds logging.debug('Sync button pressed for long enough to reset wifi') for i in range(3): gpio.output(syncLEDPin, gpio.HIGH) time.sleep(0.2) gpio.output(syncLEDPin, gpio.LOW) time.sleep(0.2) cleanup() time.sleep(5) logging.info('Resetting wifi') reset_lib.reset_to_host_mode() else: logging.debug('Sync button pressed to sync') executor.submit(sync) else: syncRiseTime = datetime.now() #time when button was pressed
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"]) if counter == 5: GPIO.output(LED2, GPIO.HIGH) time.s;eep(1) reset_lib.reset_to_host_mode() if GPIO.input(MONITOR) == 0: counter = 0 break time.sleep(1)
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: counter = 0 break time.sleep(1)
def rdr_reset(): reset_lib.reset_to_host_mode() return "Are you subscribed to pewdiepie? Yes | No"
# If iwconfig report association with an AP add 1 to the # consecutive_active_reports counter and 10 to the no_conn_counter else: consecutive_active_reports += 1 no_conn_counter += 10 # Since wpa_supplicant seems to breifly associate with an AP for # 6-8 seconds to check the network key the below will reset the # no_conn_counter to 0 only if two 10 second checks have come up active. if consecutive_active_reports >= 2: no_conn_counter = 0 consecutive_active_reports = 0 try: if not os.path.isfile('/etc/wpa_supplicant/was_working'): os.system('touch /etc/wpa_supplicant/was_working') except: pass # If the number of seconds not associated with an AP is greater or # equal to the auto_config_delay specified in the /etc/raspiwifi/raspiwifi.conf # trigger a reset into AP Host (Configuration) mode. if no_conn_counter >= int(config_hash['auto_config_delay']): was_working = False if os.path.isfile('/etc/wpa_supplicant/wpa_supplicant.conf') and \ os.path.isfile('/etc/wpa_supplicant/was_working'): was_working = True try: os.system('rm -f /etc/wpa_supplicant/was_working') except: pass reset_lib.reset_to_host_mode(was_working)
import reset_lib reset_lib.reset_to_host_mode(reboot=False)
temp_conf_file.write('wpa-ssid ' + ssid + '\n') temp_conf_file.write('wpa-psk ' + wifi_key + '\n') temp_conf_file.close() os.system('mv interfaces /etc/network/interfaces') def set_ap_client_mode( ): #boot the device in client mode and remove the flag (APMODE) os.system('rm /etc/cron.raspiwifi/aphost_bootstrapper') os.system('mv /etc/dnsmasq.conf.original /etc/dnsmasq.conf') os.system('rm -rf /usr/lib/raspiwifi/APMODE') os.system('reboot') if __name__ == '__main__': if os.path.exists('/usr/lib/raspiwifi/APMODE' ) is True: #check if the file APMODE exists config_hash = reset_lib.config_file_hash() app.run( host='0.0.0.0', port=int(config_hash['server_port']) ) #if the file exists that means that the device is booted in host mode and waiting to be configured else: wifi_conn = reset_lib.is_wifi_active( ) #if the file does not exist that means the device was booted in client mode if wifi_conn == True: #check if the device has internet connection, and if it does, exit sys.exit() else: reset_lib.reset_to_host_mode( ) #if the device does not have internet connection reset it to host mode and reconfigure it