forked from zbw/yiliao2026
with '#' will be ignored, and an empty message aborts the commit. On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) Changes to be committed: modified: .gitignore modified: README.md new file: bashes/auto-wifi-connect.service new file: bashes/auto-wifi-connect.sh deleted: keyboard_control.py new file: my_model/image.png new file: path_follower_demo.py new file: scripts/PIDtracking.py new file: scripts/__pycache__/publish_sine_path.cpython-310.pyc new file: scripts/publish_sine_path.py modified: src/gc_navigation2_slamtoolbox/params/gc_navigation_slam.yaml modified: src/gc_navigation2_slamtoolbox/params/gc_navigation_slam.yaml.bak new file: src/gc_navigation2_slamtoolbox/params/gc_navigation_slam.yaml.bak2 modified: src/origincar_base/config/ekf.yaml new file: src/origincar_base/config/ekf.yaml.bak modified: src/origincar_base/launch/base_serial.launch.py new file: src/origincar_base/launch/base_serial.launch.py.bak modified: src/origincar_base/launch/origincar_bringup.launch.py new file: src/past_control/CMakeLists.txt new file: src/past_control/config/past_control.yaml new file: src/past_control/include/past_control/tools.h new file: src/past_control/launch/past_control.launch.py new file: src/past_control/msg/Obstacle.msg new file: src/past_control/msg/ObstacleArray.msg new file: src/past_control/package.xml new file: src/past_control/src/lane_follower_node.cpp new file: src/past_control/src/obstacle_detector_node.cpp new file: src/past_control/src/racing_orchestrator.cpp new file: src/planner/CMakeLists.txt new file: src/planner/config/planner.yaml new file: src/planner/launch/planner.launch.py new file: src/planner/package.xml new file: src/planner/src/planner_version.cpp modified: src/qr_detection/src/qr_dete_depth.cpp new file: src/racing_control/CMakeLists.txt new file: src/racing_control/include/racing_control/racing_control.hpp new file: src/racing_control/package.xml new file: src/racing_control/src/racing_control.cpp modified: src/vlm_detect/setup.py new file: src/vlm_detect/vlm_detect/__pycache__/__init__.cpython-310.pyc new file: src/vlm_detect/vlm_detect/__pycache__/tts_node.cpython-310.pyc new file: src/vlm_detect/vlm_detect/test_publisher.py new file: src/vlm_detect/vlm_detect/tts_node.py modified: src/vlm_detect/vlm_detect/vlm_node.py new file: tools/measure_turning_radius.py new file: tools/set_volume.py new file: tools/udp_to_cmdvel.py new file: tools/windows_keyboard_control.py new file: vlm_server.py new file: "\350\260\203\350\257\225\350\256\260\345\275\225.Assets/1.png" renamed: "\350\260\203\350\257\225\350\256\260\345\275\225.log" -> "\350\260\203\350\257\225\350\256\260\345\275\225.md"
79 lines
2.2 KiB
Bash
Executable File
79 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
||
# ============================================================================
|
||
# auto-wifi-connect.sh — 开机自动连接 WiFi
|
||
#
|
||
# 优先级:openwrt_5G > kskbl_2.4G
|
||
# 扫描可用网络,优先连接 5G 热点,不可用时回退到 2.4G
|
||
#
|
||
# 退出码:
|
||
# 0 — 成功连接
|
||
# 1 — NetworkManager 未就绪(超时)
|
||
# 2 — 两个热点均不可用
|
||
# 3 — 连接失败
|
||
# ============================================================================
|
||
|
||
PRIMARY="openwrt_5G"
|
||
FALLBACK="kskbl_2.4G"
|
||
WIFI_PASSWORD="11112222"
|
||
MAX_WAIT=30 # 最多等 NetworkManager 就绪的秒数
|
||
SCAN_WAIT=3 # WiFi 扫描后的等待秒数
|
||
|
||
log() {
|
||
echo "[auto-wifi] $(date '+%H:%M:%S') $*" | tee /dev/kmsg 2>/dev/null
|
||
}
|
||
|
||
# ── 等待 NetworkManager 就绪 ──
|
||
log "等待 NetworkManager 就绪..."
|
||
for i in $(seq 1 $MAX_WAIT); do
|
||
state=$(nmcli -t -f STATE general status 2>/dev/null)
|
||
if [ -n "$state" ]; then
|
||
log "NetworkManager 状态: $state"
|
||
break
|
||
fi
|
||
sleep 2
|
||
done
|
||
|
||
if [ -z "$state" ]; then
|
||
log "错误: NetworkManager 在 ${MAX_WAIT}s 内未就绪"
|
||
exit 1
|
||
fi
|
||
|
||
# ── 获取 WiFi 网卡名 ──
|
||
WIFI_IFACE=$(nmcli -t -f DEVICE,TYPE device status 2>/dev/null | grep ':wifi$' | cut -d: -f1 | head -1)
|
||
if [ -z "$WIFI_IFACE" ]; then
|
||
log "错误: 未找到 WiFi 网卡"
|
||
exit 2
|
||
fi
|
||
log "WiFi 网卡: $WIFI_IFACE"
|
||
|
||
# ── 先检查是否已经连接到目标热点 ──
|
||
current=$(nmcli -t -f GENERAL.CONNECTION device show "$WIFI_IFACE" 2>/dev/null | cut -d: -f2)
|
||
if [ "$current" = "$PRIMARY" ] || [ "$current" = "$FALLBACK" ]; then
|
||
log "已连接到 $current,无须切换"
|
||
exit 0
|
||
fi
|
||
|
||
# ── 扫描 WiFi ──
|
||
log "正在扫描 WiFi..."
|
||
nmcli device wifi rescan 2>/dev/null
|
||
sleep $SCAN_WAIT
|
||
|
||
# ── 检查 PRIMARY 是否可见 ──
|
||
if nmcli -t -f SSID device wifi list 2>/dev/null | grep -qx "$PRIMARY"; then
|
||
TARGET="$PRIMARY"
|
||
log "检测到 $PRIMARY"
|
||
else
|
||
TARGET="$FALLBACK"
|
||
log "$PRIMARY 不可用,回退到 $TARGET"
|
||
fi
|
||
|
||
# ── 连接 ──
|
||
log "正在连接 $TARGET ..."
|
||
if nmcli device wifi connect "$TARGET" password "$WIFI_PASSWORD" ifname "$WIFI_IFACE" 2>&1; then
|
||
log "成功连接到 $TARGET"
|
||
exit 0
|
||
else
|
||
log "错误: 无法连接到 $TARGET"
|
||
exit 3
|
||
fi
|