def stay_connected(self): """ """ # Prepare information about known WiFi networks. networks_known = self.get_configured_stations() # Attempt to connect to known/configured networks. attempt = 0 while self.is_running: delay = 1 if self.is_connected(): attempt = 0 else: log.info("WiFi STA: Connecting to configured networks: %s. " "Attempt: #%s", list(networks_known), attempt + 1) try: self.connect_stations(networks_known) except KeyboardInterrupt: raise except Exception as ex: log.exc(ex, 'WiFi STA: Connecting to configured networks "{}" failed'.format(list(networks_known))) delay = backoff_time(attempt, minimum=1, maximum=600) log.info('WiFi STA: Retrying in {} seconds'.format(delay)) attempt += 1 machine.idle() time.sleep(delay)
def stay_connected(self): # Prepare information about known WiFi networks. networks_known = frozenset( [station['ssid'] for station in self.stations]) # Attempt to connect to known/configured networks. attempt = 0 while True: delay = 1 if self.is_connected(): attempt = 0 else: log.info( "WiFi STA: Connecting to configured networks: %s. Attempt: #%s", list(networks_known), attempt + 1) try: self.connect_stations(networks_known) except Exception as ex: log.exc( ex, 'WiFi STA: Connecting to configured networks "{}" failed' .format(list(networks_known))) delay = backoff_time(attempt, minimum=1, maximum=600) log.info('WiFi STA: Retrying in {} seconds'.format(delay)) attempt += 1 machine.idle() time.sleep(delay)
def start_real(self): """ https://docs.pycom.io/tutorials/all/wlan.html https://github.com/pycom/pydocs/blob/master/firmwareapi/pycom/network/wlan.md """ #if machine.reset_cause() == machine.SOFT_RESET: # print("WiFi STA: Network connection after SOFT_RESET.") # self.print_short_status() # # Inform about networking status. # self.print_address_status() # return True # Save the default ssid and auth for restoring AP mode later #original_ssid = self.station.ssid() #original_auth = self.station.auth() # Inform about networking status. self.print_address_status() # Setup network interface. log.info("WiFi STA+AP: Starting interface") self.station.mode(WLAN.STA_AP) self.station.init() # Check WiFi connectivity. if self.is_connected(): log.info( "WiFi STA: Network connection already established, will skip scanning and resume connectivity." ) self.print_short_status() # Give system some breath. time.sleep(0.25) # Inform about networking status. self.print_short_status() self.print_address_status() return True # Prepare information about known WiFi networks. networks_known = frozenset( [station['ssid'] for station in self.stations]) # Attempt to connect to known/configured networks. attempt = 0 while True: delay = 1 if self.is_connected(): attempt = 0 else: log.info( "WiFi STA: Connecting to configured networks: %s. Attempt: #%s", list(networks_known), attempt + 1) try: self.connect_stations(networks_known) except: log.exception( 'WiFi STA: Connecting to configured networks "{}" failed' .format(list(networks_known))) delay = backoff_time(attempt, minimum=1, maximum=600) log.info('WiFi STA: Retrying in {} seconds'.format(delay)) attempt += 1 machine.idle() time.sleep(delay) # Todo: Reenable WiFi AP mode in the context of an "initial configuration" mode. """