Speedtest-cli Internet Up-/Downlink Measurement Integration

(Jason Brunk) #42

I have this installed now as well. I have mysql persistence enabled on everything. I can now graph my speeds/pings

Since I do a lot of work from home stuff, this is interesting data. Just like my drive to the office traffic item.

(Tommy Sharp) #43

Hi guys, are there any tips for getting this to work on a windows environment? I downloaded a speedtest CLI from the link below where they have a windows version. If I run it manually from the windows command line then it works just fine and I see the output.

In my rule I have replaced this in the path…
var String speedtestCliOutput = executeCommandLine(“c:\OpenHAB\speedtest.exe”, 120*1000)

When I hit the button in openhab to do a manual speed test I get an error running the rule.

I’m sure running it on a windows platform will not be as easy as this simple path change so any advice would be appreciated.

( ) #44

Hey Tommy,
it would help to know more details about the error, can you post the output here?

I already included some debugging possibilities for you. Look at these three lines:

// for debugging:
//var String speedtestCliOutput = "Ping: 43.32 ms\nDownload: 21.64 Mbit/s\nUpload: 4.27 Mbit/s"
//logInfo("RULE", "--> speedtest output:\n" + speedtestCliOutput + "\n\n")

The first code line can be used to bypass the actual speedtest command and test the rest of the algorithm. This shouldn’t make any problems but just to make sure, you may want to test that first.

Next, activate the second line to get the output of your command execution. From the information I got from your link, this program has a slightly different output formatting. So you may need to update parsing.

So overall I would guess you need to add --quiet to your command and adopt the .split(...) command. Good luck!

Remember, the newest version of the linux solution can be found here https://github.com/openhab/openhab/wiki/speedtest-cli-integration
Please update the article on windows related differences or tell me here and I will update the wiki :wink:

(Tommy Sharp) #45

Okay, so I enabled your first line which sets the output manually and get this in the error log when I run it…

2016-07-04 16:55:18.198 [INFO ] [org.openhab.model.script.RULE ] - --> speedtest executed...
2016-07-04 16:55:18.603 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Speedtest': Index: 0, Size: 0

UPDATE : No I lie… My stupid error, the rule is now running properly since I have bypassed the actual “exec” of the cli utility. I’ll keep digging and see if I can work out what the issue is…

(Tommy Sharp) #46

This is what I get when I run the actual utility from a command line in windows 7…

github.com/zpeters/speedtest -- unofficial cli for speedtest.net
Server: 2720 - Auckland (WorldNet)
2016/07/04 17:09:37 Testing download speed
2016/07/04 17:09:50 Testing upload speed
Ping (Lowest): 0.00 ms | Download (Max): 65.39 Mbps | Upload (Max): 15.82 Mbps

So it at least works… But I think my line below isn’t running it in the correct way?
var String speedtestCliOutput = executeCommandLine("c:\OpenHAB\speedtest.exe")

Where/what would I need to do for the --quite piece? you mention?

( ) #47

Looking good.
You’ll need to fiddle around a bit. Without testing myself, I think you need to do the following:

First find the right command. What you want is a minimalistic output you’re able to parse easily.

github.com/zpeters/speedtest -- unofficial cli for speedtest.net
Server: 3823 - Ilmenau (Newone)
2016/07/04 13:54:00 Testing download speed
2016/07/04 13:54:04 Testing upload speed
Ping (Lowest): 15.00 ms | Download (Max): 288.06 Mbps | Upload (Max): 6.25 Mbps
.\speedtest-64-v1.0.0.exe --quiet
github.com/zpeters/speedtest -- unofficial cli for speedtest.net
Server: 3823 - Ilmenau (Newone)
Ping (Lowest): 15.00 ms | Download (Max): 343.34 Mbps | Upload (Max): 6.29 Mbps
.\speedtest-64-v1.0.0.exe --report
2016-07-04 13:58:12 +0200|3823|Newone(Ilmenau,Germany)|15.00|290492|6176

As you can see, quiet is not really the best option here. You should go with report. So you problably want to change your code to this: executeCommandLine("c:\OpenHAB\speedtest.exe@@--report", 120*1000) and test the whole thing with the logInfo line from before.

Next you need to adopt the parsing. My guess:

if (speedtestCliOutput.startsWith("201")) { // this is obviously not good practice but okay for now       
        var String[] results = speedtestCliOutput.split("|")
        var float ping = new java.lang.Float(results.get(3))
        var float down = new java.lang.Float(results.get(4))
        var float up   = new java.lang.Float(results.get(5))

Again, use logInfo(...) to find the right settings.

Good luck!

(Scott H.) #48

I tried your parsing code and the split method requires a regex to work, if you change it to:
var String[] results = speedtestCliOutput.split("\\|")
everything works as expected.

@watou @Farhanito @yancym The file locking is not a “bug”, jetty (the web server used in openHAB) on windows loads the files into a mapped buffer for faster loading. This causes the file locking effect you are seeing. If you open your “etc\webdefault.xml” file, and change the parameter “useFileMappedBuffer” to false it will stop this issue. You must restart openHAB for the setting to take effect.

(Tommy Sharp) #49

I still seem to be getting the following error when the rule fires, even with debug logging on… Is there any way to get more info when this happens?

09:24:30.425 [INFO ] [org.openhab.model.script.RULE :53   ] - --> speedtest executed...
09:24:31.314 [ERROR] [o.o.c.s.ScriptExecutionThread :50   ] - Error during the execution of rule 'Speedtest': Index: 0, Size: 0

( ) #50

@scooter_seh could you provide us with your working solution? Thanks :wink:

(Scott H.) #51

My Rule File:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*

rule "Speedtest"
    //Time cron "0 0 5 * * ?" or
    //Time cron "0 0 13 * * ?"
    Time cron "0 0 * * * ?" or
    Item SpeedtestRerun received command ON
then {
    logInfo("RULE", "--> speedtest executed...")
    SpeedtestRunning.postUpdate("Measurement in progress...")

    // update timestamp for last execution
    SpeedtestResultDate.postUpdate(new DateTimeType())

    // execute the script, you may have to change the path depending on your system
    var String speedtestCliOutput = executeCommandLine("c:\\speedtest.exe@@--report", 120*1000)

    // for debugging:

    SpeedtestRunning.postUpdate("data evaluation...")
logInfo("RULE", speedtestCliOutput)
	if (speedtestCliOutput.startsWith("201")) {        
        var String[] results = speedtestCliOutput.split("\\|")
		//logInfo("RULE", results.get(3))
		//logInfo("RULE", results.get(4))
		//logInfo("RULE", results.get(5))
        var float ping = new java.lang.Float(results.get(3))
        var float down = new java.lang.Float(results.get(4))
        var float up   = new java.lang.Float(results.get(5))
        SpeedtestSummary.postUpdate(String::format("ᐁ  %.2f Mbit/s  ᐃ %.2f Mbit/s (%.0f ms)", down/1024, up/1024, ping))
        logInfo("RULE", "--> speedtest finished.")
	} else {
        SpeedtestRunning.postUpdate("Execution error")
        logError("RULE", "--> speedtest failed. Output:\n" + speedtestCliOutput + "\n\n")

( ) #52

Are you sure you are showing MBits?

(Scott H.) #53

I see my mistake, should be kilobits per second or I need to add some math.

(Scott H.) #54

I edited my rule to divide by 1024 to get Mbps. I updated the post above as well. Thanks for the catching my error.

( ) #55

nice. I’ll update the wiki to reflect Windows-needed settings.
Btw, all icons used by me in the sitemap are from this iconset: http://www.iconarchive.com/show/polygon-icons-by-graphicloads.html
Maybe I’ll put an archive containing all of them in the wiki, if you are at it: care to do that?

(Tommy Sharp) #56

Awesome! Thanks @scooter_seh

I can confirm that your rule works on my windows machine, just had to tweak the path to where my exe file was…

(Tommy Sharp) #58

And thanks to you too @ThomDietrich

( ) #59

Short update: the guide in the first posting is up to date with all comments discussed here.

(Dominic Spatz) #60

I had issues with speedtest cli since i moved openhab from my VM to a raspberry pi.
from now on the script needs to check for “Mbits/s”

Modification i did to support both versions:
if (speedtestCliOutput.startsWith("Ping") && (speedtestCliOutput.endsWith("Mbit/s")||speedtestCliOutput.endsWith("Mbits/s"))) {...}

( ) #61

Interesting :worried:
Can you tell me the speedtest-cli --version you are using? I suspect this being a change in the newest version.
Actually I think that checking for Ping at the beginning is all that’s really needed. If there was a problem, there will be no “Ping”. Case closed :wink:

(Dominic Spatz) #62

its 0.3.1
i had to change the url in the speedtest_cli.py before i could use the tool.
otherwise the server list is not available.
(Just added this second expression, in case that i will use my VM again.)