fix: maixcam wifi连接
This commit is contained in:
+21
-21
@@ -474,10 +474,10 @@ class NetworkManager:
|
|||||||
def select_network(self, prefer_wifi=None):
|
def select_network(self, prefer_wifi=None):
|
||||||
"""
|
"""
|
||||||
自动选择网络(WiFi优先)
|
自动选择网络(WiFi优先)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prefer_wifi: 是否优先使用WiFi(None表示使用默认策略)
|
prefer_wifi: 是否优先使用WiFi(None表示使用默认策略)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"wifi" 或 "4g" 或 None(无可用网络)
|
"wifi" 或 "4g" 或 None(无可用网络)
|
||||||
"""
|
"""
|
||||||
@@ -624,16 +624,16 @@ class NetworkManager:
|
|||||||
password = inner_data.get("password")
|
password = inner_data.get("password")
|
||||||
ota_res_url = inner_data.get("url")
|
ota_res_url = inner_data.get("url")
|
||||||
try:
|
try:
|
||||||
ip, err = self.connect_wifi(ssid, password, persist=False, timeout_s=15, verify_host=None, verify_port=None)
|
w = network.wifi.Wifi()
|
||||||
if err:
|
e = w.connect(ssid, password, wait=True, timeout=15)
|
||||||
raise RuntimeError(err)
|
err.check_raise(e, "connect wifi failed")
|
||||||
if self.logger:
|
if self.logger:
|
||||||
self.logger.info(f"[ota] Connect success, got ip{ip}")
|
self.logger.info(f"[ota] Connect success, got ip{w.get_ip()}")
|
||||||
self.safe_enqueue(
|
self.safe_enqueue(
|
||||||
{
|
{
|
||||||
"cmd": 300,
|
"cmd": 300,
|
||||||
"result": "ota start...",
|
"result": "ota start...",
|
||||||
"wifi": ip,
|
"wifi": w.get_ip(),
|
||||||
},
|
},
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
@@ -643,7 +643,7 @@ class NetworkManager:
|
|||||||
{
|
{
|
||||||
"cmd": 300,
|
"cmd": 300,
|
||||||
"result": "success",
|
"result": "success",
|
||||||
"wifi": ip,
|
"wifi": w.get_ip(),
|
||||||
},
|
},
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
@@ -665,16 +665,16 @@ class NetworkManager:
|
|||||||
ssid = inner_data.get("ssid")
|
ssid = inner_data.get("ssid")
|
||||||
password = inner_data.get("password")
|
password = inner_data.get("password")
|
||||||
try:
|
try:
|
||||||
ip, err = self.connect_wifi(ssid, password, persist=False, timeout_s=15, verify_host=None, verify_port=None)
|
w = network.wifi.Wifi()
|
||||||
if err:
|
e = w.connect(ssid, password, wait=True, timeout=15)
|
||||||
raise RuntimeError(err)
|
err.check_raise(e, "connect wifi failed")
|
||||||
if self.logger:
|
if self.logger:
|
||||||
self.logger.info(f"[conn wifi] Connect success, got ip{ip}")
|
self.logger.info(f"[ota] Connect success, got ip{w.get_ip()}")
|
||||||
self.safe_enqueue(
|
self.safe_enqueue(
|
||||||
{
|
{
|
||||||
"cmd": 600,
|
"cmd": 600,
|
||||||
"result": "success",
|
"result": "success",
|
||||||
"wifi": ip,
|
"wifi": w.get_ip(),
|
||||||
},
|
},
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
@@ -697,7 +697,7 @@ class NetworkManager:
|
|||||||
def connect_server(self):
|
def connect_server(self):
|
||||||
"""
|
"""
|
||||||
连接到服务器(自动选择WiFi或4G)
|
连接到服务器(自动选择WiFi或4G)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: 是否连接成功
|
bool: 是否连接成功
|
||||||
"""
|
"""
|
||||||
@@ -973,11 +973,11 @@ class NetworkManager:
|
|||||||
def tcp_send_raw(self, data: bytes, max_retries=2) -> bool:
|
def tcp_send_raw(self, data: bytes, max_retries=2) -> bool:
|
||||||
"""
|
"""
|
||||||
统一的TCP发送接口(自动选择WiFi或4G)
|
统一的TCP发送接口(自动选择WiFi或4G)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data: 要发送的数据
|
data: 要发送的数据
|
||||||
max_retries: 最大重试次数
|
max_retries: 最大重试次数
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: 是否发送成功
|
bool: 是否发送成功
|
||||||
"""
|
"""
|
||||||
@@ -1148,10 +1148,10 @@ class NetworkManager:
|
|||||||
def receive_tcp_data_via_wifi(self, timeout_ms=100):
|
def receive_tcp_data_via_wifi(self, timeout_ms=100):
|
||||||
"""
|
"""
|
||||||
通过WiFi接收TCP数据
|
通过WiFi接收TCP数据
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
timeout_ms: 超时时间(毫秒)
|
timeout_ms: 超时时间(毫秒)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bytes: 接收到的数据,如果没有数据则返回 b""
|
bytes: 接收到的数据,如果没有数据则返回 b""
|
||||||
"""
|
"""
|
||||||
@@ -1189,7 +1189,7 @@ class NetworkManager:
|
|||||||
def _upload_log_file(self, upload_url, wifi_ssid=None, wifi_password=None, include_rotated=True, max_files=None,
|
def _upload_log_file(self, upload_url, wifi_ssid=None, wifi_password=None, include_rotated=True, max_files=None,
|
||||||
archive_format="tgz"):
|
archive_format="tgz"):
|
||||||
"""上传日志文件到指定URL
|
"""上传日志文件到指定URL
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
upload_url: 上传目标URL,例如 "https://example.com/upload/"
|
upload_url: 上传目标URL,例如 "https://example.com/upload/"
|
||||||
wifi_ssid: WiFi SSID(可选,如果未连接WiFi则尝试连接)
|
wifi_ssid: WiFi SSID(可选,如果未连接WiFi则尝试连接)
|
||||||
@@ -1197,7 +1197,7 @@ class NetworkManager:
|
|||||||
include_rotated: 是否包含轮转日志(app.log.1 等)
|
include_rotated: 是否包含轮转日志(app.log.1 等)
|
||||||
max_files: 最多打包多少个日志文件(包含 app.log 本身),None=按 backupCount 自动推断
|
max_files: 最多打包多少个日志文件(包含 app.log 本身),None=按 backupCount 自动推断
|
||||||
archive_format: 打包格式:tgz 或 zip
|
archive_format: 打包格式:tgz 或 zip
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
该功能仅在 WiFi 连接时可用,4G 网络暂不支持文件上传
|
该功能仅在 WiFi 连接时可用,4G 网络暂不支持文件上传
|
||||||
"""
|
"""
|
||||||
@@ -2148,7 +2148,7 @@ class NetworkManager:
|
|||||||
self.logger.info(f"password: {password}")
|
self.logger.info(f"password: {password}")
|
||||||
ota_manager._start_update_thread()
|
ota_manager._start_update_thread()
|
||||||
self._spawn_cmd_thread(ota_manager.handle_wifi_and_update,
|
self._spawn_cmd_thread(ota_manager.handle_wifi_and_update,
|
||||||
(ssid, password, ota_url))
|
(ssid, password, ota_url))
|
||||||
elif inner_cmd == 6:
|
elif inner_cmd == 6:
|
||||||
try:
|
try:
|
||||||
ip = os.popen(
|
ip = os.popen(
|
||||||
|
|||||||
Reference in New Issue
Block a user