本文整理匯總了Python中network.STAT_CONNECTING屬性的典型用法代碼示例。如果您正苦於以下問題:Python network.STAT_CONNECTING屬性的具體用法?Python network.STAT_CONNECTING怎麽用?Python network.STAT_CONNECTING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類network
的用法示例。
在下文中一共展示了network.STAT_CONNECTING屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_wlan_status
# 需要導入模塊: import network [as 別名]
# 或者: from network import STAT_CONNECTING [as 別名]
def get_wlan_status(self, wlan):
status = wlan.status()
if status == network.STAT_IDLE:
return 'STAT_IDLE'
elif status == network.STAT_CONNECTING:
return 'STAT_CONNECTING'
elif status == network.STAT_WRONG_PASSWORD:
return 'STAT_WRONG_PASSWORD'
elif status == network.STAT_NO_AP_FOUND:
return 'STAT_NO_AP_FOUND'
elif status == network.STAT_CONNECT_FAIL:
return 'STAT_CONNECT_FAIL'
elif status == network.STAT_GOT_IP:
return 'STAT_GOT_IP'
else:
return "Unknown wlan status: {}".format(status)
示例2: _connect
# 需要導入模塊: import network [as 別名]
# 或者: from network import STAT_CONNECTING [as 別名]
def _connect(self, s):
print('Connecting to WiFi')
s.active(True)
s.connect() # ESP8266 remembers connection.
# Break out on fail or success.
while s.status() == network.STAT_CONNECTING:
await asyncio.sleep(1)
t = utime.ticks_ms()
print('Checking WiFi stability for {}ms'.format(2 * self.timeout))
# Timeout ensures stable WiFi and forces minimum outage duration
while s.isconnected() and utime.ticks_diff(utime.ticks_ms(), t) < 2 * self.timeout:
await asyncio.sleep(1)
示例3: manage
# 需要導入模塊: import network [as 別名]
# 或者: from network import STAT_CONNECTING [as 別名]
def manage(cls):
while True:
status = cls.wlan().status()
# ESP32 does not currently return
if (status != network.STAT_GOT_IP) or \
(cls.wlan().ifconfig()[0] == '0.0.0.0'): # temporary till #3967
log.info("Network not connected: managing")
# Ignore connecting status for now.. ESP32 is a bit strange
# if status != network.STAT_CONNECTING: <- do not care yet
cls.setup_network()
await asyncio.sleep(10) # Pause 5 seconds
示例4: wifi_connect
# 需要導入模塊: import network [as 別名]
# 或者: from network import STAT_CONNECTING [as 別名]
def wifi_connect(self):
s = self._sta_if
if ESP8266:
if s.isconnected(): # 1st attempt, already connected.
return
s.active(True)
s.connect() # ESP8266 remembers connection.
for _ in range(60):
if s.status() != network.STAT_CONNECTING: # Break out on fail or success. Check once per sec.
break
await asyncio.sleep(1)
if s.status() == network.STAT_CONNECTING: # might hang forever awaiting dhcp lease renewal or something else
s.disconnect()
await asyncio.sleep(1)
if not s.isconnected() and self._ssid is not None and self._wifi_pw is not None:
s.connect(self._ssid, self._wifi_pw)
while s.status() == network.STAT_CONNECTING: # Break out on fail or success. Check once per sec.
await asyncio.sleep(1)
else:
s.active(True)
s.connect(self._ssid, self._wifi_pw)
if PYBOARD: # Doesn't yet have STAT_CONNECTING constant
while s.status() in (1, 2):
await asyncio.sleep(1)
elif LOBO:
i = 0
while not s.isconnected():
await asyncio.sleep(1)
i += 1
if i >= 10:
break
else:
while s.status() == network.STAT_CONNECTING: # Break out on fail or success. Check once per sec.
await asyncio.sleep(1)
if not s.isconnected():
raise OSError
# Ensure connection stays up for a few secs.
self.dprint('Checking WiFi integrity.')
for _ in range(5):
if not s.isconnected():
raise OSError # in 1st 5 secs
await asyncio.sleep(1)
self.dprint('Got reliable connection')
示例5: wifi_connect
# 需要導入模塊: import network [as 別名]
# 或者: from network import STAT_CONNECTING [as 別名]
def wifi_connect(self):
if LINUX is True: # no network control, assume connected as OS takes care of that
self._sta_isconnected = True
return
s = self._sta_if
if ESP8266:
if s.isconnected(): # 1st attempt, already connected.
return
s.active(True)
s.connect() # ESP8266 remembers connection.
for _ in range(60):
if s.status() != network.STAT_CONNECTING: # Break out on fail or success. Check once per sec.
break
await asyncio.sleep(1)
if s.status() == network.STAT_CONNECTING: # might hang forever awaiting dhcp lease renewal or something else
s.disconnect()
await asyncio.sleep(1)
if not s.isconnected() and self._ssid is not None and self._wifi_pw is not None:
s.connect(self._ssid, self._wifi_pw)
while s.status() == network.STAT_CONNECTING: # Break out on fail or success. Check once per sec.
await asyncio.sleep(1)
else:
s.active(True)
s.connect(self._ssid, self._wifi_pw)
if PYBOARD: # Doesn't yet have STAT_CONNECTING constant
while s.status() in (1, 2):
await asyncio.sleep(1)
elif LOBO:
i = 0
while not s.isconnected():
await asyncio.sleep(1)
i += 1
if i >= 10:
break
else:
while s.status() == network.STAT_CONNECTING: # Break out on fail or success. Check once per sec.
await asyncio.sleep(1)
if not s.isconnected():
raise OSError
# Ensure connection stays up for a few secs.
self.dprint('Checking WiFi integrity.')
for _ in range(5):
if not s.isconnected():
raise OSError # in 1st 5 secs
await asyncio.sleep(1)
self.dprint('Got reliable connection')