It is currently March 29th, 2024, 6:30 am

Want to automatically switch between active Wifi

Get help with creating, editing & fixing problems with skins
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Want to automatically switch between active Wifi

Post by DanielPodo »

Hey all,

it's been a while and I haven't touched Rainmeter for quite some time. I want to get back into it and design some new skins but I really forgotten a ton of stuff, plus the last version I used was 3, not 4, so have no clue what's new (yet!).

For the time being, I'm trying to polish off some skins I designed last year to get to grips with everything again. I've started by updating my Wifi widgets, so that they can automatically display information about whichever Wifi adaptor I have active (currently using a laptop with both inbuilt Wifi and a USB dongle).

Currently my code looks like this...

Code: Select all

[Variables]
@include=#@#Styles.inc
WiFiConnection=0

; **********************************
; MEASURES 
; **********************************

[CheckWifi]
Measure=Calc
IfCondition=MeasureWifiSSID = -1
IfTrueAction=!SetVariable WifiConnection 1
DynamicVariables=1

[MeasureWifidB]
Measure=Plugin
Group=Wifi
Plugin=WiFiStatus
WiFiInfoType=Quality
WiFiIntfID=#WiFiConnection#
IfCondition=MeasureWifidB >= 90
IfTrueAction=[!SetOption meterWifiIcon ImageName "#@#Images\Wifi\WifiFull"]
IfCondition2=(MeasureWifidB < 90) && (MeasureWifidB >= 80)
IfTrueAction2=[!SetOption meterWifiIcon ImageName "#@#Images\Wifi\WifiStrong"]
IfCondition3=(MeasureWifidB < 80) && (MeasureWifidB >= 70)
IfTrueAction3=[!SetOption meterWifiIcon ImageName "#@#Images\Wifi\WifiMedium"]
IfCondition4=MeasureWifidB < 70
IfTrueAction4=[!SetOption meterWifiIcon ImageName "#@#Images\Wifi\WifiWeak"]
IfCondition5=MeasureWifidB = 0
IfTrueAction5=[!SetOption meterWifiIcon ImageName "#@#Images\Wifi\WifiOff"]
OnChangeAction=[!Update][!Refresh]

[MeasureWifiSSID]
Measure=Plugin
Plugin=WiFiStatus
WiFiInfoType=SSID
WiFiIntfID=#WiFiConnection#
Substitute="0":"No Wifi"

[MeasureWifiAuth]
Measure=Plugin
Plugin=WiFiStatus
WiFiInfoType=AUTH
WiFiIntfID=#WiFiConnection#
Substitute="0":"-"

; ----------------------------------
; METERS
; ----------------------------------

[meterWifiIcon]
Meter=Image
W=50
SolidColor=0,0,0,1
LeftMouseUpAction=[Shell:::{8E908FC9-BECC-40f6-915B-F4CA0E70D03D}]
ToolTipText=[MeasureWifidB] dB
DynamicVariables=1

[meterWifiInfo]
meter=String
MeasureName=MeasureWifiSSID
MeasureName2=MeasureWifiAuth
MeterStyle=SmallText
X=5R
Y=8
Text=%1#CRLF#%2
ClipString=1
I figured that if I receive a "-1" if the Wifi adaptor the widget is trying to get information from isn't active, I can get the widget to recognise that and switch the WifiConnection variable to the other active Wifi adaptor. It's not working...have I done something silly? Is it possible to somehow simplify the code and just use some conditional expression for a variable?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Want to automatically switch between active Wifi

Post by jsmorley »

You need to use DynamicVariables=1 where you "use" the variable #WiFiConnection#, not where you set it.
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Re: Want to automatically switch between active Wifi

Post by DanielPodo »

jsmorley wrote:You need to use DynamicVariables=1 where you "use" the variable #WiFiConnection#, not where you set it.
Hmm, thanks for reminding me that, however, adding it to the other measures which use the variable doesn't change a thing. Still doesn't work.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Want to automatically switch between active Wifi

Post by jsmorley »

Dunno. I don't have two WiFi adapters to test with. As far as I can tell, it finds the correct ID number, or at least returns valid data for my WiFI, no matter what I put for the ID.

With one adapter, I really can't test. What the plugin does when it see that there in in fact a functioning adapter at ID #0, is to just ralph up an error message in the log when I set the ID to anything else, then just ignore my setting and use the adapter at ID #0.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Want to automatically switch between active Wifi

Post by balala »

Same as jsmorley, neither me have two WiFi adapters, so also can't test. But I saw something in your code and want to tell: the IfCondition set on the [CheckWifi] measure doesn't work, because the [MeasureWifiSSID] measure returns not a numeric value, but a string instead. The IfCondition won't never see the condition met, so the according IfTrueAction will never be executed. Try to replace the IfCondition with the following one: IfCondition=([MeasureWifiSSID]=-1) (here I also removed some spaces and added parentheses). Important is to convert the string value of the measure to a number, which is done by include its name between brackets. This step also requires the DynamicVariables=1 option, but this is already added to the measure, so it's ok.
But I don't see the importance of the [CheckWifi] measure. In fact its meaning is just to have where to set up the IfCondition. I would move the IfCondition (as it is) to the [MeasureWifiSSID] measure and would completely remove the [CheckWifi] measure.
Also note that once the WifiConnection variable is set to 1, it never gets back its initial value of 0. I'm not sure it should have to, but maybe it should. If it should, maybe an IfFalseAction near the IfTrueAction could help.
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Re: Want to automatically switch between active Wifi

Post by DanielPodo »

balala wrote:Same as jsmorley, neither me have two WiFi adapters, so also can't test. But I saw something in your code and want to tell: the IfCondition set on the [CheckWifi] measure doesn't work, because the [MeasureWifiSSID] measure returns not a numeric value, but a string instead. The IfCondition won't never see the condition met, so the according IfTrueAction will never be executed. Try to replace the IfCondition with the following one: IfCondition=([MeasureWifiSSID]=-1) (here I also removed some spaces and added parentheses). Important is to convert the string value of the measure to a number, which is done by include its name between brackets. This step also requires the DynamicVariables=1 option, but this is already added to the measure, so it's ok.
But I don't see the importance of the [CheckWifi] measure. In fact its meaning is just to have where to set up the IfCondition. I would move the IfCondition (as it is) to the [MeasureWifiSSID] measure and would completely remove the [CheckWifi] measure.
Also note that once the WifiConnection variable is set to 1, it never gets back its initial value of 0. I'm not sure it should have to, but maybe it should. If it should, maybe an IfFalseAction near the IfTrueAction could help.
So I took your points into account and did the following:

Code: Select all

[MeasureWifiSSID]
Measure=Plugin
Plugin=WiFiStatus
WiFiInfoType=SSID
WiFiIntfID=#WiFiConnection#
IfCondition=([MeasureWifiSSID]=-1)
IfTrueAction=!SetVariable WiFiConnection 1
;Substitute="-1":"No Wifi"
DynamicVariables=1
;UpdateDivider=-1
However, what this does is cause the widget to "blink", with the correct info for a fleeting moment before simply displaying -1 for the SSID again. For some reason, though, the [MeasureWifiAuth] measure gives a good static result and isn't flashing/changing. Any ideas?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Want to automatically switch between active Wifi

Post by balala »

DanielPodo wrote:However, what this does is cause the widget to "blink", with the correct info for a fleeting moment before simply displaying -1 for the SSID again. For some reason, though, the [MeasureWifiAuth] measure gives a good static result and isn't flashing/changing. Any ideas?
I don't know, but I can't replicate your issue. Maybe because, as I said, I have one single WiFi adapter?
For any case, please post the actual whole code once again.
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Re: Want to automatically switch between active Wifi

Post by DanielPodo »

balala wrote:I don't know, but I can't replicate your issue. Maybe because, as I said, I have one single WiFi adapter?
For any case, please post the actual whole code once again.
Hey, sorry for the late reply, I've got a ton of personal stuff going on and this has meant I've got barely any time to work on Rainmeter (or even scratch my butt, for that matter). I have a hunch I know what's going on, so I'll mess around with the code and get back to you guys soon :)
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Re: Want to automatically switch between active Wifi

Post by DanielPodo »

HOLY THREAD REVIVAL BATMAN

Right! Sorry it's taken so long to get this done, life can get in the way sometimes...

So as it turns out, how the plugin WifiStatus behaves depends on how the Wifi adaptors are organised within Windows. I had a feeling there was more to just the rainmeter code when sometimes the widget would perform perfectly well, and sometimes it would not, no matter what I did.

Whichever adaptor is "active" first becomes WiFiIntfID = 0, then the next one becomes 1, etc etc. This is why when I plugged in my USB WiFi adaptor AFTER turning on Windows, the widget wouldn't work.
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: Want to automatically switch between active Wifi

Post by fonpaolo »

Probably this happens only to me, however, if I don't have any WiFi active when Rainmeter is loaded after my computer is started, then no WiFi is available until I restart Rainmeter (refreshing it does nothing).
At least one WiFi connection must be active (even if not connected) before Rainmeter starts, so, as I do, plug your USB WiFi before you turn on your computer.