This module is used to initialize various network card drivers. The network card has these function: connecting routes, disconnecting routes, viewing network card connection information, checking whether connections are made.
Please make sure the antenna is connected before using WiFi.
Some development boards expose an
AT network interface module, such as an
esp8285 interface connected to the
k210 processor via a serial port.
8 is the enable pin. Instantiate a
GPIO object set it high to enable, low to disable. To reset, set it low, wait a short while, then set it high.
Sample code [wifi_ap_scan.py] (https://github.com/sipeed/MaixPy_scripts/blob/master/network/demo_wifi_ap_scan.py)
There is currently a
esp32 module in the
MaixDuino development board connected to
There is also a separate
TF plug-in module.
ESP8285 NIC object, passing in an
uart object. On the
GO currently supported by
MaixPy, use the AT command module as
WiFi. So the
uart object is the object that communicates with the
AT module, you can view the
uart module routine.
Calling this method will initialize
ESP8285, throwing an exception if it fails.
uart: UART object that communicates with the AT module
ESP8285: NIC object
Connect to a hotspot (AP/router).
key: password for hotspot
None. An exception will be thrown if an error occurs.
Display the current WiFi connection information. Currently, the network does not support setting the network card configuration.
tuple type, the elements are all strings:
(ip, netmask, gateway, dns_server, dhcp_server, mac, ssid), if not queried or invalid, the value is `"0".
Check if WiFi is connected.
True: Already connected
Scan for surrounding WiFi hotspots.
list object, each element containing a string, the string comes from the response of the
AT module, the content is the same as described in
AT directive document, as follows:
'<ecn>,<ssid>,<rssi>,<mac>,<channel>,<freq offset>,<freq cali>,<pairwise_cipher>, <group_cipher>,<bgn>,<wps>'
<ecn>: encryption method
- 0: OPEN
- 1: WEP
- 2: WPA_PSK
- 3: WPA2_PSK
- 4: WPA_WPA2_PSK
- 5: WPA2_Enterprise (current AT does not support connection to this encrypted AP)
<ssid>: string parameter, SSID of AP
<rssi>: signal strength
<mac>: string parameter, AP's MAC address
<channel>: channel number
<freq offset>: AP frequency offset, unit: kHz. This value is divided by 2.4 to get the ppm value.
<freq cali>: frequency offset calibration value
- 0: CIPHER_NONE
- 1: CIPHER_WEP40
- 2: CIPHER_WEP104
- 3: CIPHER_TKIP
- 4: CIPHER_CCMP
- 5: CIPHER_TKIP_CCMP
- 6: CIPHER_UNKNOWN
<group_cipher>: definition is the same as
<bgn>: bit0 stands for b mode; bit1 stands for g mode; bit2 stands for n mode
If the corresponding bit is 1, it indicates that the mode is enabled; if the corresponding bit is 0, the mode is not enabled.
<wps>:0, WPS is not enabled; 1, WPS is enabled
info_strs = ['4,"ChinaNet-lot0",-79,"c8:50:e9:e8:21:3e",1,-42,0,4,3,7,1', '4,"TOPSTEP2G4",-7 0,"f8:e7:1e:0d:0d:f8",1,-57,0,4,4,7,0']
This may seem strange, because each AP's information is a string of characters, there are integers and strings in the message, the string is enclosed in double quotes, so you need to deal with it again after getting this string, for example:
def wifi_deal_ap_info(info): res =  for ap_str in info: ap_str = ap_str.split(",") info_one =  for node in ap_str: if node.startswith('"'): info_one.append(node[1:-1]) else: info_one.append(int(node)) res.append(info_one) return res info_strs = ['4,"ChinaNet-lot0",-79,"c8:50:e9:e8:21:3e",1,-42,0,4,3,7,1', '4,"TOPSTEP2G4",-70,"f8:e7:1e:0d:0d:f8",1,-57,0,4,4,7,0'] info = wifi_deal_ap_info(info_strs) print(info)
The output is:
[[4, 'ChinaNet-lot0', -79, 'c8:50:e9:e8:21:3e', 1, -42, 0, 4, 3, 7, 1], [4, 'TOPSTEP2G4', -70, 'f8:e7:1e:0d:0d:f8', 1, -57, 0, 4, 4, 7, 0]]
Then for example to get every
for ap_info in info: print(ap_info)
Connect to the specified WiFi hotspot.
chl: channel number of the WiFi signal
ecn: encryption method, there are
OPEN``WPA2_PSK, etc., refer to the constant part of this page
ESP8285, the default value is
3, which is
ESP8285.WPA2_PSK, for example
Nic = network.ESP8285(uart) Nic.enable_ap("maixpy", "12345678", 5, nic.OPEN)
Nic.enable_ap("maixpy", "12345678", 5, network.ESP8285.OPEN)
Disconnect from the currently connected WiFi hotspot.
No encryption and no password required.
Refer to [code in the network directory] (https://github.com/sipeed/MaixPy_scripts/tree/master/network)
To instantiate an
ESP32_SPI NIC object, you need to pass in the corresponding
If the number of parameters passed in is incorrect, an error will be returned.
fpioa_funcfor pin function
adc value of the
adc value of 5 channels is
"PIN36", "PIN39", "PIN34", "PIN35", "PIN32"