Update 
I changed my HP MicroServer Gen8 from running Windows Server 2016 directly to an ESXi host with NextCloud, Win Server 2016 and another openHAB instance.
This second oH instance has an Gigabit network port and can run the speedtest-cli
at full speed.
The next step was to get the Speedtest running and send the results to my main oH instance.
openHAB-Speedtest
val String filename = "speedtest.rules"
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 5,13 * * ?" or
Time cron "0 0 * * * ?" or
Item SpeedtestRerun changed from OFF to ON or
Item SpeedtestRerun received command ON
then
logInfo(filename, "--> speedtest executed...")
SpeedtestRunning.postUpdate("Messung läuft...")
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestRunning/state", "text/plain", "Messung läuft...")
// update timestamp for last execution
val String ResultDate = "" + new DateTimeType()
SpeedtestResultDate.postUpdate(ResultDate)
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestResultDate/state", "text/plain", ResultDate.toString)
// execute the script, you may have to change the path depending on your system
var String speedtestCliOutput = executeCommandLine("/usr/local/bin/speedtest-cli@@--simple", 120*1000)
// for debugging:
//var String speedtestCliOutput = "Ping: 43.32 ms\nDownload: 21.64 Mbit/s\nUpload: 4.27 Mbit/s"
//logInfo(filename, "--> speedtest output:\n" + speedtestCliOutput + "\n\n")
SpeedtestRunning.postUpdate("Datenauswertung...")
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestRunning/state", "text/plain", "Datenauswertung...")
// starts off with a fairly simple error check, should be enough to catch all problems I can think of
if (speedtestCliOutput.startsWith("Ping") && speedtestCliOutput.endsWith("Mbit/s"))
{
var String[] results = speedtestCliOutput.split("\\r?\\n")
var float ping = new java.lang.Float(results.get(0).split(" ").get(1))
var float down = new java.lang.Float(results.get(1).split(" ").get(1))
var float up = new java.lang.Float(results.get(2).split(" ").get(1))
SpeedtestResultPing.postUpdate(ping)
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestResultPing/state", "text/plain", ping.toString)
SpeedtestResultDown.postUpdate(down)
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestResultDown/state", "text/plain", down.toString)
SpeedtestResultUp.postUpdate(up)
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestResultUp/state", "text/plain", up.toString)
SpeedtestSummary.postUpdate(String::format("ᐁ %.1f Mbit/s ᐃ %.1f Mbit/s (%.0f ms)", down, up, ping))
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestSummary/state", "text/plain", String::format("ᐁ %.1f Mbit/s ᐃ %.1f Mbit/s (%.0f ms)", down, up, ping))
SpeedtestRunning.postUpdate("-")
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestRunning/state", "text/plain", "-")
logInfo(filename, "--> speedtest finished.")
}
else
{
SpeedtestResultPing.postUpdate(0)
SpeedtestResultDown.postUpdate(0)
SpeedtestResultUp.postUpdate(0)
SpeedtestSummary.postUpdate("(unbekannt)")
sendHttpPutRequest("http://192.168.2.11:8080/rest/items/SpeedtestSummary/state", "text/plain", "Error")
SpeedtestRunning.postUpdate("Fehler bei der Ausführung")
logError(filename, "--> speedtest failed. Output:\n" + speedtestCliOutput + "\n\n")
}
SpeedtestRerun.postUpdate(OFF)
end
openHAB2 main
val String filename = "speedtest.rules"
rule "Speedtest"
when
Item SpeedtestRerun received command ON
then
SpeedtestRunning.postUpdate("Messung gestartet...")
sendHttpPutRequest("http://192.168.2.111:8080/rest/items/SpeedtestRerun/state", "text/plain", "ON")
SpeedtestRerun.postUpdate(OFF)
end
rule "Speedtest Fehler"
when
Item SpeedtestSummary changed to "Error"
then
logError(filename, "--> Speedtest fehlgeschlagen\nFehler auf openHAB-Speedtest (http://192.168.2.111:9001/) einsehbar")
sendTelegram("bot1", "--> Speedtest fehlgeschlagen\nFehler auf openHAB-Speedtest (http://192.168.2.111:9001/) einsehbar")
end
Things to do:
- Install InfluxDB and Grafana
kind regards
Michael