Compare commits
9
Commits
5ab4ef2944
...
linyimin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0df9ad915 | ||
|
|
3fcd38f417 | ||
|
|
abbf30d7c0 | ||
|
|
5cf752bb3f | ||
|
|
6d8de56bfa | ||
|
|
aee1a92760 | ||
|
|
c34efed6f9 | ||
|
|
226394d3ed | ||
|
|
b169618b16 |
@@ -1,6 +1,6 @@
|
|||||||
id: t11
|
id: t11
|
||||||
name: t11
|
name: t11
|
||||||
version: 2.15.14
|
version: 2.15.18
|
||||||
author: t11
|
author: t11
|
||||||
icon: ''
|
icon: ''
|
||||||
desc: t11
|
desc: t11
|
||||||
@@ -18,8 +18,6 @@ files:
|
|||||||
- laser_manager.py
|
- laser_manager.py
|
||||||
- logger_manager.py
|
- logger_manager.py
|
||||||
- main.py
|
- main.py
|
||||||
- model_270139.cvimodel
|
|
||||||
- model_270139.mud
|
|
||||||
- network.py
|
- network.py
|
||||||
- ota_curl.sh
|
- ota_curl.sh
|
||||||
- ota_manager.py
|
- ota_manager.py
|
||||||
|
|||||||
+7
-6
@@ -76,10 +76,11 @@ class ATClient:
|
|||||||
"""
|
"""
|
||||||
expect_b = expect.encode() if isinstance(expect, str) else expect
|
expect_b = expect.encode() if isinstance(expect, str) else expect
|
||||||
with self._cmd_lock:
|
with self._cmd_lock:
|
||||||
# 初始化等待
|
with self._q_lock:
|
||||||
self._waiting = True
|
# 初始化等待
|
||||||
self._expect = expect_b
|
self._waiting = True
|
||||||
self._resp = b""
|
self._expect = expect_b
|
||||||
|
self._resp = b""
|
||||||
|
|
||||||
# 发送
|
# 发送
|
||||||
if cmd:
|
if cmd:
|
||||||
@@ -300,8 +301,8 @@ class ATClient:
|
|||||||
if len(self._rx) > 512 * 1024:
|
if len(self._rx) > 512 * 1024:
|
||||||
self._rx = self._rx[-256 * 1024:]
|
self._rx = self._rx[-256 * 1024:]
|
||||||
else:
|
else:
|
||||||
if len(self._rx) > 16384:
|
if len(self._rx) > 32768:
|
||||||
self._rx = self._rx[-4096:]
|
self._rx = self._rx[-16384:]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ TRIANGLE_DETECT_SCALE = 0.4
|
|||||||
# SERVER_IP = "stcp.shelingxingqiu.com"
|
# SERVER_IP = "stcp.shelingxingqiu.com"
|
||||||
SERVER_IP = "www.shelingxingqiu.com"
|
SERVER_IP = "www.shelingxingqiu.com"
|
||||||
SERVER_PORT = 50005
|
SERVER_PORT = 50005
|
||||||
HEARTBEAT_INTERVAL = 15 # 心跳间隔(秒)
|
HEARTBEAT_INTERVAL = 5 # 心跳间隔(秒)
|
||||||
|
|
||||||
# WiFi 质量评估(开机先尝试 WiFi;质量差且 4G 可用则切到 4G,本次上电直至关机锁定 4G)
|
# WiFi 质量评估(开机先尝试 WiFi;质量差且 4G 可用则切到 4G,本次上电直至关机锁定 4G)
|
||||||
WIFI_QUALITY_RTT_SAMPLES = 3 # 到业务服务器 TCP 建连耗时采样次数,取中位数
|
WIFI_QUALITY_RTT_SAMPLES = 3 # 到业务服务器 TCP 建连耗时采样次数,取中位数
|
||||||
|
|||||||
+57
-8
@@ -624,6 +624,11 @@ 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:
|
||||||
|
for _f in ("/etc/wpa_supplicant.conf", "/boot/wpa_supplicant.conf", "/boot/wifi.ssid", "/boot/wifi.pass"):
|
||||||
|
try:
|
||||||
|
os.remove(_f)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
w = network.wifi.Wifi()
|
w = network.wifi.Wifi()
|
||||||
e = w.connect(ssid, password, wait=True, timeout=15)
|
e = w.connect(ssid, password, wait=True, timeout=15)
|
||||||
err.check_raise(e, "connect wifi failed")
|
err.check_raise(e, "connect wifi failed")
|
||||||
@@ -665,6 +670,11 @@ class NetworkManager:
|
|||||||
ssid = inner_data.get("ssid")
|
ssid = inner_data.get("ssid")
|
||||||
password = inner_data.get("password")
|
password = inner_data.get("password")
|
||||||
try:
|
try:
|
||||||
|
for _f in ("/etc/wpa_supplicant.conf", "/boot/wpa_supplicant.conf", "/boot/wifi.ssid", "/boot/wifi.pass"):
|
||||||
|
try:
|
||||||
|
os.remove(_f)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
w = network.wifi.Wifi()
|
w = network.wifi.Wifi()
|
||||||
e = w.connect(ssid, password, wait=True, timeout=15)
|
e = w.connect(ssid, password, wait=True, timeout=15)
|
||||||
err.check_raise(e, "connect wifi failed")
|
err.check_raise(e, "connect wifi failed")
|
||||||
@@ -678,6 +688,11 @@ class NetworkManager:
|
|||||||
},
|
},
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
|
self._session_force_4g = False
|
||||||
|
self.disconnect_server()
|
||||||
|
self._tcp_connected = False
|
||||||
|
self._network_type = None
|
||||||
|
self.logger.info("[conn wifi] WiFi已连接,等待主循环重新登录")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"cmd600 失败: {e}")
|
self.logger.error(f"cmd600 失败: {e}")
|
||||||
self.safe_enqueue(
|
self.safe_enqueue(
|
||||||
@@ -706,7 +721,7 @@ class NetworkManager:
|
|||||||
if self._network_type == "wifi":
|
if self._network_type == "wifi":
|
||||||
return self._check_wifi_connection()
|
return self._check_wifi_connection()
|
||||||
elif self._network_type == "4g":
|
elif self._network_type == "4g":
|
||||||
return True # 4G连接状态由AT命令维护
|
return self._check_4g_connection()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 自动选择网络
|
# 自动选择网络
|
||||||
@@ -723,6 +738,37 @@ class NetworkManager:
|
|||||||
return self._connect_tcp_via_4g()
|
return self._connect_tcp_via_4g()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _check_4g_connection(self):
|
||||||
|
"""检查4G TCP连接是否仍然有效(通过查询PDP地址验证网络附着状态)"""
|
||||||
|
try:
|
||||||
|
atc = hardware_manager.at_client
|
||||||
|
if atc is None:
|
||||||
|
return False
|
||||||
|
if not self._uart4g_lock.acquire(timeout=3000):
|
||||||
|
# 获取锁超时说明有其他操作在进行,视为连接仍有效
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
r = atc.send("AT+CGPADDR=1", "OK", 3000)
|
||||||
|
m = re.search(r'\+CGPADDR:\s*1,"([^"]+)"', r)
|
||||||
|
ip = m.group(1) if m else ""
|
||||||
|
if ip and ip != "0.0.0.0":
|
||||||
|
return True
|
||||||
|
# 无IP或IP无效,尝试重新激活PDP
|
||||||
|
self.logger.warning("[4G-TCP] PDP地址无效,尝试重新激活")
|
||||||
|
atc.send("AT+MIPCALL=1,1", "OK", 15000)
|
||||||
|
r2 = atc.send("AT+CGPADDR=1", "OK", 3000)
|
||||||
|
m2 = re.search(r'\+CGPADDR:\s*1,"([^"]+)"', r2)
|
||||||
|
ip2 = m2.group(1) if m2 else ""
|
||||||
|
if ip2 and ip2 != "0.0.0.0":
|
||||||
|
return True
|
||||||
|
self.logger.error("[4G-TCP] 重新激活PDP仍无有效IP,连接已断开")
|
||||||
|
return False
|
||||||
|
finally:
|
||||||
|
self._uart4g_lock.release()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.warning(f"[4G-TCP] 连接检查异常: {e}")
|
||||||
|
return True # 异常时不误判断线
|
||||||
|
|
||||||
def _wrap_wifi_tls(self, plain_sock, hostname):
|
def _wrap_wifi_tls(self, plain_sock, hostname):
|
||||||
"""
|
"""
|
||||||
在已建立的 TCP socket 上做 TLS(WiFi 走主机 ssl 库;4G 仍用模组 AT+SSL)。
|
在已建立的 TCP socket 上做 TLS(WiFi 走主机 ssl 库;4G 仍用模组 AT+SSL)。
|
||||||
@@ -1070,6 +1116,8 @@ class NetworkManager:
|
|||||||
total += n
|
total += n
|
||||||
|
|
||||||
hardware_manager.uart4g.write(b"\x1A")
|
hardware_manager.uart4g.write(b"\x1A")
|
||||||
|
with hardware_manager.at_client._q_lock:
|
||||||
|
hardware_manager.at_client._rx = b""
|
||||||
r = hardware_manager.at_client.send("", "OK", 8000)
|
r = hardware_manager.at_client.send("", "OK", 8000)
|
||||||
if ("SEND OK" in r) or ("OK" in r) or ("+MIPSEND" in r):
|
if ("SEND OK" in r) or ("OK" in r) or ("+MIPSEND" in r):
|
||||||
return True
|
return True
|
||||||
@@ -1784,7 +1832,7 @@ class NetworkManager:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if not self.connect_server():
|
if not self.connect_server():
|
||||||
time.sleep_ms(5000)
|
time.sleep_ms(1000)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 发送登录包
|
# 发送登录包
|
||||||
@@ -1805,7 +1853,7 @@ class NetworkManager:
|
|||||||
self.disconnect_server()
|
self.disconnect_server()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
time.sleep_ms(2000)
|
time.sleep_ms(500)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.logger.info("➡️ 登录包已发送,等待确认...")
|
self.logger.info("➡️ 登录包已发送,等待确认...")
|
||||||
@@ -2092,6 +2140,7 @@ class NetworkManager:
|
|||||||
battery_data = {
|
battery_data = {
|
||||||
"battery": battery_percent,
|
"battery": battery_percent,
|
||||||
"voltage": round(float(voltage), 3),
|
"voltage": round(float(voltage), 3),
|
||||||
|
"netType": self.network_type,
|
||||||
}
|
}
|
||||||
self.safe_enqueue(battery_data, 2)
|
self.safe_enqueue(battery_data, 2)
|
||||||
self.logger.info(f"电量上报: {battery_percent}%")
|
self.logger.info(f"电量上报: {battery_percent}%")
|
||||||
@@ -2147,7 +2196,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(
|
||||||
@@ -2293,8 +2342,8 @@ class NetworkManager:
|
|||||||
pass
|
pass
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# 不立即断开,让下一轮心跳再试;同时缩短一点等待,提升恢复速度
|
# 不立即断开,让下一轮心跳再试
|
||||||
time.sleep_ms(200)
|
time.sleep_ms(50)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
send_hartbeat_fail_count = 0
|
send_hartbeat_fail_count = 0
|
||||||
@@ -2324,8 +2373,8 @@ class NetworkManager:
|
|||||||
self._send_event.clear()
|
self._send_event.clear()
|
||||||
|
|
||||||
self._tcp_connected = False
|
self._tcp_connected = False
|
||||||
self.logger.error("连接异常,2秒后重连...")
|
self.logger.error("连接异常,50ms后重连...")
|
||||||
time.sleep_ms(200)
|
time.sleep_ms(50)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TCP主循环的顶层异常捕获,防止线程静默退出
|
# TCP主循环的顶层异常捕获,防止线程静默退出
|
||||||
|
|||||||
@@ -94,29 +94,33 @@ def detect_circle_v3(frame, laser_point=None):
|
|||||||
# 如果检测到黄色圆圈,再检测红色圆圈进行验证
|
# 如果检测到黄色圆圈,再检测红色圆圈进行验证
|
||||||
if yellow_center and yellow_radius:
|
if yellow_center and yellow_radius:
|
||||||
# HSV 红色掩码检测(红色在HSV中跨越0度,需要两个范围)
|
# HSV 红色掩码检测(红色在HSV中跨越0度,需要两个范围)
|
||||||
# 红色范围1: 0-10度(接近0度的红色)
|
# 红色范围1: 0-12度(接近0度的红色)
|
||||||
lower_red1 = np.array([0, 50, 40])
|
# 放宽S/V阈值:S>=30, V>=20 以捕获淡红/暗红
|
||||||
upper_red1 = np.array([10, 255, 255])
|
lower_red1 = np.array([0, 30, 20])
|
||||||
|
upper_red1 = np.array([12, 255, 255])
|
||||||
mask_red1 = cv2.inRange(hsv, lower_red1, upper_red1)
|
mask_red1 = cv2.inRange(hsv, lower_red1, upper_red1)
|
||||||
|
|
||||||
# 红色范围2: 170-180度(接近180度的红色)
|
# 红色范围2: 168-180度(接近180度的红色)
|
||||||
lower_red2 = np.array([170, 50, 40])
|
lower_red2 = np.array([168, 30, 20])
|
||||||
upper_red2 = np.array([180, 255, 255])
|
upper_red2 = np.array([180, 255, 255])
|
||||||
mask_red2 = cv2.inRange(hsv, lower_red2, upper_red2)
|
mask_red2 = cv2.inRange(hsv, lower_red2, upper_red2)
|
||||||
|
|
||||||
# 合并两个红色掩码
|
# 合并两个红色掩码
|
||||||
mask_red = cv2.bitwise_or(mask_red1, mask_red2)
|
mask_red = cv2.bitwise_or(mask_red1, mask_red2)
|
||||||
|
|
||||||
# 形态学操作
|
# 形态学操作:先CLOSE填充空洞,再DILATE加厚环状区域
|
||||||
kernel_red = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
|
kernel_red = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
|
||||||
mask_red = cv2.morphologyEx(mask_red, cv2.MORPH_CLOSE, kernel_red)
|
mask_red = cv2.morphologyEx(mask_red, cv2.MORPH_CLOSE, kernel_red)
|
||||||
|
mask_red = cv2.dilate(mask_red, kernel_red, iterations=1)
|
||||||
|
|
||||||
contours_red, _ = cv2.findContours(mask_red, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
contours_red, _ = cv2.findContours(mask_red, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||||
|
|
||||||
|
red_pixel_count = np.sum(mask_red > 0)
|
||||||
|
print(f"Debug -> 红色掩码: {red_pixel_count} 像素, {len(contours_red)} 个轮廓")
|
||||||
|
|
||||||
found_valid_red = False
|
found_valid_red = False
|
||||||
|
|
||||||
if contours_red:
|
if contours_red:
|
||||||
# 找到所有符合条件的红色圆圈
|
|
||||||
for cnt_red in contours_red:
|
for cnt_red in contours_red:
|
||||||
area_red = cv2.contourArea(cnt_red)
|
area_red = cv2.contourArea(cnt_red)
|
||||||
perimeter_red = cv2.arcLength(cnt_red, True)
|
perimeter_red = cv2.arcLength(cnt_red, True)
|
||||||
@@ -126,9 +130,10 @@ def detect_circle_v3(frame, laser_point=None):
|
|||||||
else:
|
else:
|
||||||
circularity_red = 0
|
circularity_red = 0
|
||||||
|
|
||||||
# 红色圆圈也应该有一定的圆度
|
# 环状轮廓圆度可能偏低,放宽到0.2
|
||||||
if area_red > 30 and circularity_red > 0.4:
|
print(f"Debug -> 红轮廓: 面积={area_red:.1f}, 圆度={circularity_red:.2f}" +
|
||||||
# 计算红色圆圈的中心和半径
|
f" (面积>15={area_red > 15}, 圆度>0.2={circularity_red > 0.2})")
|
||||||
|
if area_red > 15 and circularity_red > 0.2:
|
||||||
if len(cnt_red) >= 5:
|
if len(cnt_red) >= 5:
|
||||||
(x_red, y_red), (w_red, h_red), angle_red = cv2.fitEllipse(cnt_red)
|
(x_red, y_red), (w_red, h_red), angle_red = cv2.fitEllipse(cnt_red)
|
||||||
radius_red = min(w_red, h_red) / 2
|
radius_red = min(w_red, h_red) / 2
|
||||||
@@ -139,22 +144,25 @@ def detect_circle_v3(frame, laser_point=None):
|
|||||||
red_center = (int(x_red), int(y_red))
|
red_center = (int(x_red), int(y_red))
|
||||||
red_radius = int(radius_red)
|
red_radius = int(radius_red)
|
||||||
|
|
||||||
# 计算黄色和红色圆心的距离
|
|
||||||
if red_center:
|
if red_center:
|
||||||
dx = yellow_center[0] - red_center[0]
|
dx = yellow_center[0] - red_center[0]
|
||||||
dy = yellow_center[1] - red_center[1]
|
dy = yellow_center[1] - red_center[1]
|
||||||
distance = np.sqrt(dx * dx + dy * dy)
|
distance = np.sqrt(dx * dx + dy * dy)
|
||||||
|
|
||||||
# 圆心距离阈值:应该小于黄色半径的某个倍数(比如1.5倍)
|
max_distance = yellow_radius * 2.0
|
||||||
max_distance = yellow_radius * 1.5
|
min_r = min(red_radius, yellow_radius)
|
||||||
|
max_r = max(red_radius, yellow_radius)
|
||||||
|
size_ratio = min_r / max_r if max_r > 0 else 0
|
||||||
|
print(f"Debug -> 圆心距={distance:.1f}(阈值={max_distance:.1f}), "
|
||||||
|
f"大小比={size_ratio:.2f}(阈值=0.5), "
|
||||||
|
f"距离OK={distance < max_distance}, 大小OK={size_ratio > 0.5}")
|
||||||
|
|
||||||
# 红色圆圈应该比黄色圆圈大(外圈)
|
# 允许红圈在黄圈外侧或内侧,只要大小相近(较小/较大 >= 0.5)
|
||||||
if distance < max_distance and red_radius > yellow_radius * 0.7:
|
if distance < max_distance and size_ratio > 0.5:
|
||||||
found_valid_red = True
|
found_valid_red = True
|
||||||
print(
|
print(
|
||||||
f"[target] -> 找到匹配的红圈: 黄心({yellow_center}), 红心({red_center}), 距离:{distance:.1f}, 黄半径:{yellow_radius}, 红半径:{red_radius}")
|
f"[target] -> 找到匹配的红圈: 黄心({yellow_center}), 红心({red_center}), 距离:{distance:.1f}, 黄半径:{yellow_radius}, 红半径:{red_radius}")
|
||||||
|
|
||||||
# 记录这个有效目标
|
|
||||||
valid_targets.append({
|
valid_targets.append({
|
||||||
'center': yellow_center,
|
'center': yellow_center,
|
||||||
'radius': yellow_radius,
|
'radius': yellow_radius,
|
||||||
@@ -164,7 +172,17 @@ def detect_circle_v3(frame, laser_point=None):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if not found_valid_red:
|
if not found_valid_red:
|
||||||
print("Debug -> 未找到匹配的红色圆圈,可能是误识别")
|
# 如果黄圈非常可靠(大且圆),在没有红圈验证时仍接受
|
||||||
|
if area > 30 and circularity > 0.85:
|
||||||
|
print(f"[target] -> 黄圈高置信度(面积:{area:.0f}, 圆度:{circularity:.2f}),跳过红圈验证直接接受")
|
||||||
|
valid_targets.append({
|
||||||
|
'center': yellow_center,
|
||||||
|
'radius': yellow_radius,
|
||||||
|
'ellipse': yellow_ellipse,
|
||||||
|
'area': area
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
print("Debug -> 未找到匹配的红色圆圈,可能是误识别")
|
||||||
|
|
||||||
# 从所有有效目标中选择最佳目标
|
# 从所有有效目标中选择最佳目标
|
||||||
if valid_targets:
|
if valid_targets:
|
||||||
@@ -596,7 +614,7 @@ if __name__ == "__main__":
|
|||||||
# 检查文件扩展名
|
# 检查文件扩展名
|
||||||
if any(filename.lower().endswith(ext) for ext in IMAGE_EXTENSIONS):
|
if any(filename.lower().endswith(ext) for ext in IMAGE_EXTENSIONS):
|
||||||
# 过滤掉 _result.jpg 后缀的文件
|
# 过滤掉 _result.jpg 后缀的文件
|
||||||
if not filename.endswith('_result.jpg'):
|
if filename.endswith('no_target.jpg'):
|
||||||
filepath = os.path.join(TARGET_DIR, filename)
|
filepath = os.path.join(TARGET_DIR, filename)
|
||||||
if os.path.isfile(filepath):
|
if os.path.isfile(filepath):
|
||||||
image_files.append(filepath)
|
image_files.append(filepath)
|
||||||
|
|||||||
@@ -25,3 +25,7 @@
|
|||||||
# 2.15.12 优化算法
|
# 2.15.12 优化算法
|
||||||
# 2.15.13 优化算法
|
# 2.15.13 优化算法
|
||||||
# 2.15.14 优化算法
|
# 2.15.14 优化算法
|
||||||
|
# 2.15.15 优化wifi连接
|
||||||
|
# 2.15.16 修复wifi连接问题
|
||||||
|
# 2.15.17 修复wifi连接问题
|
||||||
|
# 2.15.18 wifi连接成功重新登录
|
||||||
+1
-1
@@ -4,6 +4,6 @@
|
|||||||
应用版本号
|
应用版本号
|
||||||
每次 OTA 更新时,只需要更新这个文件中的版本号
|
每次 OTA 更新时,只需要更新这个文件中的版本号
|
||||||
"""
|
"""
|
||||||
VERSION = '2.15.14'
|
VERSION = '2.15.18'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -239,7 +239,6 @@ class WiFiManager:
|
|||||||
old_conf = _read_text(conf_path)
|
old_conf = _read_text(conf_path)
|
||||||
old_boot_ssid = _read_text(ssid_file)
|
old_boot_ssid = _read_text(ssid_file)
|
||||||
old_boot_pass = _read_text(pass_file)
|
old_boot_pass = _read_text(pass_file)
|
||||||
old_boot_wpa = _read_text(boot_wpa_path) if os.path.exists(boot_wpa_path) else None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
@@ -251,9 +250,13 @@ class WiFiManager:
|
|||||||
_write_text(conf_path, full_conf)
|
_write_text(conf_path, full_conf)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
_write_text(boot_wpa_path, full_conf)
|
# 删除 wpa_supplicant.conf,让 S30wifi 回退读 ssid/pass
|
||||||
|
try:
|
||||||
|
if os.path.exists(boot_wpa_path):
|
||||||
|
os.remove(boot_wpa_path)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# 仍写入 ssid/pass,便于其它脚本/人工查看;S30wifi 优先使用 wpa_supplicant.conf
|
|
||||||
_write_text(ssid_file, ssid.strip())
|
_write_text(ssid_file, ssid.strip())
|
||||||
_write_text(pass_file, password.strip())
|
_write_text(pass_file, password.strip())
|
||||||
|
|
||||||
@@ -293,7 +296,6 @@ class WiFiManager:
|
|||||||
if not persist:
|
if not persist:
|
||||||
# 不持久化:把 /boot 恢复成旧值(不重启,当前连接保持不变)
|
# 不持久化:把 /boot 恢复成旧值(不重启,当前连接保持不变)
|
||||||
_restore_boot(old_boot_ssid, old_boot_pass)
|
_restore_boot(old_boot_ssid, old_boot_pass)
|
||||||
_restore_boot_wpa(old_boot_wpa)
|
|
||||||
self.logger.info("[WIFI] 网络验证通过,但按 persist=False 回滚 /boot 凭证(不重启)")
|
self.logger.info("[WIFI] 网络验证通过,但按 persist=False 回滚 /boot 凭证(不重启)")
|
||||||
else:
|
else:
|
||||||
self.logger.info("[WIFI] 网络验证通过,/boot 凭证已保留(持久化)")
|
self.logger.info("[WIFI] 网络验证通过,/boot 凭证已保留(持久化)")
|
||||||
@@ -307,7 +309,6 @@ class WiFiManager:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 失败:回滚 /boot 和 /etc,重启 WiFi 恢复旧网络
|
# 失败:回滚 /boot 和 /etc,重启 WiFi 恢复旧网络
|
||||||
_restore_boot(old_boot_ssid, old_boot_pass)
|
_restore_boot(old_boot_ssid, old_boot_pass)
|
||||||
_restore_boot_wpa(old_boot_wpa)
|
|
||||||
try:
|
try:
|
||||||
if old_conf is not None:
|
if old_conf is not None:
|
||||||
_write_text(conf_path, old_conf)
|
_write_text(conf_path, old_conf)
|
||||||
@@ -352,7 +353,11 @@ class WiFiManager:
|
|||||||
else:
|
else:
|
||||||
full_conf = build_sta_conf_open(ssid)
|
full_conf = build_sta_conf_open(ssid)
|
||||||
_write_text(conf_path, full_conf)
|
_write_text(conf_path, full_conf)
|
||||||
_write_text(boot_wpa_path, full_conf)
|
try:
|
||||||
|
if os.path.exists(boot_wpa_path):
|
||||||
|
os.remove(boot_wpa_path)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return False, str(e)
|
return False, str(e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user