|
|
@@ -179,6 +179,26 @@ def _port_status_to_pic(port_state_entry):
|
|
|
return 3 # CONNECTED
|
|
|
|
|
|
|
|
|
+def _get_display_ip():
|
|
|
+ """获取用于屏幕显示的本机 IP 地址。"""
|
|
|
+ try:
|
|
|
+ net_status = network_manager.get_network_status()
|
|
|
+ for iface, data in net_status.get('interfaces', {}).items():
|
|
|
+ if iface in ('lo', 'docker0') or iface.startswith(('br-', 'veth')):
|
|
|
+ continue
|
|
|
+ for addr in data.get('ip_addresses', []):
|
|
|
+ if '.' in addr and not addr.startswith('127.'):
|
|
|
+ return addr
|
|
|
+ # 回退:尝试网络配置中的静态 IP
|
|
|
+ net_config = network_manager.get_network_config()
|
|
|
+ static_ip = net_config.get('static_config', {}).get('ip_address')
|
|
|
+ if static_ip:
|
|
|
+ return static_ip
|
|
|
+ except Exception as e:
|
|
|
+ logger.warning(f"获取显示 IP 失败: {e}")
|
|
|
+ return ''
|
|
|
+
|
|
|
+
|
|
|
def _screen_refresh_worker():
|
|
|
"""在后台线程中异步刷新 Nextion 屏幕。"""
|
|
|
while True:
|
|
|
@@ -221,8 +241,11 @@ def refresh_screen_panel(panel_id):
|
|
|
|
|
|
delay_ms = NEXTION_CMD_DELAY_MS
|
|
|
|
|
|
+ # 获取本机 IP 地址显示在 t1.txt
|
|
|
+ ip_address = _get_display_ip()
|
|
|
+
|
|
|
screen_display.send_cmd(f't2.txt="{NEXTION_PANEL_NAME_PREFIX}{idx + 1}"', delay_ms=delay_ms)
|
|
|
- screen_display.send_cmd(f't1.txt="{panel_id}"', delay_ms=delay_ms)
|
|
|
+ screen_display.send_cmd(f't1.txt="{ip_address}"', delay_ms=delay_ms)
|
|
|
screen_display.send_cmd(f't4.txt="{dtu_config.get("firmware_version", "v1.0.0")}"', delay_ms=delay_ms)
|
|
|
|
|
|
mqtt_str = '已连接' if mqtt_connected else '未连接'
|