I am running this script and it updates the status to this:
0 KB/Sec - Average: 0 KB/Sec (0/0)[0/0]
then I get this in the log file:
5/2/2006 8:15:52 PM Info Event Trigger "Bandwith Monitor"
5/2/2006 8:15:52 PM Info Running script in background: Bandwidth.vbs
5/2/2006 8:16:52 PM Info Running script in background: Bandwidth.vbs
5/2/2006 8:17:03 PM Bandwidth.vbs 0 bytes downloaded in 11.17188 seconds (0 KB/sec)
5/2/2006 8:18:12 PM Bandwidth.vbs 0 bytes downloaded in 136.9375 seconds (0 KB/sec)
5/2/2006 8:18:12 PM Bandwidth.vbs 0 bytes downloaded in 140.7969 seconds (0 KB/sec)
Here is the script it is running with the file extension .VBS

then I get this in the log file:
5/2/2006 8:15:52 PM Info Event Trigger "Bandwith Monitor"
5/2/2006 8:15:52 PM Info Running script in background: Bandwidth.vbs
5/2/2006 8:16:52 PM Info Running script in background: Bandwidth.vbs
5/2/2006 8:17:03 PM Bandwidth.vbs 0 bytes downloaded in 11.17188 seconds (0 KB/sec)
5/2/2006 8:18:12 PM Bandwidth.vbs 0 bytes downloaded in 136.9375 seconds (0 KB/sec)
5/2/2006 8:18:12 PM Bandwidth.vbs 0 bytes downloaded in 140.7969 seconds (0 KB/sec)
Here is the script it is running with the file extension .VBS
PHP Code:
' filename : custom_bandwidth.txt
' version : 0.9
' description : measures maximum bandwidth available
' author : Dan (xplosiv)
' email : dannydude at cyberdude dot com
' instructions : 1) copy this script to the homeseer\scripts directory
' : 2) create a new virtual device (description and house/unit code don't matter)
' : 3) assign that house & unit code to the virtualdevice variable in this script
' : 4) create a new event, recurring every 3 minutes (or whatever time interval you like)
' : 5) select custom_cnn.txt to run in the "Scripts/Speech" tab
' : 6) if you wish to enable debugging, add custom_bandwidth.txt("main","debug") instead of just custom_cnn.txt
'
'
' things to do:
' * [0% ] add average (storing values in txt file)
' * [95% ] add INI support
'
'
' Changelog
'
' version 0.9 beta (10262002): created script
' 08.29.03 TBK Changed timestart and timeend to use Timer Function
' instead of Now(). Timer gives us a decimal value w/ seven
' places of accuracy (from midnight) so we can calc a more
' accurate bandwidth speed.
' Added code to disable internet events while test is
' running.
' Added section to store transfer rates to ini key so
' an average can be determined. Added code to calculate
' average.
' 09.05.03 TBK Added code to record high and low transfer rate. Also changed
' to read 'KB/sec' throughout the script to conserve space.
' 12.12.03 JWT Added code to keep track of Windowed High Low and absoluet High and low
Public scriptmode,filesize,fso,ftpserver,ftpuser,ftppass,ftpfile,localfile,s,ftppath,tmp,tmp2,timestart,timeend,btime,bspeed,virtualdevice,mode,treshhold,treshholdmargin,templatelow,templatefast,templatenormal
Public High,Low
Public AbsoluteHigh,AbsoluteLow
Sub Main()
Dim AvgString
Dim Average
Dim Total
Dim KBytes
Dim First
Dim Limit
Dim i
Dim hs
Dim bFinished
Dim Array
On Error Resume Next
Set hs = CreateObject("HomeSeer.Application")
' scriptmode = "debug"
INIprocessor
'
If mode = "ftp" Then
localfile = "bandwidth.test"
dbg "file will be saved as " & localfile
hs.TriggerEvent "Disable Internet Events"
timestart = Timer
s = hs.ftp(ftpserver,ftpuser,ftppass,"get",ftppath,localfile,ftpfile)
timeend = Timer
If s <> "" Then
dbg "[ftp:error] " & s
End If
Set fso = Createobject("scripting.filesystemobject")
If FSO.FileExists(localfile) Then
filesize = fso.GetFile(localfile).Size
Call fso.DeleteFile(localfile,True)
btime = timeend - timestart
If btime = 0 then btime = .1
bspeed = Round(filesize / 1024 / btime)
If bspeed <= (treshhold - treshholdmargin) Then
tmp = replace(templatelow,"%%data%%",bspeed & " KB/Sec")
End If
If bspeed > (treshhold - treshholdmargin) And bspeed < (treshhold + treshholdmargin) Then
tmp = replace(templatenormal,"%%data%%",bspeed & " KB/Sec")
End If
if bspeed >= (treshhold + treshholdmargin) Then
tmp = replace(templatefast,"%%data%%",bspeed & " KB/Sec")
End If
hs.writelog "Bandwidth.vbs", filesize & " bytes downloaded in " & btime & " seconds (" & bspeed & " KB/sec)"
dbg filesize & " bytes downloaded in " & btime & " seconds (" & bspeed & " KB/sec)"
hs.TriggerEvent "Enable Internet Events"
AvgString = Trim(hs.GetINISetting("settings", "Average", "", "bandwidthmonitor.ini"))
AbsoluteHigh = Trim(hs.GetINISetting("settings", "AbsoluteHigh", "", "bandwidthmonitor.ini"))
AbsoluteLow = Trim(hs.GetINISetting("settings", "AbsoluteLow", "", "bandwidthmonitor.ini"))
High = 0
Low = 100000000
Limit = Trim(hs.GetINISetting("settings" , "Limit", "20", "bandwidthmonitor.ini"))
' Calculate Average
If AvgString <> "" Then
' MsgBox AvgString
Array = Split(AvgString,",")
AvgString = ""
i = 0
Do Until bFinished Or (CLng(i) = CLng(Limit))
KBytes = Trim(Array(i))
If i = 0 Then
First = KBytes
Else
If KBytes <> "" Then
Total = Total + CLng(KBytes)
AvgString = AvgString & KBytes & ","
Else
bFinished = True
End If
End If
' MsgBox AvgString
' MsgBox Total
' MsgBox i & " " & Limit
i = i + 1
' See if we should update High or Low values
If CLng(KBytes) > CLng(High) Then
High = CLng(KBytes)
End If
If CLng(KBytes) < CLng(Low) Then
Low = CLng(KBytes)
End If
Loop
' MsgBox i & " " & Limit
If CLng(i) < CLng(Limit) Then
AvgString = First & "," & AvgString
Total = Total + CLng(First)
End If
Total = Total + CLng(bspeed)
' MsgBox "Average = " & Round(Total / i)
' MsgBox "Total = " & Total
' MsgBox "i = " & i
Average = Round(Total / i)
If Average <= (treshhold - treshholdmargin) Then
tmp2 = replace(templatelow,"%%data%%",Average & " KB/Sec")
End If
If Average > (treshhold - treshholdmargin) And Average < (treshhold + treshholdmargin) Then
tmp2 = replace(templatenormal,"%%data%%",Average & " KB/sec")
End If
if Average >= (treshhold + treshholdmargin) Then
tmp2 = replace(templatefast,"%%data%%",Average & " KB/sec")
End If
Average = tmp2
' See if we should update High or Low values
If CLng(bspeed) > CLng(High) Then
High = bspeed
End If
If CLng(bspeed) < CLng(Low) Then
Low = bspeed
End If
' See if we should update AbsoluteHigh or AbsoluteLow values
If CLng(bspeed) > CLng(AbsoluteHigh) Then
AbsoluteHigh = bspeed
End If
If CLng(bspeed) < CLng(AbsoluteLow) Then
AbsoluteLow = bspeed
End If
Else
Average = tmp
High = bspeed
Low = bspeed
AbsoluteHigh = bspeed
AbsoluteLow = bspeed
End If
hs.SetDeviceString virtualdevice, "[img]http://board.homeseer.com/images/DooNetwork/alive.gif[/img]" & " " & tmp & " - Average: " & Average & " (" & Low & "/" & High & ")[" & AbsoluteLow & "/" & AbsoluteHigh & "]", True
hs.SaveINISetting "settings", "Average", AvgString & bspeed & ",", "bandwidthmonitor.ini"
hs.SaveINISetting "settings", "High", High, "bandwidthmonitor.ini"
hs.SaveINISetting "settings", "Low", Low, "bandwidthmonitor.ini"
hs.SaveINISetting "settings", "AbsoluteHigh", AbsoluteHigh, "bandwidthmonitor.ini"
hs.SaveINISetting "settings", "AbsoluteLow", AbsoluteLow, "bandwidthmonitor.ini"
Else
call hs.WriteLog("Bandwidth.vbs","FTP:" & hs.FTPLastError() )
hs.TriggerEvent "Enable Internet Events"
End If
End If
End Sub
Sub INIprocessor()
Dim items
Dim SettingName
Dim inifile
Dim section
Dim audio
SettingName = "settings"
inifile = "bandwidthmonitor.ini"
section = hs.GetINISection(SettingName, inifile)
If section = "" Then
dbg "New installation detected, creating " & inifile
hs.SaveINISetting SettingName,"virtualdevice","v8",inifile
hs.SaveINISetting SettingName,"mode","ftp",inifile
hs.SaveINISetting SettingName,"treshhold","150",inifile
hs.SaveINISetting SettingName,"treshholdmargin","25",inifile
hs.SaveINISetting SettingName,"ftpserver","ibiblio.org",inifile
hs.SaveINISetting SettingName,"ftpfile","Game2.1.0.1B.tar.gz",inifile
hs.SaveINISetting SettingName,"ftppath","/pub/Linux/games",inifile
hs.SaveINISetting SettingName,"ftpuser","anonymous",inifile
hs.SaveINISetting SettingName,"ftppass","guest@",inifile
hs.SaveINISetting SettingName,"templateLow","%%data%%",inifile
hs.SaveINISetting SettingName,"templateNormal","%%data%%",inifile
hs.SaveINISetting SettingName,"templateFast","%%data%%",inifile
hs.SaveINISetting SettingName,"Average","",inifile
hs.SaveINISetting SettingName,"High","",inifile
hs.SaveINISetting SettingName,"Low","",inifile
hs.SaveINISetting SettingName,"AbsoluteHigh","",inifile
hs.SaveINISetting SettingName,"AbsoluteLow","",inifile
hs.SaveINISetting SettingName,"Limit","20",inifile
dbg "Installation Complete"
Else
virtualdevice=hs.GetINISetting(SettingName,"virtualdevice","",inifile)
mode=hs.GetINISetting(SettingName,"mode","",inifile)
treshhold=CLng(hs.GetINISetting(SettingName,"treshhold","1",inifile))
treshholdmargin=CLng(hs.GetINISetting(SettingName,"treshholdmargin","1",inifile))
ftpserver=hs.GetINISetting(SettingName,"ftpserver","",inifile)
ftpfile=hs.GetINISetting(SettingName,"ftpfile","",inifile)
ftppath=hs.GetINISetting(SettingName,"ftppath","",inifile)
ftpuser=hs.GetINISetting(SettingName,"ftpuser","",inifile)
ftppass=hs.GetINISetting(SettingName,"ftppass","",inifile)
templateLow=hs.GetINISetting(SettingName,"templateLow","",inifile)
templateNormal=hs.GetINISetting(SettingName,"templateNormal","",inifile)
templateFast=hs.GetINISetting(SettingName,"templateFast","",inifile)
dbg "[variable:virtualdevice] " & virtualdevice
dbg "[variable:mode] " & mode
dbg "[variable:treshhold] " & treshhold
dbg "[variable:treshholdmargin] " & treshholdmargin
dbg "[variable:ftpserver] " & ftpserver
dbg "[variable:ftppath] " & ftppath
dbg "[variable:ftpuser] " & ftpuser
dbg "[variable:ftppass] " & ftppass
dbg "[variable:templateLow] " & templateLow
dbg "[variable:templateNormal] " & templateNormal
dbg "[variable:templateFast] " & templateFast
End If
End Sub
Sub dbg(data)
If scriptmode = "debug" Then
hs.writelog "BandwidthMonitor", "[debug] " & data
End If
End Sub