Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
59d6a686
提交
59d6a686
authored
11月 28, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new feature: evwifi
上级
f3569e56
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
57 行增加
和
93 行删除
+57
-93
evwifi.cpp
opencv-motion-detect/evwifi.cpp
+54
-59
index.vue
opencv-motion-detect/web/main/pages/wifisettings/index.vue
+2
-2
sw.js
opencv-motion-detect/web/main/static/sw.js
+1
-32
没有找到文件。
opencv-motion-detect/evwifi.cpp
浏览文件 @
59d6a686
...
...
@@ -51,7 +51,18 @@ class WifiMgr {
void
scanWifi
(){
lock_guard
<
mutex
>
lk
(
mutMode
);
string
res
=
exec
(
"iwlist wlan1 scan|grep ESSID"
);
/// get sn
LVDB
::
getSn
(
this
->
info
);
devSn
=
this
->
info
[
"sn"
];
/// get wifi mac & IP
auto
mac
=
exec
(
"ifconfig wlan1|grep ether|awk '{print $2}'"
);
auto
ip
=
exec
(
"ifconfig wlan1|grep -v inet6|grep inet|awk '{print $2}'"
);
wifiData
[
"wifi"
][
"ip"
]
=
ip
;
wifiData
[
"mac"
]
=
mac
;
// scan wifi
string
res
=
exec
(
"iwlist wlan1 scan|grep ESSID|awk {'print $1'}"
);
wifiData
[
"wifi"
][
"ssids"
].
clear
();
httplib
::
detail
::
split
(
&
res
[
0
],
&
res
[
res
.
size
()],
'\n'
,
[
&
](
const
char
*
b
,
const
char
*
e
)
{
string
ssid
;
...
...
@@ -162,7 +173,7 @@ class WifiMgr {
while
(
1
){
// check wifi interface
{
auto
s
=
exec
(
"ifconfig wlan1|grep -v inet6|grep inet"
);
auto
s
=
exec
(
"ifconfig wlan1|grep -v inet6|grep inet
|awk '{print $2}'
"
);
if
(
s
.
empty
())
{
// switch to ap automatically
if
(
this
->
mode
==
0
)
{
...
...
@@ -173,73 +184,57 @@ class WifiMgr {
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
))){
if
(
mode1Cnt
%
600
==
0
){
// read password
string
line
;
ifstream
wpaCfgFile
(
wpaCfgPath
);
int
flag
=
0
;
if
(
wpaCfgFile
.
is_open
())
{
// ssid="iLabService"
// psk="ILABSERVICE666666"
string
ssidName
=
"ssid=
\"
(.+)
\"
"
;
//"/(\\w+)/ipcs/(\\d+)(?:/[^/]+)?";
string
password
=
"psk=
\"
(.+)
\"
"
;
regex
ssidReg
(
ssidName
);
regex
passwdReg
(
password
);
// read password
string
line
;
ifstream
wpaCfgFile
(
wpaCfgPath
);
int
flag
=
0
;
if
(
wpaCfgFile
.
is_open
())
{
// ssid="iLabService"
// psk="ILABSERVICE666666"
string
ssidName
=
"ssid=
\"
(.+)
\"
"
;
//"/(\\w+)/ipcs/(\\d+)(?:/[^/]+)?";
string
password
=
"psk=
\"
(.+)
\"
"
;
regex
ssidReg
(
ssidName
);
regex
passwdReg
(
password
);
std
::
smatch
results
;
while
(
getline
(
wpaCfgFile
,
line
))
{
if
(
regex_match
(
line
,
results
,
ssidReg
))
{
if
(
results
.
size
()
==
2
)
{
this
->
wifiData
[
"wifi"
][
"ssid"
]
=
results
[
1
].
str
();
flag
++
;
}
}
else
if
(
regex_match
(
line
,
results
,
passwdReg
))
{
if
(
results
.
size
()
==
2
)
{
this
->
wifiData
[
"wifi"
][
"password"
]
=
results
[
1
].
str
();
flag
++
;
}
}
}
wpaCfgFile
.
close
();
std
::
smatch
results
;
while
(
getline
(
wpaCfgFile
,
line
))
{
if
(
regex_match
(
line
,
results
,
ssidReg
))
{
if
(
results
.
size
()
==
2
)
{
this
->
wifiData
[
"wifi"
][
"ssid"
]
=
results
[
1
].
str
();
flag
++
;
}
}
else
if
(
regex_match
(
line
,
results
,
passwdReg
))
{
if
(
results
.
size
()
==
2
)
{
this
->
wifiData
[
"wifi"
][
"password"
]
=
results
[
1
].
str
();
flag
++
;
}
}
}
if
(
flag
==
2
)
{
spdlog
::
info
(
"evwifi {} maybe crashed before, try connect wifi"
,
this
->
devSn
);
this
->
enableMode
(
2
);
}
wpaCfgFile
.
close
();
}
}
else
{
// mode1
spdlog
::
info
(
"evwifi {} has wifi ip, but no configuration, this should never happen. switch to AP mode"
,
this
->
devSn
);
this
->
enableMode
(
1
);
if
(
flag
==
2
)
{
spdlog
::
info
(
"evwifi {} try reconnect wifi using existing config"
,
this
->
devSn
);
this
->
enableMode
(
2
);
}
}
}
}
else
{
// having wifi ip
if
(
s
==
"192.168.0.1"
){
this
->
mode
=
1
;
}
else
if
(
fs
::
exists
(
fs
::
path
(
wpaCfgPath
))){
this
->
mode
=
2
;
}
else
{
spdlog
::
error
(
"evwifi {} invalid mode: {}, switch to AP mode"
,
this
->
devSn
,
this
->
mode
);
spdlog
::
info
(
"evwifi {} invalid state(having wifi IP but no config), switch to AP mode"
,
this
->
devSn
);
this
->
enableMode
(
1
);
}
}
/// background scanning
/// background
wifi
scanning
this
->
scanWifi
();
if
(
this
->
mode
!=
1
)
{
this
->
mode1Cnt
=
0
;
}
// TODO: flash light
}
...
...
opencv-motion-detect/web/main/pages/wifisettings/index.vue
浏览文件 @
59d6a686
...
...
@@ -61,7 +61,7 @@
<
script
>
import
axios
from
"axios"
;
const
apiHost
=
''
;
const
apiHost
=
'
http://192.168.1.104
'
;
export
default
{
async
mounted
()
{
try
{
...
...
@@ -103,7 +103,7 @@ export default {
this.devSn = this.wifiData.info.sn;
this.bInScan = false;
console.log(this.devSn);
console.log(this.
ssids
);
console.log(this.
wifiData
);
},
cancelDisabled: false,
connDisabled: false,
...
...
opencv-motion-detect/web/main/static/sw.js
浏览文件 @
59d6a686
importScripts
(
'https://cdn.jsdelivr.net/npm/workbox-cdn@4.3.1/workbox/workbox-sw.js'
)
// --------------------------------------------------
// Configure
// --------------------------------------------------
// Set workbox config
workbox
.
setConfig
({
"debug"
:
false
})
// Start controlling any existing clients as soon as it activates
workbox
.
core
.
clientsClaim
()
// Skip over the SW waiting lifecycle stage
workbox
.
core
.
skipWaiting
()
workbox
.
precaching
.
cleanupOutdatedCaches
()
// --------------------------------------------------
// Precaches
// --------------------------------------------------
// Precache assets
// --------------------------------------------------
// Runtime Caching
// --------------------------------------------------
// Register route handlers for runtimeCaching
workbox
.
routing
.
registerRoute
(
new
RegExp
(
'/_nuxt/'
),
new
workbox
.
strategies
.
CacheFirst
({}),
'GET'
)
workbox
.
routing
.
registerRoute
(
new
RegExp
(
'/'
),
new
workbox
.
strategies
.
NetworkFirst
({}),
'GET'
)
// THIS FILE SHOULD NOT BE VERSION CONTROLLED
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论