Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
2762d018
Commit
2762d018
authored
Apr 08, 2026
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了大窝船,修改了部分代码,重写了网络重连机制,多种保底
parent
ffa4cc2c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
4 deletions
+85
-4
wifi_autoconfig.c
app/main/wifi_autoconfig.c
+84
-3
main
build/main
+0
-0
zlog.conf
zlog.conf
+1
-1
No files found.
app/main/wifi_autoconfig.c
View file @
2762d018
...
...
@@ -174,13 +174,89 @@ static void check_and_install_dependencies() {
}
}
// 检测是否有互联网连接(多目标探测,任意一个成功即视为有网)
// HTTP 204 保底探测:用于 ping 被屏蔽时的应用层联网判断
static
int
has_http_204_connection
()
{
// 先尝试 curl
if
(
is_command_available
(
"curl"
))
{
int
ret
=
system
(
"test
\"
$(curl -sL --max-time 3 -o /dev/null -w '%{http_code}' https://connectivitycheck.gstatic.com/generate_204)
\"
=
\"
204
\"
"
);
if
(
ret
==
0
)
{
my_zlog_debug
(
"网络探测成功: HTTP 204 (curl, https)"
);
return
1
;
}
// 备用 HTTP,适配部分 HTTPS 证书链异常场景
ret
=
system
(
"test
\"
$(curl -sL --max-time 3 -o /dev/null -w '%{http_code}' http://connectivitycheck.gstatic.com/generate_204)
\"
=
\"
204
\"
"
);
if
(
ret
==
0
)
{
my_zlog_debug
(
"网络探测成功: HTTP 204 (curl, http)"
);
return
1
;
}
}
// curl 不可用时,使用 wget 做兜底探测
if
(
is_command_available
(
"wget"
))
{
int
ret
=
system
(
"wget -q --timeout=3 --spider https://connectivitycheck.gstatic.com/generate_204"
);
if
(
ret
==
0
)
{
my_zlog_debug
(
"网络探测成功: HTTP 204 (wget)"
);
return
1
;
}
}
return
0
;
}
// 业务接口保底探测:请求 getConfig,若返回 data 非空则视为联网可用
static
int
has_business_api_connection
()
{
const
char
*
device_no_raw
=
device_id_function
();
if
(
device_no_raw
==
NULL
||
device_no_raw
[
0
]
==
'\0'
)
{
return
0
;
}
// 设备号文件可能带换行,先清理
char
device_no
[
64
];
snprintf
(
device_no
,
sizeof
(
device_no
),
"%s"
,
device_no_raw
);
device_no
[
strcspn
(
device_no
,
"
\r\n
"
)]
=
'\0'
;
if
(
device_no
[
0
]
==
'\0'
)
{
return
0
;
}
if
(
is_command_available
(
"curl"
))
{
char
cmd
[
512
];
snprintf
(
cmd
,
sizeof
(
cmd
),
"curl -sL --max-time 3
\"
https://fcrs-api.yd-ss.com/device/getConfig?deviceNo=%s
\"
"
,
device_no
);
FILE
*
fp
=
popen
(
cmd
,
"r"
);
if
(
fp
!=
NULL
)
{
char
resp
[
1024
];
size_t
n
=
fread
(
resp
,
1
,
sizeof
(
resp
)
-
1
,
fp
);
resp
[
n
]
=
'\0'
;
pclose
(
fp
);
cJSON
*
json
=
cJSON_Parse
(
resp
);
if
(
json
!=
NULL
)
{
cJSON
*
data
=
cJSON_GetObjectItemCaseSensitive
(
json
,
"data"
);
if
(
data
!=
NULL
&&
!
cJSON_IsNull
(
data
))
{
my_zlog_debug
(
"网络探测成功: business api"
);
cJSON_Delete
(
json
);
return
1
;
}
cJSON_Delete
(
json
);
}
}
}
return
0
;
}
// 检测是否有互联网连接(多目标 ping + HTTP 204 保底,任意成功即视为有网)
static
int
has_internet_connection
()
{
static
const
char
*
targets
[]
=
{
"baidu.com"
,
// 国内常见目标
"google.com"
,
// 海外常见目标
"mqtt177.controlmelive.com"
,
// 业务域名探测
"47.83.167.0"
,
// 业务 IP 探测(不依赖 DNS)
"1.1.1.1"
,
// Cloudflare DNS(不依赖域名解析)
"8.8.8.8"
// Google DNS(不依赖域名解析)
"8.8.8.8"
,
// Google DNS(不依赖域名解析)
};
// -c 1: 发送 1 个包, -W 2: 超时 2 秒
...
...
@@ -192,7 +268,12 @@ static int has_internet_connection() {
return
1
;
// 任意一个成功,直接返回
}
}
return
0
;
// ping 全失败时,尝试应用层保底探测
if
(
has_http_204_connection
())
{
return
1
;
}
return
has_business_api_connection
();
}
// 尝试连接 WiFi
...
...
build/main
View file @
2762d018
No preview for this file type
zlog.conf
View file @
2762d018
...
...
@@ -9,4 +9,4 @@ file perms = 600
millisecond
=
"%d(%Y-%m-%d %H:%M:%S).%ms [%V] %m%n"
[
rules
]
my_log
.*
"/home/orangepi/car/master/log/log_2026-04-0
3
.log"
;
millisecond
my_log
.*
"/home/orangepi/car/master/log/log_2026-04-0
8
.log"
;
millisecond
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment