Added the wifi network scan interface

This commit is contained in:
anschrammh 2022-09-28 23:27:55 +02:00
parent 5dd667e1d5
commit 4841bb8dff
2 changed files with 64 additions and 27 deletions

View File

@ -5,14 +5,14 @@
<style>
body
{
display: flex;
/*display: flex;
min-height: 100vh;
flex-direction: column;
flex-direction: column;*/
}
section
{
flex: 1 0 auto;
/*flex: 1 0 auto;*/
}
.switch label input[type=checkbox]:checked+.lever
@ -178,20 +178,17 @@
<span id="localIP"></span>
</div>
</div>
<select>
<option value="" disabled selected>Select a network</option>
<option value="1">Network 1</option>
<option value="2">Network 2</option>
<option value="3">Network 3</option>
<select id="networksSelect">
<option value="" disabled selected>Click on scan</option>
</select>
<input placeholder="Password" id="pwd" type="password" class="validate white-text">
</div>
<div class="card-action">
<button class="btn waves-effect waves-light green darken-3" type="submit" name="apply">
Apply &#10004;
<button class="btn waves-effect waves-light green darken-3" type="submit" name="apply">
Connect
</button>
<button class="btn waves-effect waves-light red darken-3" style="" type="submit" name="cancel">
Cancel &#10008;
<button class="btn waves-effect waves-light lime darken-3" style="" onclick="scanAvailableNetworks();" type="submit" name="Scan">
Scan
</button>
</div>
</div>

View File

@ -4,6 +4,9 @@
* Anatole SCHRAMM-HENRY - Th3maz1ng
**/
//Dev variables
var deviceIPAddr = 'http://192.168.43.46'
//Global variables
var App = new Object();
var tabInstance = null;
@ -102,12 +105,12 @@ function init()
elemById('datepicker_id').value = day+'-'+month+'-'+year;
/*Initializing the App object*/
App.init();
App.registerAutomatedRequest({timeout:5000, pollInterval: 1000, apiEndPoint:'/sab/rtc/get/datetime', gotResponse:(data) => {rtcRefreshHandler(data, 'OK');}, gotError:(e) => {rtcRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 10000, apiEndPoint:'/sab/systeminfo', gotResponse:(data) => {sysInfoRefreshHandler(data, 'OK');}, gotError:(e) => {sysInfoRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 1000, apiEndPoint:'/sab/wifi/stainfo', gotResponse:(data) => {staInfoRefreshHandler(data, 'OK');}, gotError:(e) => {staInfoRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 5000, apiEndPoint:'/sab/io/get/mode', gotResponse:(data) => {ioModeRefreshHandler(data, 'OK');}, gotError:(e) => {ioModeRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 1000, apiEndPoint:'/sab/io/get/level', gotResponse:(data) => {ioLevelRefreshHandler(data, 'OK');}, gotError:(e) => {ioLevelRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 10000, apiEndPoint:'/sab/power/info', gotResponse:(data) => {powerInfoRefreshHandler(data, 'OK');}, gotError:(e) => {powerInfoRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 1000, apiEndPoint:deviceIPAddr + '/sab/rtc/get/datetime', gotResponse:(data) => {rtcRefreshHandler(data, 'OK');}, gotError:(e) => {rtcRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 10000, apiEndPoint:deviceIPAddr + '/sab/systeminfo', gotResponse:(data) => {sysInfoRefreshHandler(data, 'OK');}, gotError:(e) => {sysInfoRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 1000, apiEndPoint:deviceIPAddr + '/sab/wifi/stainfo', gotResponse:(data) => {staInfoRefreshHandler(data, 'OK');}, gotError:(e) => {staInfoRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 5000, apiEndPoint:deviceIPAddr + '/sab/io/get/mode', gotResponse:(data) => {ioModeRefreshHandler(data, 'OK');}, gotError:(e) => {ioModeRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 1000, apiEndPoint:deviceIPAddr + '/sab/io/get/level', gotResponse:(data) => {ioLevelRefreshHandler(data, 'OK');}, gotError:(e) => {ioLevelRefreshHandler(e, 'FAIL');}});
App.registerAutomatedRequest({timeout:5000, pollInterval: 10000, apiEndPoint:deviceIPAddr + '/sab/power/info', gotResponse:(data) => {powerInfoRefreshHandler(data, 'OK');}, gotError:(e) => {powerInfoRefreshHandler(e, 'FAIL');}});
//All requests needing an UI action:
setFrequencyReq = App.buildXMLHttpRequest({timeout:2000, gotResponse:(data) => {setFreqHandler(data, 'OK');}, gotError:(e) => {setFreqHandler(e, 'FAIL');}});
@ -116,6 +119,7 @@ function init()
sdCardActionReq = App.buildXMLHttpRequest({timeout:2000, gotResponse:(data) => {CardActionHandler(data, 'OK');}, gotError:(e) => {CardActionHandler(e, 'FAIL');}});
setIoModeReq = App.buildXMLHttpRequest({timeout:2000, gotResponse:(data) => {setIoModeHandler(data, 'OK');}, gotError:(e) => {setIoModeHandler(e, 'FAIL');}});
setIoLevelReq = App.buildXMLHttpRequest({timeout:2000, gotResponse:(data) => {setIoLevelHandler(data, 'OK');}, gotError:(e) => {setIoLevelHandler(e, 'FAIL');}});
scanNetworkReq = App.buildXMLHttpRequest({timeout:2000, gotResponse:(data) => {scanAvailableNetworksHandler(data, 'OK');}, gotError:(e) => {scanAvailableNetworksHandler(data, 'FAIL');}});
}
//Callback functions
@ -341,12 +345,42 @@ function getCardSizeHandler(data,kind)
}
}
function scanAvailableNetworksHandler(data, kind)
{
if(kind === 'OK')
{
var networkScanObj = JSON.parse(data);
var networksSelect = elemById('networksSelect');
for(var i = 0; i < networksSelect.options.length; i++)
{
networksSelect.remove(0);
}
for(var network in networkScanObj)
{
console.log(network);
var opt = document.createElement("option");
opt.text = networkScanObj[network].SSID + '(' + networkScanObj[network].RSSI + ') ' + (networkScanObj[network].Protected === 'Yes' ? 'protected' : 'open');
opt.value = networkScanObj[network].SSID;
networksSelect.add(opt);
}
elems = document.querySelectorAll('select');
instances = M.FormSelect.init(elems);
}
else
{
}
}
//All UI action functions are here
function setCpuFrequ(freq)
{
console.log('cpu frequ : '+freq);
setFrequencyReq.open('GET', '/sab/power/set/freq?FREQ='+freq);
setFrequencyReq.open('GET', deviceIPAddr + '/sab/power/set/freq?FREQ='+freq);
setFrequencyReq.send();
}
@ -357,7 +391,7 @@ function setRtc2BrowserTime()
console.log(data);
setRTCReq.open('GET', '/sab/rtc/set/datetime?datetime='+data);
setRTCReq.open('GET', deviceIPAddr + '/sab/rtc/set/datetime?datetime='+data);
setRTCReq.send();
}
@ -373,13 +407,13 @@ function setRtcTime()
let data = parseInt(dtArray[0])+'_'+parseInt(dtArray[1])+'_'+parseInt(dtArray[2])+'_'+parseInt(tiArray[0])+'_'+parseInt(tiArray[1])+'_0';
console.log(data);
setRTCReq.open('GET', '/sab/rtc/set/datetime?datetime='+data);
setRTCReq.open('GET', deviceIPAddr + '/sab/rtc/set/datetime?datetime='+data);
setRTCReq.send();
}
function sdCardSize()
{
sdCardSizeReq.open('GET','/sab/sdcard/size');
sdCardSizeReq.open('GET',deviceIPAddr + '/sab/sdcard/size');
sdCardSizeReq.send();
}
@ -387,12 +421,12 @@ function mountUnmountCard(id)
{
if(elemById(id).checked) //We should mount the sd card
{
sdCardActionReq.open('GET','/sab/sdcard/action?action=mount');
sdCardActionReq.open('GET',deviceIPAddr + '/sab/sdcard/action?action=mount');
sdCardActionReq.send();
}
else //We unmount it
{
sdCardActionReq.open('GET','/sab/sdcard/action?action=unmount');
sdCardActionReq.open('GET',deviceIPAddr + '/sab/sdcard/action?action=unmount');
sdCardActionReq.send();
}
}
@ -400,17 +434,23 @@ function mountUnmountCard(id)
function setIoMode(pin,mode)
{
var pinOnly = pin.split('_')[0];
setIoModeReq.open('GET',"/sab/io/set/mode?"+pinOnly+'='+ (mode == 'OUTPUT' ? 'OUT' : 'IN'));
setIoModeReq.open('GET',deviceIPAddr + "/sab/io/set/mode?"+pinOnly+'='+ (mode == 'OUTPUT' ? 'OUT' : 'IN'));
setIoModeReq.send();
}
function setIoLevel(pin,mode)
{
var pinOnly = pin.split('_')[0];
setIoLevelReq.open('GET',"/sab/io/set/level?"+pinOnly+'='+ (mode == 'HIGH' ? '1' : '0'));
setIoLevelReq.open('GET',deviceIPAddr + "/sab/io/set/level?"+pinOnly+'='+ (mode == 'HIGH' ? '1' : '0'));
setIoLevelReq.send();
}
function scanAvailableNetworks()
{
scanNetworkReq.open('GET', deviceIPAddr + "/sab/wifi/scanner");
scanNetworkReq.send();
}
App = {
init:function()
@ -424,7 +464,7 @@ App = {
if(!connected)
{
console.log('Sending heartbeat');
heartBeatAjx.open('GET', '/sab/web/apitester');
heartBeatAjx.open('GET', deviceIPAddr + '/sab/web/apitester');
heartBeatAjx.send();
}
},5000);