Just a quick note to let you know I have this up and running on Windows…it was fairly easy…
I downloaded the appropriate version of the CLI for Windows
As of now I have removed the charting as I wanted to get the basic functionality working.
My Items:
Group gSpeedtest <"speedtest">
String SpeedtestSummary "Speedtest [%s]" <"speedtest_summary"> (gSpeedtest)
Number SpeedtestResultPing "Ping [%.3f ms]" <"speedtest_ping"> (gSpeedtest)
Number SpeedtestResultDown "Download [%.2f Mbit/s]" <"speedtest_download"> (gSpeedtest)
Number SpeedtestResultUp "Upload [%.2f Mbit/s]" <"speedtest_upload"> (gSpeedtest)
String SpeedtestRunning "Speedtest Running ... [%s]" <"speedtest_run"> (gSpeedtest)
Switch SpeedtestRerun "Start Manually" <"speedtest_reload"> (gSpeedtest)
DateTime SpeedtestResultDate "Last Run [%1$td.%1$tm.%1$tY, %1$tH:%1$tM Uhr]" <"speedtest_date"> (gSpeedtest)
String SpeedtestResultError "Error Message [%s]" <"speedtest_error"> (gSpeedtest)
String SpeedtestResultImage "Image"
My Rules:
val String ruleId = "Speedtest"
val Number calc = 125000 // Converting from bits to Mbits
rule "Speedtest init"
when
System started
then
createTimer(now.plusSeconds(195))
[|
if(SpeedtestRerun.state == NULL)
{
SpeedtestRerun.postUpdate(OFF)
}
if(SpeedtestRunning.state == NULL)
{
SpeedtestRunning.postUpdate("-")
}
if(SpeedtestSummary.state == NULL || SpeedtestSummary.state == "")
{
SpeedtestSummary.postUpdate("⁉ (unbekannt)")
}
]
end
rule "Speedtest"
when
Time cron "0 0/15 * * * ?" or
Item SpeedtestRerun changed from OFF to ON or
Item SpeedtestRerun received command ON
then
//logInfo(ruleId, "--> speedtest executed...")
SpeedtestRunning.postUpdate("Measurement in Progress...")
// execute the script, you may have to change the path depending on your system
// Please use -f json and not -f json-pretty
val speedtestExecute = "D:/Tools/Speedtest/speedtest.exe -f json"
var speedtestCliOutput = executeCommandLine(speedtestExecute, 120*1000)
// for debugging:
// var String speedtestCliOutput = "Ping: 43.32 ms\nDownload: 21.64 Mbit/s\nUpload: 4.27 Mbit/s"
//logInfo(ruleId, "--> speedtest output:\n" + speedtestCliOutput + "\n\n")
SpeedtestRunning.postUpdate("Data Analysis...")
// starts off with a fairly simple error check, should be enough to catch all problems I can think of
if (speedtestCliOutput.startsWith("{\"type\":\"result\",") && speedtestCliOutput.endsWith("}}"))
{
var ping = Float::parseFloat(transform("JSONPATH", "$.ping.latency", speedtestCliOutput))
SpeedtestResultPing.postUpdate(ping)
var float down = Float::parseFloat(transform("JSONPATH", "$.download.bandwidth", speedtestCliOutput))
down = (down / calc)
SpeedtestResultDown.postUpdate(down)
var float up = Float::parseFloat(transform("JSONPATH", "$.upload.bandwidth", speedtestCliOutput))
up = (up / calc)
SpeedtestResultUp.postUpdate(up)
var String url = transform("JSONPATH", "$.result.url", speedtestCliOutput)
val img = url + ".png"
SpeedtestResultImage.postUpdate(img)
SpeedtestSummary.postUpdate(String::format("ᐁ %.1f Mbit/s ᐃ %.1f Mbit/s (%.0f ms)", down, up, ping))
SpeedtestRunning.postUpdate("-")
// update timestamp for last execution
val String ResultDate = "" + new DateTimeType()
SpeedtestResultDate.postUpdate(ResultDate)
}
else
{
SpeedtestResultPing.postUpdate(0)
SpeedtestResultDown.postUpdate(0)
SpeedtestResultUp.postUpdate(0)
SpeedtestSummary.postUpdate("(unknown)")
SpeedtestRunning.postUpdate("Error")
logError(ruleId, "--> speedtest failed. Output:\n" + speedtestCliOutput + "\n\n")
}
SpeedtestRerun.postUpdate(OFF)
end
On line 47 note how the path to the .exe is created…you also must add the entire path to the executable in the exec.whitelist file if you are running on 2.5.2
My rendered sitemap
Only things left to do are:
1, Change time and date display
2. Figure out why my Gigabit services is only showing 246Mb on the download.
3. Make HabPanel widget
Squid