本文整理汇总了Python中network.WLAN属性的典型用法代码示例。如果您正苦于以下问题:Python network.WLAN属性的具体用法?Python network.WLAN怎么用?Python network.WLAN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类network
的用法示例。
在下文中一共展示了network.WLAN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wifi_connect
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def wifi_connect(self, essid: str, passphrase: str, **kwargs):
"""
Connect the device WiFi interface to the specified access point.
:param essid: WiFi ESSID.
:param passphrase: WiFi passphrase.
:param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
"""
code = '''
import network
import time
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('{essid}', '{passphrase}')
while not wlan.isconnected():
time.sleep(1)
'''.format(essid=essid, passphrase=passphrase)
self.execute(code, **kwargs)
示例2: _connectCaller
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def _connectCaller(self):
if platform == "esp8266":
import network
ap = network.WLAN(network.AP_IF)
ap.active(False)
while True:
try:
await self.connect()
return
except OSError as e:
_log.error("Error connecting to wifi or mqtt:", e, local_only=True)
# not connected after trying.. not much we can do without a connection except
# trying again.
# Don't like resetting the machine as components could be working without wifi.
await asyncio.sleep(10)
continue
示例3: do_connect
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def do_connect():
sta_if = network.WLAN(network.STA_IF)
start = utime.time()
timed_out = False
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect(config.wifi_config["ssid"], config.wifi_config["password"])
while not sta_if.isconnected() and \
not timed_out:
if utime.time() - start >= 20:
timed_out = True
else:
pass
if sta_if.isconnected():
ntptime.settime()
print('network config:', sta_if.ifconfig())
else:
print('internet not available')
示例4: wifi_connect
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def wifi_connect(essid, password):
# Connect to the wifi. Based on the example in the micropython
# documentation.
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('connecting to network ' + essid + '...')
wlan.connect(essid, password)
# connect() appears to be async - waiting for it to complete
while not wlan.isconnected():
print('waiting for connection...')
utime.sleep(4)
print('checking connection...')
print('Wifi connect successful, network config: %s' % repr(wlan.ifconfig()))
else:
# Note that connection info is stored in non-volatile memory. If
# you are connected to the wrong network, do an explicity disconnect()
# and then reconnect.
print('Wifi already connected, network config: %s' % repr(wlan.ifconfig()))
示例5: download_json
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def download_json(url):
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected() or sta_if.ifconfig()[0] == '0.0.0.0':
raise OtaException('OTA: Network is not ready.')
try:
f = upip.url_open(url)
except:
raise OtaException('Cannot get ota version')
try:
data = upip.json.load(f)
except:
f.close()
raise OtaException('Cannot decode OTA json data')
else:
f.close()
return data
示例6: start_services
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def start_services(state):
if not state: # Wifi disconnected
return
global services_started
if services_started is False:
if sys.platform == "esp32_LoBo":
import pysmartnode.networking.wifi_esp32_lobo
del pysmartnode.networking.wifi_esp32_lobo
del sys.modules["pysmartnode.networking.wifi_esp32_lobo"]
elif sys.platform == "esp32":
import pysmartnode.networking.wifi_esp32
del pysmartnode.networking.wifi_esp32
del sys.modules["pysmartnode.networking.wifi_esp32"]
elif sys.platform == "esp8266":
import pysmartnode.networking.wifi_esp8266
del pysmartnode.networking.wifi_esp8266
del sys.modules["pysmartnode.networking.wifi_esp8266"]
if config.MQTT_RECEIVE_CONFIG:
loop.create_task(_receiveConfig())
services_started = True
if sys.platform != "linux":
import network
s = network.WLAN(network.STA_IF)
print("Connected, local ip {!r}".format(s.ifconfig()[0]))
示例7: getDeviceDiscovery
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def getDeviceDiscovery():
from pysmartnode import config
mf = "espressif" if platform in ("esp8266", "esp32", "esp32_LoBo") else "None"
if platform != "linux":
import network
s = network.WLAN(network.STA_IF)
mac = ',"connections": [["mac", "{!s}"]]'.format(
ubinascii.hexlify(s.config("mac"), ":").decode())
else:
mac = ""
return DISCOVERY_DEVICE_BASE.format(getDeviceID(),
config.VERSION,
mf,
os.uname().sysname if platform != "linux" else "linux",
config.DEVICE_NAME if config.DEVICE_NAME is not None else getDeviceID(),
mac)
示例8: _loop
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def _loop(self):
mqtt = config.getMQTT()
mqtt.registerWifiCallback(self._wifiChanged)
mqtt.registerConnectedCallback(self._reconnected)
await self._flash(500, 1)
sta = network.WLAN(network.STA_IF)
st = time.ticks_ms()
while True:
while self._next:
await self._flash(*self._next.pop(0))
await asyncio.sleep(1)
if time.ticks_diff(time.ticks_ms(), st) > 60000: # heartbeat
st = time.ticks_ms()
if sta.isconnected():
await self._flash(20, 1)
await asyncio.sleep_ms(250)
await self._flash(20, 1)
else:
await self._flash(500, 3)
await asyncio.sleep_ms(500)
示例9: __init__
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def __init__(self, server, port):
# On ESP32 need to submit WiFi credentials
self._sta_if = network.WLAN(network.STA_IF)
self._sta_if.active(True)
# Note that the following blocks, potentially for seconds, owing to DNS lookup
self._addr = socket.getaddrinfo(server, port)[0][-1]
self._sock = socket.socket()
self._sock.setblocking(False)
try:
self._sock.connect(addr)
except OSError as e:
if e.args[0] not in BUSY_ERRORS:
raise
if ESP32: # Revolting kludge :-(
loop = asyncio.get_event_loop()
loop.create_task(self._idle_task())
示例10: get_rssi
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def get_rssi():
global rssi
s = network.WLAN()
ssid = config['ssid'].encode('UTF8')
while True:
try:
rssi = [x[3] for x in s.scan() if x[0] == ssid][0]
except IndexError: # ssid not found.
rssi = -199
await asyncio.sleep(30)
示例11: __init__
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def __init__(self, config):
# MQTT config
self._client_id = config['client_id']
self._user = config['user']
self._pswd = config['password']
self._keepalive = config['keepalive']
if self._keepalive >= 65536:
raise ValueError('invalid keepalive time')
self._response_time = config['response_time'] * 1000 # Repub if no PUBACK received (ms).
self._max_repubs = config['max_repubs']
self._clean_init = config['clean_init'] # clean_session state on first connection
self._clean = config['clean'] # clean_session state on reconnect
will = config['will']
if will is None:
self._lw_topic = False
else:
self._set_last_will(*will)
# WiFi config
self._ssid = config['ssid'] # Required for ESP32 / Pyboard D. Optional ESP8266
self._wifi_pw = config['wifi_pw']
self._ssl = config['ssl']
self._ssl_params = config['ssl_params']
# Callbacks and coros
self._cb = config['subs_cb']
self._wifi_handler = config['wifi_coro']
self._connect_handler = config['connect_coro']
# Network
self.port = config['port']
if self.port == 0:
self.port = 8883 if self._ssl else 1883
self.server = config['server']
if self.server is None:
raise ValueError('no server specified.')
self._sock = None
self._sta_if = network.WLAN(network.STA_IF)
self._sta_if.active(True)
self.newpid = pid_gen()
self.rcv_pids = set() # PUBACK and SUBACK pids awaiting ACK response
self.last_rx = ticks_ms() # Time of last communication from broker
self.lock = asyncio.Lock()
示例12: get
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def get(self, data):
mem = {'mem_alloc': gc.mem_alloc(),
'mem_free': gc.mem_free(),
'mem_total': gc.mem_alloc() + gc.mem_free()}
sta_if = network.WLAN(network.STA_IF)
ifconfig = sta_if.ifconfig()
net = {'ip': ifconfig[0],
'netmask': ifconfig[1],
'gateway': ifconfig[2],
'dns': ifconfig[3]
}
return {'memory': mem, 'network': net}
# RESTAPI: GPIO status
示例13: wifi_disconnect
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def wifi_disconnect():
# Disconnect from the current network. You may have to
# do this explicitly if you switch networks, as the params are stored
# in non-volatile memory.
wlan = network.WLAN(network.STA_IF)
if wlan.isconnected():
print("Disconnecting...")
wlan.disconnect()
else:
print("Wifi not connected.")
示例14: disable_wifi_ap
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def disable_wifi_ap():
# Disable the built-in access point.
wlan = network.WLAN(network.AP_IF)
wlan.active(False)
print('Disabled access point, network status is %s' %
wlan.status())
示例15: start_access_point
# 需要导入模块: import network [as 别名]
# 或者: from network import WLAN [as 别名]
def start_access_point(ssid, password):
access_point = network.WLAN(network.AP_IF)
access_point.active(True)
access_point.config(essid=ssid, password=password, authmode=network.AUTH_WPA_WPA2_PSK)
return access_point
# tries to connect to a wi-fi network
# returns true in case of successful connection, and false otherwise