Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
0cd902f6
提交
0cd902f6
authored
11月 26, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new feature: evwifi
上级
70796d4f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
46 行增加
和
8 行删除
+46
-8
evwifi.cpp
opencv-motion-detect/evwifi.cpp
+46
-8
没有找到文件。
opencv-motion-detect/evwifi.cpp
浏览文件 @
0cd902f6
#include "inc/httplib.h"
#include "inc/httplib.h"
#include "inc/zmqhelper.hpp"
#include "inc/zmqhelper.hpp"
#include "inc/json.hpp"
#include "inc/json.hpp"
#include "inc/fs.h"
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
#include "fmt/format.h"
#include "fmt/format.h"
#include "database.h"
#include "database.h"
...
@@ -43,10 +44,12 @@ class WifiMgr {
...
@@ -43,10 +44,12 @@ class WifiMgr {
json
wifiData
;
json
wifiData
;
int
mode
,
lastMode
;
// 0:no; network 1: ap; 2: ste
int
mode
,
lastMode
;
// 0:no; network 1: ap; 2: ste
mutex
mutMode
;
mutex
mutMode
;
int
mode1Cnt
=
0
;
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"
;
void
scanWifi
(){
void
scanWifi
(){
lock_guard
<
mutex
>
lk
(
mutMode
);
string
res
=
exec
(
"iwlist wlan1 scan|grep ESSID"
);
string
res
=
exec
(
"iwlist wlan1 scan|grep ESSID"
);
wifiData
[
"wifi"
][
"ssids"
].
clear
();
wifiData
[
"wifi"
][
"ssids"
].
clear
();
httplib
::
detail
::
split
(
&
res
[
0
],
&
res
[
res
.
size
()],
'\n'
,
[
&
](
const
char
*
b
,
const
char
*
e
)
{
httplib
::
detail
::
split
(
&
res
[
0
],
&
res
[
res
.
size
()],
'\n'
,
[
&
](
const
char
*
b
,
const
char
*
e
)
{
...
@@ -152,29 +155,64 @@ class WifiMgr {
...
@@ -152,29 +155,64 @@ class WifiMgr {
// ping outside address
// ping outside address
// this->lastMode = 0;
// this->lastMode = 0;
while
(
1
){
while
(
1
){
// check wifi interface
// check wifi interface
{
{
lock_guard
<
mutex
>
lk
(
mutMode
);
auto
s
=
exec
(
"ifconfig wlan1|grep -v inet6|grep inet"
);
auto
s
=
exec
(
"ifconfig wlan1|grep -v inet6|grep inet"
);
if
(
s
.
empty
()
&&
this
->
mode
==
0
)
{
if
(
s
.
empty
())
{
spdlog
::
info
(
"evwifi {} detects no wifi connection, enabling AP mode"
,
this
->
devSn
);
// switch to ap automatically
this
->
enableMode
(
1
);
if
(
this
->
mode
==
0
)
{
this
->
mode
=
1
;
spdlog
::
info
(
"evwifi {} detects no wifi connection, enabling AP mode"
,
this
->
devSn
);
this
->
scanWifi
();
this
->
enableMode
(
1
);
}
else
if
(
this
->
mode
==
1
)
{
// maybe give it a try to switch into mode2 is not a bad idea
this
->
mode1Cnt
++
;
if
(
fs
::
exists
(
fs
::
path
(
wpaCfgPath
))
&&
mode1Cnt
%
600
){
spdlog
::
info
(
"evwifi {} give it a try to mode2, since configuration exists."
,
this
->
devSn
);
this
->
enableMode
(
2
);
}
}
}
else
{
// maybe mode1
if
(
this
->
mode
==
1
)
{
//
}
else
if
(
this
->
mode
==
2
){
//
}
else
if
(
this
->
mode
==
0
)
{
// try to mode2
if
(
fs
::
exists
(
fs
::
path
(
wpaCfgPath
))
&&
mode1Cnt
%
600
){
spdlog
::
info
(
"evwifi {} maybe crashed before, try connect wifi"
,
this
->
devSn
);
this
->
enableMode
(
2
);
}
else
{
// mode1
spdlog
::
info
(
"evwifi {} has wifi ip, but no configuration, this should never happen. switch to AP mode"
,
this
->
devSn
);
this
->
enableMode
(
1
);
}
}
else
{
spdlog
::
error
(
"evwifi {} invalid mode: {}, switch to AP mode"
,
this
->
devSn
,
this
->
mode
);
this
->
enableMode
(
1
);
}
}
/// background scanning
this
->
scanWifi
();
if
(
this
->
mode
!=
1
)
{
this
->
mode1Cnt
=
0
;
}
}
// TODO: flash light
// TODO: flash light
}
}
this_thread
::
sleep_for
(
chrono
::
seconds
(
1
0
));
this_thread
::
sleep_for
(
chrono
::
seconds
(
6
0
));
}
}
});
});
monitor
.
detach
();
monitor
.
detach
();
srv
.
Get
(
"/wifi"
,
[
this
](
const
Request
&
req
,
Response
&
res
)
{
srv
.
Get
(
"/wifi"
,
[
this
](
const
Request
&
req
,
Response
&
res
)
{
this
->
mode1Cnt
=
0
;
string
mode
=
req
.
get_param_value
(
"mode"
);
string
mode
=
req
.
get_param_value
(
"mode"
);
json
ret
;
json
ret
;
ret
[
"code"
]
=
0
;
ret
[
"code"
]
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论