Is it possible to make a connection to a certain Wi Fi network as a condition?
-
Is it possible to do so?
if <Connecting to a specific wifi network>:
ActionI did the following on Raspberry Pi:
import subprocess
from time import sleeptry:
ssid = subprocess.check_output(["iwgetid", "-r"]).rstrip()
except subprocess.CalledProcessError:
ssid = ""while True:
if ssid.decode('ascii') == 'mySSID':
print("connect")
else:
print("No connection")
sleep(1)But this does not work for Omega-2
-
@CAP-33 I typed "iwgetid" at the command line and was told "command not found". This while running the old f/w.
Ask yourself these questions:
- Which f/w version are you running? Command is not supported in f/w b160.
- Did you intend to use "iwinfo"? If so, it doesn't have a "-r" option.
- Is there a specific s/w package you need to install to get the command you desire?
take care!
Bill
-
This post is deleted!
-
@William-Scott said in Is it possible to make a connection to a certain Wi Fi network as a condition?:
iwinfo
I entered:
iwinfo -h
And received:
Usage:
iwinfo <device> info
iwinfo <device> scan
iwinfo <device> txpowerlist
iwinfo <device> freqlist
iwinfo <device> assoclist
iwinfo <device> countrylist
iwinfo <device> htmodelist
iwinfo <backend> phyname <section>
What is <device>?
What is f / w and s / w?
-
@CAP-33 said in Is it possible to make a connection to a certain Wi Fi network as a condition?:
What is <device>?
type ifconfig then you see all your devices.
what you look for is apcli0iwinfo apcli0 info
-
@Fabian-Nydegger-0
Thank you. I wrote like this:import subprocess from time import sleep ssid = subprocess.call(["uci","get","wireless.@wifi-iface[0].ApCliSsid"]) while True: if ssid == 'myssid': print("Connect") print(ssid) else: print("No nonnection") print(ssid) sleep(1)
But instead of
myssid
was output1
-
my fault
you need subprocess.check_ouput()import subprocess from time import sleep ssid = subprocess.check_output(["uci","get","wireless.@wifi-iface[0].ApCliSsid"]) while True: if ssid == 'myssid' + '\n': print("Connect") print(ssid) else: print("No nonnection") print(ssid) sleep(1)
-
@Fabian-Nydegger-0
Sorry, an error occurs.uci: Entry not found Traceback (most recent call last): File "/root/Wi-fi.py", line 5, in <module> ssid = subprocess.check_output(["uci","get","wireless.@wifi-iface[0].ApCliSsid"]) File "/usr/lib/python3.6/subprocess.py", line 336, in check_output **kwargs).stdout File "/usr/lib/python3.6/subprocess.py", line 418, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['uci', 'get', 'wireless.@wifi-iface[0].ApCliSsid']' returned non-zero exit status 1.
-
@CAP-33 said in Is it possible to make a connection to a certain Wi Fi network as a condition?:
uci: Entry not found
That means uci dind't find the enrty in the config file
tryuci show wireless
look for the entry that shows your ssid, it'll have a .ApCliSsid at the end.
copy that path and use it.
-
@Fabian-Nydegger-0
I found the line:
wireless.@wifi-config[0].ssid='myssid'
But I did not find a single line that ends in.ApCliSsid
-
It looks like @Fabian-Nydegger-0 's code is meant for firmware b160 and older.
As of b174, the wifi configuration syntax has changed, that's likely why you're running into issues, @CAP-33
-
@Lazar-Demin
I'm using b183
-
@CAP-33 ya, so you're on the the new wifi config syntax as well as on the new wifi warp core.
The warp core works differently than the previous wifi, and actually does what you're looking for, if I've understood your posts correctly.An Omega with warp core works more like how your laptop or smartphone work with wifi networks:
- stores configuration data for networks you've previously configured
- attempts to automatically connect to configured networks that are in range
All the details can be found here: https://onion.io/2bt-brand-new-os-release/
-
This post is deleted!
-
@CAP-33 I know better than to not spell out acronyms or abbreviations on first use - my bad!
Firmware (f/w)
Software (s/w)
Hardware (h/w)take care!
Bill
-
@Lazar-Demin
When I upgraded the firmware I encountered some problems. I had to reset the firmware to the factory settings and set everything up again. And finally, I updated my Omega to the latest version, as described in the link left by you, but still the code written above does not work for me.
-
@CAP-33
It looks like your script is meant for a system that must be explicitly told which network to connect to. You don't need to worry about that on the Omega.
As I mentioned above, in the new firmware (b176 and up) the wifi driver actually automatically does what you're trying to do with a script.It stores configuration data for networks you've previously configured, and automatically connects to available networks. If there's multiple configured networks in range, it will connect to the network that is listed higher in the
/etc/config/wireless
configuration file. So the list of configured networks works like a preference list (kind of like how Mac OS does their Wifi networking).If you want to manually trigger a network reconnect, just run the
wifi
command.
-
@Lazar-Demin
Perhaps you misunderstood what I'm trying to achieve. I'm trying to achieve that when Omega connects to a particular network, it performs the specified action.
-
@CAP-33 Lol yeah, you're right.
You can useiwinfo
to grab the name of the network to which you're currently connected:root@Omega-66FF:~# iwinfo apcli0 info apcli0 ESSID: "MyNetworkName" ....
If you don't feel like doing multi-line text manipulation in Python, you can isolate the network name as well:
root@Omega-66FF:~# iwinfo apcli0 info | grep ESSID | awk '{print $3}' | sed -e 's/"//g' MyNetworkName
-
@Lazar-Demin
Thank you. That's what I need.