简体   繁体   中英

Javascript list available connections

I'm trying to list all available connections my raspberry pi can find in a dropdown list, with the intention to connect to the one selected.

I found a library which should fit my needs however i just can't wrap my head around it. node-wireless

Here is the html code:

<script type="text/javascript" src="../js/wifilist.js"></script>
<label for="inputlg">WiFi Connections</label>
<select>
    <option value="list_wifi()"></option>
</select>

and my javascript file

var wireless = new Wireless({
    iface: 'wlan0',
    updateFrequency: 10, // Optional, seconds to scan for networks
    connectionSpyFrequency: 2, // Optional, seconds to scan if connected
    vanishThreshold: 2 // Optional, how many scans before network considered gone
});




function list_wifi() {
    wireless.enable(function(err) {
        wireless.start();
        console.log(wireless.start());
    });
}

screenshot of the app: interface

Connecting your Raspberry to a Wifi network can't be done from the browser, since the browser doesn't have access to such information. Even though it was possible your implementation would still not make much sense, because if you would open that webpage not locally from your Pi's browser but from another PC, it wouldn't show the connection of the Pi but those of that PC. You need to build a server (eg in Node.js in order to use that library), that fetches a list of connetions, prints them to a webpage and handles HTTP requests from the webpage to establish the connection. So basically you will need both a small backend and a frontend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM