get wifi channel for currently connected AP?

Post your questions and help other users.

Moderator: Martin

Post Reply
crackers8199
Posts: 14
Joined: 03 May 2017 18:20

get wifi channel for currently connected AP?

Post by crackers8199 » 18 Aug 2017 23:25

is there a way to do this? i know about the wifi available condition to get the frequency, but that only uses the highest signal strength with the given SSID...i want to know the channel i'm currently connected to. i'm trying to set up a wifi information widget with ssid, bssid, channel and signal strength...but i haven't been able to figure out how to get the currently connected channel.

also, in the alternative, is there an easy way to get the data from tasker to automagic? tasker can get the wifi channel number, but i can't figure out how to get that into automagic...although i'd really rather if there were a way to do it from automagic itself, since it's so much easier to use. i've been playing with tasker for 30 minutes or so and i want to rip my hair out already...

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: get wifi channel for currently connected AP?

Post by Desmanto » 19 Aug 2017 06:49

I never knew that we can get the detail wifi info from the condition : wifi available. I tested the trigger and action, turns out it is the condition which has the detail info. Thanks for pointing out, nice info. This is why i love to visit this forum, always learn something new. :idea:

If you have the frequency already, you can calculate the channel from that. The frequency shown is the center frequency. More detail in wikipedia. 2.4 GHz Channel Frequency
First, create a map to hold the frequency to channel mapping. Then pass the frequency to that map to get the channel.

Code: Select all

freqcha = newMapFromValues(
2412, 1,
2417, 2,
2422, 3,
2427, 4,
2432, 5,
2437, 6,
2442, 7,
2447, 8,
2452, 9,
2457, 10,
2462, 11,
2467, 12,
2472, 13,
2484, 14
);
channel = getMapValue(freqcha, frequency);
I purposely make the map multiline, so it is easier to read. freqcha just shortened from frequency channel :D The result in is variable {channel} (maybe Martin can add this built-in directly in that condition)
There is 5 GHz channel as well. If you need it, you can also map it using the data from Wikipedia.
You can use action Map Values to create the map too. But I prefer to do it in script, to get the best perfomance. Every additional elements in automagic can add 100-150 ms latency. (I shall explain this later in flow sharing)

BTW, when I created the map, i finally get the idea about the mapping. I already rip my hair too, thinking way how to use the script just like Vlookup table in excel. Turns out, I can use several maps, each map has the key the same as the key for vlookup, and the value correspond to each column in the table. So if I have a table with 5 column (1st column is the lookup), I need to create 4 maps. Later, use the getMapValue() to lookup the value in each map to get that row. What a wonderful enlightment! :idea: Sorry to posted it here, I am too excited that I've finally sorted it out. :mrgreen:

If you wanna pass variable from tasker to automagic, you can use send intent in tasker + trigger general broadcast in automagic.
http://automagic4android.com/forum/view ... f=5&t=6868
But you don't have to now, since it can be done in automagic already. ;)
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

crackers8199
Posts: 14
Joined: 03 May 2017 18:20

Re: get wifi channel for currently connected AP?

Post by crackers8199 » 21 Aug 2017 13:00

Yes like I said I know about mapping it from the frequency...the problem is that it only returns the strongest AP, which may or may not be the one we are currently connected to.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: get wifi channel for currently connected AP?

Post by Desmanto » 21 Aug 2017 15:18

Sorry, it seems I miss the point before, got too excited about the mapping.

Now I understand that the frequency shown at the variable, not always the one connected, but only the strongest from available.
Do you scan will all SSID, or you limit to certain one?
How may BSSID you have with the same SSID?
I tried with only two available channel here (different SSID and BSSID), 1 and 11. I am connected to 1. I move my phone stick to the channel 11 wifi, so the signal is -18 dBm, channel 1 only -36 dBm. When I execute the flow, still show channel 1. So it still shows the connected one for me. But i haven't tested with multiple BSSID in the same location. Tomorrow I will tested it out.

BTW, how do you get the channel in tasker. I can't find the option (or maybe too easy to give up now with tasker)
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

massaquah
Posts: 6
Joined: 21 Feb 2017 09:36

Re: get wifi channel for currently connected AP?

Post by massaquah » 29 Aug 2017 13:40

Any news on this topic?

Did anyone find a way to display the channel of the wifi actually CONNECTED to?

Mesh networks like Linksys Velop, Netgear Orbi, Google Wifi use the same SSID for multiple frequencys (2.4 ghz and 5 ghz) and multiple bssids (nodes).

I would like to create a persistent notification displaying the channel and frequency of the currently connected wifi.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: get wifi channel for currently connected AP?

Post by Desmanto » 29 Aug 2017 15:47

So far I have tested with same SSID, it will give info from random AP with the same SSID.
http://automagic4android.com/forum/view ... f=4&t=6900

Maybe the feature need to be implemented is to use BSSID as the option in scanning or connected (has been requested).
If we can limit the scan to certain BSSID, then using the data from the trigger, we can be sure it is the connected bssid, thus the channel can be calculated.

You can try to the wifi scan and see how your phone behave when it sees multiple AP with same SSID.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply