提交 59d6a686 authored 作者: blu's avatar blu

new feature: evwifi

上级 f3569e56
...@@ -51,7 +51,18 @@ class WifiMgr { ...@@ -51,7 +51,18 @@ class WifiMgr {
void scanWifi(){ void scanWifi(){
lock_guard<mutex> lk(mutMode); 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(); 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) {
string ssid; string ssid;
...@@ -162,7 +173,7 @@ class WifiMgr { ...@@ -162,7 +173,7 @@ class WifiMgr {
while(1){ while(1){
// check wifi interface // 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()) { if(s.empty()) {
// switch to ap automatically // switch to ap automatically
if(this->mode == 0) { if(this->mode == 0) {
...@@ -173,19 +184,6 @@ class WifiMgr { ...@@ -173,19 +184,6 @@ class WifiMgr {
this->mode1Cnt++; this->mode1Cnt++;
if(fs::exists(fs::path(wpaCfgPath)) && mode1Cnt % 600){ if(fs::exists(fs::path(wpaCfgPath)) && mode1Cnt % 600){
spdlog::info("evwifi {} give it a try to mode2, since configuration exists.", this->devSn); 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 // read password
string line; string line;
ifstream wpaCfgFile(wpaCfgPath); ifstream wpaCfgFile(wpaCfgPath);
...@@ -218,28 +216,25 @@ class WifiMgr { ...@@ -218,28 +216,25 @@ class WifiMgr {
} }
if(flag == 2) { if(flag == 2) {
spdlog::info("evwifi {} maybe crashed before, try connect wifi", this->devSn); spdlog::info("evwifi {} try reconnect wifi using existing config", this->devSn);
this->enableMode(2); 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{ }else{
spdlog::error("evwifi {} invalid mode: {}, switch to AP mode", this->devSn, this->mode); // having wifi ip
if(s == "192.168.0.1"){
this->mode = 1;
}else if(fs::exists(fs::path(wpaCfgPath))){
this->mode = 2;
}else{
spdlog::info("evwifi {} invalid state(having wifi IP but no config), switch to AP mode", this->devSn);
this->enableMode(1); this->enableMode(1);
} }
} }
/// background scanning /// background wifi scanning
this->scanWifi(); this->scanWifi();
if(this->mode != 1) {
this->mode1Cnt = 0;
}
// TODO: flash light // TODO: flash light
} }
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
<script> <script>
import axios from "axios"; import axios from "axios";
const apiHost = ''; const apiHost = 'http://192.168.1.104';
export default { export default {
async mounted() { async mounted() {
try { try {
...@@ -103,7 +103,7 @@ export default { ...@@ -103,7 +103,7 @@ export default {
this.devSn = this.wifiData.info.sn; this.devSn = this.wifiData.info.sn;
this.bInScan = false; this.bInScan = false;
console.log(this.devSn); console.log(this.devSn);
console.log(this.ssids); console.log(this.wifiData);
}, },
cancelDisabled: false, cancelDisabled: false,
connDisabled: false, connDisabled: false,
......
importScripts('https://cdn.jsdelivr.net/npm/workbox-cdn@4.3.1/workbox/workbox-sw.js') // THIS FILE SHOULD NOT BE VERSION CONTROLLED
// --------------------------------------------------
// 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')
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论