Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
63b4c13f
提交
63b4c13f
authored
11月 25, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new feature: evwifi
上级
2f33bdea
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
64 行增加
和
39 行删除
+64
-39
CMakeLists.txt
opencv-motion-detect/CMakeLists.txt
+2
-2
evwifi.cpp
opencv-motion-detect/evwifi.cpp
+62
-37
没有找到文件。
opencv-motion-detect/CMakeLists.txt
浏览文件 @
63b4c13f
...
...
@@ -76,4 +76,4 @@ add_executable(evmlmotion evmlmotion.cpp)
target_link_libraries
(
evmlmotion PUBLIC
${
COMM_LIBS
}
${
AV_LIBS
}
${
CV_LIBRARIES
}
${
EXTRA_LIBS
}
)
add_executable
(
evwifi evwifi.cpp
)
target_link_libraries
(
evwifi PUBLIC database leveldb
)
\ No newline at end of file
target_link_libraries
(
evwifi PUBLIC database leveldb pthread
)
\ No newline at end of file
opencv-motion-detect/evwifi.cpp
浏览文件 @
63b4c13f
...
...
@@ -38,9 +38,7 @@ class WifiMgr {
Server
srv
;
promise
<
int
>
p
;
thread
monitor
;
vector
<
string
>
ssids
;
string
wifiSSID
;
string
wifiPasswd
;
json
wifiData
;
int
mode
,
lastMode
;
// 1: ap; 2: ste
const
string
apdCfgPath
=
"/etc/apd.conf"
;
const
string
wpaCfgPath
=
"/etc/wpa_supplicant/wpa_supplicant-wlan1.conf"
;
...
...
@@ -68,54 +66,64 @@ class WifiMgr {
/// scan wifis
string
res
=
exec
(
"iwlist wlan1 scan|grep ESSID"
);
ssids
.
clear
();
wifiData
[
"wifi"
][
"ssids"
]
.
clear
();
httplib
::
detail
::
split
(
&
res
[
0
],
&
res
[
res
.
size
()],
'\n'
,
[
&
](
const
char
*
b
,
const
char
*
e
)
{
string
ssid
;
ssid
.
assign
(
b
,
e
);
ssids
.
push_back
(
ssid
);
wifiData
[
"wifi"
][
"ssids"
]
.
push_back
(
ssid
);
});
//
}
else
{
ret
[
"code"
]
=
1
;
string
msg
=
fmt
::
format
(
"failed to write ap config file to {}"
,
apdCfgPath
);
spdlog
::
error
(
msg
);
ret
[
"msg"
]
=
msg
;
return
ret
;
}
}
else
if
(
mode
==
2
)
{
// station mode
spdlog
::
info
(
"prepare to enter Station mode"
);
// stop hostapd
exec
(
"pkill hostapd"
);
string
wpaContent
=
fmt
::
format
(
"ctrl_interface=/run/wpa_supplicant
\n
update_config=1
\n
ap_scan=1
\n
"
"network={{
\n
ssid=
\"
{}
\"\n
psk=
\"
{}
\"\n
}}
\n
"
,
this
->
wifiSSID
,
this
->
wifiPasswd
);
ofstream
wpaFile
(
wpaCfgPath
,
ios
::
out
|
ios
::
trunc
);
if
(
wpaFile
.
is_open
()){
wpaFile
<<
wpaContent
;
wpaFile
.
close
();
// TODO: verify
spdlog
::
info
(
exec
(
"systemctl enable wap_supplicant@wlan1"
));
spdlog
::
info
(
exec
(
"systemctl restart wap_supplicant@wlan1"
));
spdlog
::
info
(
exec
(
"dhclient wlan1"
));
}
else
{
string
msg
=
fmt
::
format
(
"failed write wpa config to {}"
,
wpaCfgPath
);
ret
[
"code"
]
=
2
;
ret
[
"msg"
]
=
msg
;
spdlog
::
error
(
msg
);
return
ret
;
}
if
(
wifiData
[
"wifi"
].
count
(
"ssid"
)
==
0
||
wifiData
[
"wifi"
][
"ssid"
].
size
()
==
0
||
wifiData
[
"wifi"
].
count
(
"password"
)
==
0
||
wifiData
[
"wifi"
][
"password"
].
size
()
==
0
)
{
string
msg
=
fmt
::
format
(
"no valid ssid/password provided"
);
spdlog
::
error
(
msg
);
ret
[
"msg"
]
=
msg
;
ret
[
"code"
]
=
3
;
}
else
{
// stop hostapd
exec
(
"pkill hostapd"
);
string
wpaContent
=
fmt
::
format
(
"ctrl_interface=/run/wpa_supplicant
\n
update_config=1
\n
ap_scan=1
\n
"
"network={{
\n
ssid=
\"
{}
\"\n
psk=
\"
{}
\"\n
}}
\n
"
,
this
->
wifiData
[
"wifi"
][
"ssid"
].
get
<
string
>
(),
this
->
wifiData
[
"wifi"
][
"password"
].
get
<
string
>
());
ofstream
wpaFile
(
wpaCfgPath
,
ios
::
out
|
ios
::
trunc
);
if
(
wpaFile
.
is_open
()){
wpaFile
<<
wpaContent
;
wpaFile
.
close
();
// TODO: verify
spdlog
::
info
(
exec
(
"systemctl enable wap_supplicant@wlan1"
));
spdlog
::
info
(
exec
(
"systemctl restart wap_supplicant@wlan1"
));
spdlog
::
info
(
exec
(
"dhclient wlan1"
));
}
else
{
string
msg
=
fmt
::
format
(
"failed write wpa config to {}"
,
wpaCfgPath
);
ret
[
"code"
]
=
2
;
ret
[
"msg"
]
=
msg
;
spdlog
::
error
(
msg
);
}
}
}
ret
[
"wifiData"
]
=
wifiData
;
return
ret
;
}
public
:
WifiMgr
(){
LVDB
::
getSn
(
this
->
info
);
wifiData
[
"sn"
]
=
this
->
info
;
wifiData
[
"wifi"
]
=
json
();
wifiData
[
"wifi"
][
"ssids"
]
=
json
();
//wifiData["wifi"]["ssid"] = string;
//wifiData["wifi"]["password"] = string;
monitor
=
thread
([
this
](){
// check /etc/systemd/wpa_supplicant@wlan1.service
...
...
@@ -126,12 +134,12 @@ class WifiMgr {
// default is AP mode
this
->
lastMode
=
0
;
while
(
1
){
// check modes
this
->
mode
=
1
;
if
(
this
->
lastMode
!=
this
->
mode
)
{
enableMode
(
this
->
mode
);
}
this
->
lastMode
=
this
->
mode
;
//
//
check modes
//
this->mode = 1;
//
if(this->lastMode != this->mode) {
//
enableMode(this->mode);
//
}
//
this->lastMode = this->mode;
this_thread
::
sleep_for
(
chrono
::
seconds
(
10
));
}
});
...
...
@@ -147,7 +155,24 @@ class WifiMgr {
if
(
!
mode
.
empty
()){
try
{
auto
i
=
stoi
(
mode
);
ret
=
this
->
enableMode
(
i
);
if
(
i
==
2
)
{
string
ssid
=
req
.
get_param_value
(
"ssid"
);
string
password
=
req
.
get_param_value
(
"password"
);
if
(
ssid
.
empty
()
||
password
.
empty
()){
string
msg
=
fmt
::
format
(
"no valid ssid/password provided"
);
spdlog
::
error
(
msg
);
ret
[
"msg"
]
=
msg
;
ret
[
"code"
]
=
3
;
}
else
{
this
->
wifiData
[
"wifi"
][
"ssid"
]
=
ssid
;
this
->
wifiData
[
"wifi"
][
"password"
]
=
password
;
}
}
if
(
ret
[
"coce"
]
==
0
)
{
ret
=
this
->
enableMode
(
i
);
}
}
catch
(
exception
&
e
){
string
msg
=
fmt
::
format
(
"exception in convert mode {} to int:{}"
,
mode
,
e
.
what
());
ret
[
"code"
]
=
-
1
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论