4 Commits
Author SHA1 Message Date
yrx 440e34097c 修复不关机补充 2026-06-23 11:09:33 +08:00
yrx 02d3e18d35 修复不关机 2026-06-23 10:20:25 +08:00
linyimin c34efed6f9 fix: wifi连接 2026-06-22 12:05:23 +08:00
linyimin 226394d3ed fix: wifi连接 2026-06-22 12:00:08 +08:00
7 changed files with 35 additions and 18 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
id: t11 id: t11
name: t11 name: t11
version: 2.15.14 version: 2.15.15
author: t11 author: t11
icon: '' icon: ''
desc: t11 desc: t11
@@ -25,6 +25,7 @@ files:
- ota_manager.py - ota_manager.py
- power.py - power.py
- server.pem - server.pem
- set_autostart.py
- shoot_manager.py - shoot_manager.py
- shot_id_generator.py - shot_id_generator.py
- target_roi_yolo.py - target_roi_yolo.py
+1 -1
View File
@@ -341,7 +341,7 @@ PIN_MAPPINGS = {
} }
# ==================== 电源配置 ==================== # ==================== 电源配置 ====================
AUTO_POWER_OFF_IN_SECONDS = 10 * 60 # 自动关机时间(秒),0表示不自动关机 AUTO_POWER_OFF_IN_SECONDS = 0 # 自动关机时间(秒),0表示不自动关机
BATTERY_SOC_LPF_ALPHA = 0.5 BATTERY_SOC_LPF_ALPHA = 0.5
BATTERY_SOC_AVG_WINDOW = 5 BATTERY_SOC_AVG_WINDOW = 5
+8 -7
View File
@@ -29,7 +29,7 @@ class HardwareManager:
self._adc_obj = None # ADC对象 self._adc_obj = None # ADC对象
self._at_client = None # AT客户端 self._at_client = None # AT客户端
self._last_active_time = 0 # 用于记录用户的最后一次活跃的时间 self._last_active_ticks = None # 上次活跃时刻(ticks_ms,单调递增,不受校时影响)
self._stop_timer = False # 用于停止定时器的标志 self._stop_timer = False # 用于停止定时器的标志
self._initialized = True self._initialized = True
@@ -111,7 +111,7 @@ class HardwareManager:
def start_idle_timer(self): def start_idle_timer(self):
self._stop_timer = False self._stop_timer = False
self._last_active_time = time.time() self._last_active_ticks = time.ticks_ms()
def stop_idle_timer(self): def stop_idle_timer(self):
self._stop_timer = True self._stop_timer = True
@@ -119,12 +119,13 @@ class HardwareManager:
def get_idle_time_in_sec(self): def get_idle_time_in_sec(self):
if self._stop_timer: if self._stop_timer:
return 0 return 0
diff = time.time() - self._last_active_time if self._last_active_ticks is None:
if diff < 0:
# 时间可能被重置了,重新计时
self._last_active_time = time.time()
return 0 return 0
return diff diff_ms = time.ticks_diff(time.ticks_ms(), self._last_active_ticks)
if diff_ms < 0:
self._last_active_ticks = time.ticks_ms()
return 0
return diff_ms / 1000.0
# 创建全局单例实例 # 创建全局单例实例
+9 -1
View File
@@ -275,6 +275,11 @@ def cmd_str():
hardware_manager.start_idle_timer() hardware_manager.start_idle_timer()
if logger: if logger:
_auto_power_off = int(getattr(config, "AUTO_POWER_OFF_IN_SECONDS", 0) or 0)
if _auto_power_off <= 0:
logger.info("[MAIN] 自动关机已禁用 (AUTO_POWER_OFF_IN_SECONDS=0)")
else:
logger.info(f"[MAIN] 自动关机: {_auto_power_off} 秒无活动")
logger.info("系统准备完成...") logger.info("系统准备完成...")
last_adc_trigger = 0 last_adc_trigger = 0
@@ -338,7 +343,10 @@ def cmd_str():
# 不在 OTA 状态下,检测是否空闲足够长,自动关机 # 不在 OTA 状态下,检测是否空闲足够长,自动关机
# print(f"[MAIN] 空闲时间: {hardware_manager.get_idle_time_in_sec() }秒") # print(f"[MAIN] 空闲时间: {hardware_manager.get_idle_time_in_sec() }秒")
# print(f"配置关机时间:{config.AUTO_POWER_OFF_IN_SECONDS} 秒") # print(f"配置关机时间:{config.AUTO_POWER_OFF_IN_SECONDS} 秒")
if hardware_manager.get_idle_time_in_sec() > config.AUTO_POWER_OFF_IN_SECONDS: if (
config.AUTO_POWER_OFF_IN_SECONDS > 0
and hardware_manager.get_idle_time_in_sec() > config.AUTO_POWER_OFF_IN_SECONDS
):
logger.info("[MAIN] 超过设定时间未检测活动,自动关机") logger.info("[MAIN] 超过设定时间未检测活动,自动关机")
network_manager.safe_enqueue({"poweroff": "超过设定时间未检测活动,自动关机"}, 2) network_manager.safe_enqueue({"poweroff": "超过设定时间未检测活动,自动关机"}, 2)
time.sleep_ms(100) time.sleep_ms(100)
+2
View File
@@ -25,3 +25,5 @@
# 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 修复不关机,空闲计时改用 ticks_ms(不受校时影响),启动时打印自动关机配置
+1 -1
View File
@@ -4,6 +4,6 @@
应用版本号 应用版本号
每次 OTA 更新时,只需要更新这个文件中的版本号 每次 OTA 更新时,只需要更新这个文件中的版本号
""" """
VERSION = '2.15.14' VERSION = '2.15.16'
+11 -6
View File
@@ -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: