Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
1736ffdf
提交
1736ffdf
authored
11月 26, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new feature: evwifi
上级
4bc7ffe5
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
37 行增加
和
22 行删除
+37
-22
evwifi.cpp
opencv-motion-detect/evwifi.cpp
+37
-22
没有找到文件。
opencv-motion-detect/evwifi.cpp
浏览文件 @
1736ffdf
...
@@ -35,11 +35,13 @@ using namespace httplib;
...
@@ -35,11 +35,13 @@ using namespace httplib;
class
WifiMgr
{
class
WifiMgr
{
private
:
private
:
json
info
;
json
info
;
string
devSn
;
Server
srv
;
Server
srv
;
promise
<
int
>
p
;
promise
<
int
>
p
;
thread
monitor
;
thread
monitor
;
json
wifiData
;
json
wifiData
;
int
mode
,
lastMode
;
// 1: ap; 2: ste
int
mode
,
lastMode
;
// 0:no; network 1: ap; 2: ste
mutex
mutMode
;
const
string
apdCfgPath
=
"/etc/apd.conf"
;
const
string
apdCfgPath
=
"/etc/apd.conf"
;
const
string
wpaCfgPath
=
"/etc/wpa_supplicant/wpa_supplicant-wlan1.conf"
;
const
string
wpaCfgPath
=
"/etc/wpa_supplicant/wpa_supplicant-wlan1.conf"
;
...
@@ -60,8 +62,7 @@ class WifiMgr {
...
@@ -60,8 +62,7 @@ class WifiMgr {
if
(
mode
==
1
)
{
if
(
mode
==
1
)
{
// ap
// ap
// stop all
spdlog
::
info
(
"evwifi {} prepare to enter AP mode"
,
devSn
);
spdlog
::
info
(
"prepare to enter AP mode"
);
// exec("systemctl dsiable wpa_supplicant@wlan1 ")
// exec("systemctl dsiable wpa_supplicant@wlan1 ")
string
apdContent
=
fmt
::
format
(
"interface=wlan1
\n
driver=nl80211
\n
ssid=EVB-{}
\n
hw_mode=g
\n
"
string
apdContent
=
fmt
::
format
(
"interface=wlan1
\n
driver=nl80211
\n
ssid=EVB-{}
\n
hw_mode=g
\n
"
"channel=6
\n
macaddr_acl=0
\n
ignore_broadcast_ssid=0
\n
wpa=0
\n
"
,
this
->
info
[
"sn"
].
get
<
string
>
());
"channel=6
\n
macaddr_acl=0
\n
ignore_broadcast_ssid=0
\n
wpa=0
\n
"
,
this
->
info
[
"sn"
].
get
<
string
>
());
...
@@ -72,23 +73,24 @@ class WifiMgr {
...
@@ -72,23 +73,24 @@ class WifiMgr {
// start hostapd
// start hostapd
auto
t
=
thread
([](){
auto
t
=
thread
([](){
system
(
"pkill hostapd;systemctl stop wpa_supplicant@wlan1;ifconfig wlan1 down;"
system
(
"pkill hostapd;systemctl stop wpa_supplicant@wlan1;ifconfig wlan1 down;"
"ifconfig wlan1 up;ifconfig wlan1 192.168.0.1;hostapd /etc/apd.conf -B"
);
"ifconfig wlan1 up;ifconfig wlan1 192.168.0.1;hostapd /etc/apd.conf -B"
);
// TODO: check result
// TODO: check result
});
});
t
.
detach
();
t
.
detach
();
}
else
{
}
else
{
ret
[
"code"
]
=
1
;
ret
[
"code"
]
=
1
;
string
msg
=
fmt
::
format
(
"failed to write ap config file to {}"
,
apdCfgPath
);
string
msg
=
fmt
::
format
(
"failed to write ap config file to {}"
,
apdCfgPath
);
spdlog
::
error
(
msg
);
spdlog
::
error
(
"evwifi {} {}"
,
devSn
,
msg
);
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
}
}
}
else
if
(
mode
==
2
)
{
}
else
if
(
mode
==
2
)
{
// station mode
// station mode
spdlog
::
info
(
"
prepare to enter Station mode"
);
spdlog
::
info
(
"
evwifi {} prepare to enter Station mode"
,
devSn
);
if
(
wifiData
[
"wifi"
].
count
(
"ssid"
)
==
0
||
wifiData
[
"wifi"
][
"ssid"
].
size
()
==
0
||
if
(
wifiData
[
"wifi"
].
count
(
"ssid"
)
==
0
||
wifiData
[
"wifi"
][
"ssid"
].
size
()
==
0
||
wifiData
[
"wifi"
].
count
(
"password"
)
==
0
||
wifiData
[
"wifi"
][
"password"
].
size
()
==
0
)
{
wifiData
[
"wifi"
].
count
(
"password"
)
==
0
||
wifiData
[
"wifi"
][
"password"
].
size
()
==
0
)
{
string
msg
=
fmt
::
format
(
"no valid ssid/password provided"
);
string
msg
=
fmt
::
format
(
"no valid ssid/password provided"
);
spdlog
::
error
(
msg
);
spdlog
::
error
(
"evwifi {} {}"
,
devSn
,
msg
);
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
ret
[
"code"
]
=
3
;
ret
[
"code"
]
=
3
;
}
}
...
@@ -100,18 +102,21 @@ class WifiMgr {
...
@@ -100,18 +102,21 @@ class WifiMgr {
wpaFile
<<
wpaContent
;
wpaFile
<<
wpaContent
;
wpaFile
.
close
();
wpaFile
.
close
();
// TODO: verify
// TODO: verify
auto
t
=
thread
([](){
auto
t
=
thread
([
this
](){
// delay for rest return (ifdown caused no networking available)
// delay for rest return (ifdown caused no networking available)
this_thread
::
sleep_for
(
chrono
::
seconds
(
1
));
this_thread
::
sleep_for
(
chrono
::
seconds
(
1
));
system
(
"pkill hostapd; pkill dhclient;systemctl enable wpa_supplicant@wlan1;systemctl restart wpa_supplicant@wlan1;"
system
(
"pkill hostapd; pkill dhclient;systemctl enable wpa_supplicant@wlan1;systemctl restart wpa_supplicant@wlan1;"
"/sbin/ifdown -a --read-environment;/sbin/ifup -a --read-environment;systemctl restart evdaemon"
);
"/sbin/ifdown -a --read-environment"
);
auto
s
=
exec
(
"/sbin/ifup -a --read-environment"
);
spdlog
::
info
(
"evwifi {} ifup:
\n
{}"
,
this
->
devSn
,
s
);
system
(
"systemctl restart evdaemon"
);
});
});
t
.
detach
();
t
.
detach
();
}
else
{
}
else
{
string
msg
=
fmt
::
format
(
"failed write wpa config to {}"
,
wpaCfgPath
);
string
msg
=
fmt
::
format
(
"failed write wpa config to {}"
,
wpaCfgPath
);
ret
[
"code"
]
=
2
;
ret
[
"code"
]
=
2
;
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
spdlog
::
error
(
msg
);
spdlog
::
error
(
"evwifi {} {}"
,
devSn
,
msg
);
}
}
}
}
}
}
...
@@ -122,6 +127,8 @@ class WifiMgr {
...
@@ -122,6 +127,8 @@ class WifiMgr {
public
:
public
:
WifiMgr
(){
WifiMgr
(){
LVDB
::
getSn
(
this
->
info
);
LVDB
::
getSn
(
this
->
info
);
devSn
=
this
->
info
[
"sn"
];
mode
=
0
;
wifiData
[
"info"
]
=
this
->
info
;
wifiData
[
"info"
]
=
this
->
info
;
wifiData
[
"wifi"
]
=
json
();
wifiData
[
"wifi"
]
=
json
();
wifiData
[
"wifi"
][
"ssids"
]
=
json
();
wifiData
[
"wifi"
][
"ssids"
]
=
json
();
...
@@ -134,15 +141,23 @@ class WifiMgr {
...
@@ -134,15 +141,23 @@ class WifiMgr {
// get wlan1 ip
// get wlan1 ip
// ping outside address
// ping outside address
// default is AP mode
// this->lastMode = 0;
this
->
lastMode
=
0
;
while
(
1
){
while
(
1
){
// // check modes
// check wifi interface
// this->mode = 1;
{
// if(this->lastMode != this->mode) {
lock_guard
<
mutex
>
lk
(
mutMode
);
// enableMode(this->mode);
auto
s
=
exec
(
"ifconfig wlan1|grep -v inet6|grep inet"
);
// }
if
(
s
.
empty
()
&&
this
->
mode
!=
1
)
{
// this->lastMode = this->mode;
spdlog
::
info
(
"evwifi {} detects no wifi connection, enabling AP mode"
,
this
->
devSn
);
this
->
enableMode
(
1
);
this
->
mode
=
1
;
this
->
scanWifi
();
}
// TODO: flash light
}
this_thread
::
sleep_for
(
chrono
::
seconds
(
10
));
this_thread
::
sleep_for
(
chrono
::
seconds
(
10
));
}
}
});
});
...
@@ -168,7 +183,7 @@ class WifiMgr {
...
@@ -168,7 +183,7 @@ class WifiMgr {
string
password
=
req
.
get_param_value
(
"password"
);
string
password
=
req
.
get_param_value
(
"password"
);
if
(
ssid
.
empty
()
||
password
.
empty
()){
if
(
ssid
.
empty
()
||
password
.
empty
()){
string
msg
=
fmt
::
format
(
"no valid ssid/password provided"
);
string
msg
=
fmt
::
format
(
"no valid ssid/password provided"
);
spdlog
::
error
(
msg
);
spdlog
::
error
(
"evwifi {} {}"
,
devSn
,
msg
);
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
ret
[
"code"
]
=
3
;
ret
[
"code"
]
=
3
;
}
else
{
}
else
{
...
@@ -185,7 +200,7 @@ class WifiMgr {
...
@@ -185,7 +200,7 @@ class WifiMgr {
string
msg
=
fmt
::
format
(
"exception in convert mode {} to int:{}"
,
mode
,
e
.
what
());
string
msg
=
fmt
::
format
(
"exception in convert mode {} to int:{}"
,
mode
,
e
.
what
());
ret
[
"code"
]
=
-
1
;
ret
[
"code"
]
=
-
1
;
ret
[
"msg"
]
=
msg
;
ret
[
"msg"
]
=
msg
;
spdlog
::
error
(
msg
);
spdlog
::
error
(
"evwifi {} {}"
,
devSn
,
msg
);
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论