It is currently April 28th, 2024, 5:41 pm

Some internet connection check related porblems

Get help with creating, editing & fixing problems with skins
User avatar
haibusa2005
Posts: 52
Joined: June 15th, 2011, 7:23 pm
Location: Bulgaria, Varna

Some internet connection check related porblems

Post by haibusa2005 »

I am writing a network monitor in two parts - the first one checks if there is an active network connection at all and the second checks if user is currently connected to a wireless network. I have reverted to the network measurement since the ping plugin was returning unusable results if connection was enabled, then disabled and enabled again or if skin was refreshed without active internet connection - the plugin didn't reset, just returned TimeoutValue and that's all. I will be glad if some posts a workaround for this problem since I haven't found an acceptable solution.

So back to the skin explanation - the first part checks the network traffic - if incoming speed is lower than 42 b/s the connection is considered inactive, so network speed monitors are hidden and in their place is displayed a meter that says that there isn't an active network connection. The other part tracks if user is connected to a WiFi network by checking the quality measurement - if quality is 0 the WiFi is considered disconnected. A transparent "mouse hover" controller image is displayed or hidden depending on the quality measure. If an active WiFi connection is available, the stats are displayed. My problem is that once WiFi has been disabled by hardware button (the WiFi adapter is physically disconnected) the stats aren't updating at skin rate but at some third party rate (around 5 seconds) which I assume is from the windows API and can't be controlled because users will get some funny status readings. I seek some help for a workaround this five second update gap - once the adapter is turned off I want the controller image to disappear instantly. It's... maddening. My code is bellow.

Ping testing code
[GetPing]
UpdateRate=1
Measure=Plugin
Plugin=PingPlugin
DestAddress=google.com
Timeout=300
TimeoutValue=0

[CheckIfConnectedToInternet]
Measure=Calc
Formula=GetPing
IfEqualValue=0
IfBelowAction=!Execute [!HideMeterGroup NetworkSpeeds] [!ShowMeter NoInternetConnection] [!Update]
IfAboveValue=0
IfAboveAction=!Execute [!ShowMeterGroup NetworkSpeeds] [!HideMeter NoInternetConnection] [!Update]
Current code
[GetWiFiQuality]
Measure=Plugin
Plugin=WiFiStatus
WiFiInfoType=Quality

[GetIncomingTrafficSpeed]
Measure=NetIn

[CheckIfConnectedToInternet]
Measure=Calc
Formula=GetIncomingTrafficSpeed
IfBelowValue=1
IfBelowAction=!Execute [!HideMeterGroup NetworkSpeeds] [!ShowMeter NoInternetConnection] [!Update]
IfAboveValue=42
IfAboveAction=!Execute [!ShowMeterGroup NetworkSpeeds] [!HideMeter NoInternetConnection] [!Update]

[CheckWiFiConnection]
Measure=Calc
Formula=GetWiFiQuality
IfEqualValue=0
IfEqualAction=!Execute [!HideMeter WiFiStatsHoverControl] [!Update]
IfAboveValue=0
IfAboveAction=!Execute [!ShowMeter WiFiStatsHoverControl] [!Update]

[WiFiStatsHoverControl]
Meter=Image
SolidColor=0,0,0,100
x=560
y=177
w=200
h=83
MouseOverAction=!Execute [!SetVariable NetworkStatsFadeMain "#MaxFadeValueMain#"] [!SetVariable NetworkStatsFadeSeparators "#MaxFadeValueSeparators#"] [!Update]
MouseLeaveAction=!Execute [!SetVariable NetworkStatsFadeMain 0] [!SetVariable NetworkStatsFadeSeparators 0] [!Update]
Hidden=1

[NetworkStatsIncoming]
Meter=String
MeasureName=GetIncomingTrafficSpeed
FontFace=Calibri
FontSize=14
AntiAlias=1
FontColor=255,255,255,255
StringAlign=Left
AutoScale=1
NumOfDecimals=1
x=565
y=R
Text=#NetworkStatsIncomingText# %1B/s
Group=NetworkSpeeds
Hidden=1

[NoInternetConnection]
Meter=String
FontFace=Calibri
FontSize=16
AntiAlias=1
FontColor=255,128,128,255
StringAlign=Left
ClipString=1
x=565
y=205
w=195
h=52
Text=#NoInternetConnection#
Hidden=1
User avatar
Church Punk
Posts: 25
Joined: September 17th, 2010, 9:26 am

Re: Some internet connection check related porblems

Post by Church Punk »

What i have done is to check Wifi strength first, then ping; using these rules:

If wifi is disconnected then wifi-measure disables ping-measure.
If wifi is connected then wifi-measure enables ping-measure.
If ping-measure receives a time out it then enables wifi-measure.
If ping receives normal responce then it keeps refreshing until it gets a time out again and disables wifi-measure.

With this i have 3 status: Not connected to network - Connected but no interneted - Connected WITH internet.
The only problem that it presents is that you can get temporaly banned if you ping a site way too often, thus making the workaround useless (so refresh the ping measure less often).

Code: Select all

[MeasureStrength]
Measure=Plugin
Plugin=WifiStatus.dll
WifiInfoType=QUALITY
UpdateDivider=2

[MeasureTextWiFi]
Measure=Calc
Formula=MeasureStrength
IfEqualAction=!Execute [!RainmeterSetVariable Wireless "9"][!RainmeterSetVariable NETcolor "253, 55, 55"][!RainmeterDisableMeasure MeasurePing][!RainmeterDisableMeasure MeasureCalcPing[!RainmeterShowMeter MeterConnected][!RainmeterHideMeter MeterInternet][!RainmeterRedraw]
IfEqualValue=0
IfAboveAction=!Execute [!RainmeterSetVariable Wireless "'"][!RainmeterSetVariable NETcolor "255, 238, 0"][!RainmeterEnableMeasure MeasurePing][!RainmeterEnableMeasure MeasureCalcPing][!RainmeterRedraw]
IfAboveValue=0
UpdateDivider=2
Disabled=0

[MeasurePing]
Measure=Plugin
Plugin=Plugins\PingPlugin
DestAddress=www.google.com
Timeout=5000
TimoutValue=0
UpdateRate=20
Disabled=1

[MeasureCalcPing]
Measure=Calc
Formula=MeasurePing
IfEqualAction=!Execute [!RainmeterShowMeter MeterConnected][!RainmeterHideMeter MeterInternet][!RainmeterEnableMeasure MeasureTextWiFi][!RainmeterRedraw]
IfEqualValue=0
IfAboveAction=!Execute [!RainmeterHideMeter MeterConnected][!RainmeterShowMeter MeterInternet][!RainmeterDisableMeasure MeasureTextWiFi][!RainmeterRedraw]
IfAboveValue=1
UpdateRate=20
Disabled=1
As you can see, i have 2 meters to help me with this. One has 2 states: Wifi disconnected/connected; the other just the one: Internet. Wifi measure enables or disables ping measure AND defines wether the first status meter is connected or disconnected. If Ping gets a time out it hides the internet meter and shows the wifi connection meter, if it gets normal responce it hides the wifi connection meter and shows the internet meter.

Its kinda complicated, but is the only way arround i could figure out. Is messy, but it does the job 90% of the time :p
Image
User avatar
haibusa2005
Posts: 52
Joined: June 15th, 2011, 7:23 pm
Location: Bulgaria, Varna

Re: Some internet connection check related porblems

Post by haibusa2005 »

Thank you for your code, but the algorithm uo have provided doesn't consider a wired connection - you can have ping even if wifi quality is 0 and you can be connected to a LAN via wifi
User avatar
haibusa2005
Posts: 52
Joined: June 15th, 2011, 7:23 pm
Location: Bulgaria, Varna

Re: Some internet connection check related porblems

Post by haibusa2005 »

I have found a way to get under consideration if computer is connected to internet by WiFi or cable and if computer is part of LAN trough WiFi. However there is some problem with the check calc and I can't see what it is. Rainmeter log says extra operation which I think is a typo in the formula but I can't see it. Here is my code

Code: Select all

[WebParserInternet]
Measure=Plugin
Plugin=WebParser
URL=http://www.isup.me
RegExp="(?siU)<meta http-equiv="content-type" content="text/html; charset=utf-(.*)"/>.*"
UpdateRate=1
UpdateDivider=8
ErrorString="-1"
Substitute="8":"1","":"-1"
StringIndex=1
ForceReload=1

[PingInternet]
Measure=Plugin
Plugin=PingPlugin
DestAddress=google.com
UpdateRate=1
UpdateDivider=4
Timeout=300
TimeoutValue=-1

[CheckIfConnectedToInternet]
Measure=Calc
;11111 -> refresh
;22222 -> no internet
;33333 -> internet
Formula=PingInternet=-1?(WebParserInternet=1?11111:22222):(PingInternet=0?22222:33333)
IfBelowValue=22221
IfBelowAction=!EnableMeasure RefreshTimer
IfEqualValue=22222
IfEqualAction=!Execute [!HideMeterGroup NetworkSpeeds] [!ShowMeter NoInternetConnection] [!DisableMeasure RefreshTimer] [!Update]
IfAboveValue=22223
IfAboveAction=!Execute [!ShowMeterGroup NetworkSpeeds] [!HideMeter NoInternetConnection] [!DisableMeasure RefreshTimer] [!Update] 

[RefreshTimer]
Measure=Calc
Formula=RefreshTimer+1
IfEqualValue=5
IfEqualAction=!Refresh
Disabled=1

User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Some internet connection check related porblems

Post by MerlinTheRed »

Try PingInternet=(-1)? Calcs are crazy like that
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
haibusa2005
Posts: 52
Joined: June 15th, 2011, 7:23 pm
Location: Bulgaria, Varna

Re: Some internet connection check related porblems

Post by haibusa2005 »

Thanks a lot, sage ;)

Here is the final code that works
[WebParserInternet]
Measure=Plugin
Plugin=WebParser
URL=http://www.isup.me
RegExp="(?siU)<meta http-equiv="content-type" content="text/html; charset=utf-(.*)"/>.*"
UpdateRate=1
UpdateDivider=8
ErrorString="-1"
Substitute="8":"1","":"-1"
StringIndex=1
ForceReload=1

[PingInternet]
Measure=Plugin
Plugin=PingPlugin
DestAddress=google.com
UpdateRate=1
UpdateDivider=4
Timeout=300
TimeoutValue=-1

[CheckIfConnectedToInternet]
DynamicVariables=1
Measure=Calc
;11111 -> refresh
;22222 -> no internet
;33333 -> internet
Formula=[PingInternet]=(-1)?([WebParserInternet]=1?11111:22222):([PingInternet]=0?22222:33333)
IfBelowValue=22221
IfBelowAction=!EnableMeasure RefreshTimer
IfEqualValue=22222
IfEqualAction=!Execute [!HideMeterGroup NetworkSpeeds] [!ShowMeter NoInternetConnection] [!DisableMeasure RefreshTimer] [!Update]
IfAboveValue=22223
IfAboveAction=!Execute [!ShowMeterGroup NetworkSpeeds] [!HideMeter NoInternetConnection] [!DisableMeasure RefreshTimer] [!Update]

[RefreshTimer]
Measure=Calc
Formula=RefreshTimer+1
IfEqualValue=5
IfEqualAction=!Refresh
Disabled=1
User avatar
Church Punk
Posts: 25
Joined: September 17th, 2010, 9:26 am

Re: Some internet connection check related porblems

Post by Church Punk »

Ha this is indeed a more elegant solution than what i have... guess i should implement it in my skin if you dont mind ;)

Thanks for sharing!
Image
User avatar
haibusa2005
Posts: 52
Joined: June 15th, 2011, 7:23 pm
Location: Bulgaria, Varna

Re: Some internet connection check related porblems

Post by haibusa2005 »

Of course, feel free to use it in any way you find suitable. I won't mind if you give me a credit but it's not a must ;)