无法在 CircuitPython 中设置软访问点

huangapple go评论44阅读模式
英文:

Can't set up soft access point in CircuitPython

问题

以下是您要翻译的部分:

import network

ap_ssid = "myAP"
ap_password = "password123"

# create access point interface
ap_if = network.WLAN(network.AP_IF)

# disable default access point
ap_if.active(False)

# configure access point settings
ap_if.active(True)
ap_if.config(essid=ap_ssid, password=ap_password)

# print access point settings
print("Access point created with SSID: {}, password: {}".format(ap_ssid, ap_password))
print("Access point IP address:", ap_if.ifconfig()[0])

请注意,我已将代码中的HTML实体(如")翻译为引号。

英文:

I want to set up a soft access point (a hotspot without an internet connection) on my Raspberry Pi Pico W with a webserver, the reason it needs to also be a soft access point is because I want to take it with me on the road so most of the times there won't be wifi networks around me to join. I need to use CircuitPython instead of MicroPython, it worked on MicroPython and I keep getting errors that I can't import network.

I tried installing newer firmware of CircuitPython on the Pico W from the original site: https://circuitpython.org/board/raspberry_pi_pico_w/ the latest release is CircuitPython 8.0.3 and I also tried installing older versions of CircuitPython, but it just won't work. I also tried importing the wifi module, that worked but it can't create a soft access point.

This is the code that I'm using:

import network

ap_ssid = "myAP"
ap_password = "password123"

# create access point interface
ap_if = network.WLAN(network.AP_IF)

# disable default access point
ap_if.active(False)

# configure access point settings
ap_if.active(True)
ap_if.config(essid=ap_ssid, password=ap_password)

# print access point settings
print("Access point created with SSID: {}, password: {}".format(ap_ssid, ap_password))
print("Access point IP address:", ap_if.ifconfig()[0])

答案1

得分: 1

CircuitPython不使用MicroPython的网络模块,而是使用自己的 wifi模块,它预装在大多数带有WiFi功能的开发板上,包括Raspberry Pi Pico W。

首先,导入模块:

import wifi

然后启动访问点:

wifi.radio.start_ap(ssid=ap_ssid, password=ap_password)

要停止访问点运行:

wifi.radio.stop_ap()

以下是完整的代码:

# 导入wifi模块
import wifi

# 设置访问点凭据
ap_ssid = "myAP"
ap_password = "password123"

# 你可能还需要使用wifi.radio.enabled(true)来启用WiFi无线电

# 配置访问点
wifi.radio.start_ap(ssid=ap_ssid, password=ap_password)

"""
start_ap参数包括:ssid,password,channel,authmode和max_connections
"""

# 打印访问点设置
print("创建的访问点的SSID为:{}, 密码为:{}".format(ap_ssid, ap_password))

# 打印IP地址
print("我的IP地址是", wifi.radio.ipv4_address)

以下是来自文档的start_ap命令的描述:

start_ap(ssid: str | ReadableBuffer, password: str | ReadableBuffer = b'', *, channel: int = 1, authmode: AuthMode | None = None, max_connections: int | None = 4)→ None
使用指定的SSID和密码启动访问点。

如果提供了通道,访问点将使用该通道,除非已经有一个站点在不同的通道上运行。

如果authmode不是None,访问点将使用该认证模式。如果给出了非空密码,authmode不得为OPEN。如果authmode未给出或为None,当密码为空字符串时将使用OPEN,否则authmode将为WPA_WPA2_PSK。

如果提供了max_connections,访问点将允许最多连接到该数量的站点。

获取更多信息,请访问CircuitPython的文档:https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html#wifi.Radio.start_ap

以下是在Raspberry Pi Pico W上使用wifi模块的教程:
https://learn.adafruit.com/pico-w-wifi-with-circuitpython/pico-w-basic-wifi-test

英文:

CircuitPython does not use MicroPython's network module, instead, it uses its own wifi module, which comes preinstalled on most wifi-equipped boards, including the Raspberry Pi Pico W.

First, import the module:

import wifi

Then start the access point:

wifi.radio.start_ap(ssid=ap_ssid, password=ap_password)

To stop the access point run:

wifi.radio.stop_ap()

Here would be your full code:

# import wifi module
import wifi

# set access point credentials
ap_ssid = "myAP"
ap_password = "password123"

# You may also need to enable the wifi radio with wifi.radio.enabled(true)

# configure access point
wifi.radio.start_ap(ssid=ap_ssid, password=ap_password)

"""
start_ap arguments include: ssid, password, channel, authmode, and max_connections
"""

# print access point settings
print("Access point created with SSID: {}, password: {}".format(ap_ssid, ap_password))

# print IP address
print("My IP address is", wifi.radio.ipv4_address)

Here's a description of the start_ap command from the docs:

> start_ap(ssid: str | ReadableBuffer, password: str | ReadableBuffer = b'', *, channel: int = 1, authmode: AuthMode | None = None, max_connections: int | None = 4)→ None
Starts an Access Point with the specified ssid and password.

> If channel is given, the access point will use that channel unless a station is already operating on a different channel.

> If authmode is not None, the access point will use that Authentication mode. If a non-empty password is given, authmode must not be OPEN. If authmode is not given or is None, OPEN will be used when the password is the empty string, otherwise authmode will be WPA_WPA2_PSK.

> If max_connections is given, the access point will allow up to that number of stations to connect.

For more information, head to CircuitPython's documentation: https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html#wifi.Radio.start_ap

Here's a tutorial on using the wifi module with a Raspberry Pi Pico W:
https://learn.adafruit.com/pico-w-wifi-with-circuitpython/pico-w-basic-wifi-test

huangapple
  • 本文由 发表于 2023年2月27日 15:11:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577610.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定