Speedtest-cli Internet Up-/Downlink Measurement Integration


(Eduard) #103

Thank you! It turns out it’s not two different files (two blocks of code as the author of the article showed), but one file. I put it in the rules folder and it all worked. But unfortunately the data record does not work in influxdb (collectd works) and openhab does not transfer data to the database. The empty database is created from scratch and a separate openhab user is created for it, all privileges are set for both writing and reading.

Sys: Ubuntu Server 16.04.3 X64
openhab: 2.1.0

Openhab2:
1. Install influxdb persistence

2. The data in the file is filled: influxdb.cfg

url=http://127.0.0.1:8086
user=openhab
password=mypass
db=openhab
retentionPolicy=autogen

3. influxdb.persist:

    Strategies {
        everyMinute : "0 * * * * ?"
        everyHour   : "0 0 * * * ?"
        everyDay    : "0 0 0 * * ?"
        default = everyMinute
    }

    Items {
        gInfluxDB* : strategy = everyChange, everyMinute
        Presence_Phone : strategy = everyChange
    }

4. SpeedTest.items

Group gSpeedtest <"network-icon"> (Whg)

String      SpeedtestSummary        "Ск.Инта: [%s]"             <"speedtest_network">       (gSpeedtest, gInfluxDB)
Number      SpeedtestResultPing     "Ping [%.3f ms]"             <"speedtest_next5">         (gSpeedtest, gInfluxDB)
Number      SpeedtestResultDown     "Downlink [%.2f Mbit/s]"     <"speedtest_download">      (gSpeedtest, gInfluxDB)
Number      SpeedtestResultUp       "Uplink [%.2f Mbit/s]"       <"speedtest_upload">        (gSpeedtest, gInfluxDB)
String      SpeedtestRunning        "Speedtest запущен ... [%s]" <"speedtest_new">           (gSpeedtest)
Switch      SpeedtestRerun          "Ручной запуск"              <"speedtest_reload2">       (gSpeedtest)
DateTime    SpeedtestResultDate     "История: [%1$td.%1$tm.%1$tY в %1$tH:%1$tM]"   <"speedtest_problem4">      (gSpeedtest, gInfluxDB)

5. sudo systemctl status influxdb:

No data db openhab:

root@edgi-server:/etc/openhab2/items# influx
Connected to http://localhost:8086 version 1.4.0~n201709010800
InfluxDB shell version: 1.4.0~n201709010800
> auth
username: openhab
password:
> use openhab
Using database openhab
> show measurements
>
>
>

nothing no data from openhab


(Rich Koshak) #104

First make sure to reboot OH. There is some weird behavior right now with groups where changes in group membership are not picked up properly until a reboot.


(Eduard) #105

no work. reboot OH did not help
there are more ideas? can provide some more data? I need very much what would have worked, I have been fighting for many days.


(Rich Koshak) #106

I’m no expert on this stuff. I’m out of ideas.


(Kuba Wolanin) #107

Hey @edgi I noticed that you have quotation marks inside categories/icons section here.

Instead of

String      SpeedtestSummary        "Ск.Инта: [%s]"             <"speedtest_network">       (gSpeedtest, gInfluxDB)
Number      SpeedtestResultPing     "Ping [%.3f ms]"             <"speedtest_next5">         (gSpeedtest, gInfluxDB)

you should probably write

String      SpeedtestSummary        "Ск.Инта: [%s]"             <speedtest_network>       (gSpeedtest, gInfluxDB)
Number      SpeedtestResultPing     "Ping [%.3f ms]"            <speedtest_next5>         (gSpeedtest, gInfluxDB)

Cheers


(Eduard) #108

Thank you! My icons work with both quotation marks and without quotes. It did not affect the record in the database. It is not written. Empty. And rebooting the demons did not help either.


(lysol) #109

Is anyone running this on a separate computer/server and importing the information into the openhab server?


( ) #110

Hey @lysol, I do not but let me know what’s your actual question and we can probably work something out.

The easiest is probably to install a small openHAB instance on the second device, then send data over to the main instance. Another option would be to write a small script executed on the second device, that would then send data to the main openHAB system via openHAB REST API or MQTT. You’d need to write a small script for that yourself.


(Rich Koshak) #111

I used to use sensorReporter with the execActuator. But my connection was super stable so I stopped running it as it didn’t provide any benefit.

I can dig up my old configs and scripts if you would like.

This is basically @ThomDietrich’s second option, only you wouldn’t need to write it yourself since I already have. :slight_smile:


(lysol) #112

Don’t really have another question. Was curious as one of my HABpanel dashboards is sort of a “Home Status” page that I can get uncommon information related to the status/health of our “home”. While it’s not that big of a deal in a home environment, I like to practice separation of roles. In this sense, having this on a separate (and more powerful) server would make sense to me. I’ll mess around with it when I get time and see what I can come up with.


(lysol) #113

Thanks! I’ll take a look at it.


(Rich Koshak) #114

OK, I had a look and I set it up before I started running OH in Docker so I was using the executeCommandLine to run the program. So here is a quick set of configs that should get you close. I’m just typing these in so there will likely be errors.

sensorReporter.ini

NOTE: This is just the config for the execActuator, you will need to include all the other config sections as well.

[Actuator1]
Class: execActuator.execActuator
Type: Exec
Connection: MQTT
Poll: 0
Command: /usr/local/bin/speedtest-cli --simple
CMDTopic: scripts/speedtest-cli/cmd
ResultTopic: scripts/speedtest-cli/results

I’m pretty sure that the code will not time out as speedtest takes awhile to run. If it does timeout let me know and I’ll update the code.

Items
NOTE: the below Items use an overly complicated naming scheme I used to use. Ignore the N_V crap.
NOTE2: Change the mqtt configs below to match yours

    String      RunSpeedTest     { mqtt="<[broker:scripts/speedtest-cli/cmd:*:default]" } // Strings passed to this Item are command line arguments to speedtest_cli
    String      SpeedTestResults { mqtt="<[broker:scripts/speedtest-cli/results:command:default]" }

    String		N_V_Speedtest_Summary		"Speedtest [%s]"				<network>
    Number		N_V_Speedtest_Ping			"Ping [%.3f msec]"				<network> (gChart)
    Number		N_V_Speedtest_Download		"Download [%.2f Mb/s]"			<network> (gChart)
    Number		N_V_Speedtest_Upload		"Upload [%.2f Mb/s]"			<network> (gChart)
    String		N_V_Speedtest_Running		"Speedtest running ... [%s]"	<network>
    Switch 		T_C_Speedtest_Start			"Start Speedtest"				<network>
    DateTime	N_V_Speedtest_Lastupdate	"Last Speedtest [%1$tm/%1$td/%1$tY %1$tT]" <clock>

Rules

rule "Initialize Speedtest"
when
    System started
then
    if(N_V_Speedtest_Summary.state == NULL || N_V_Speedtest_Summary.state == "") N_V_Speedtest_Summary.postUpdate("NA")
end

rule "Run Speedtest"
when
    Time cron "0 0 */1 * * ?" or // not sure about this cron expression, I had it set to run every 15 minutes in my last version
    Item T_C_Speedtest_Start received command
then
    RunSpeedTest.sendCommand("")
    N_V_Speedtest_Running.postUpdate("Running...")
end

rule "Process Speedtest Results"
when
    Item SpeedTestResults received update
then
    N_V_Speedtest_LastUpdate.postUpdate(new DateTimeType())
    
    val results = SpeedTestResults.state.toString
    if(results != "" && results.length >= 3 && results != "ERROR") {
        val parts = results.split("\n")
        val float ping = Float::parseFloat(parts.get(0).split(" ").get(1))  // I would do this differently these days, see the Type Conversions thread for details
        val float down = Float::parseFloat(parts.get(1).split(" ").get(1))
        val float up   = Float::parseFloat(parts.get(2).split(" ").get(1))

        N_V_Speedtest_Ping.postUpdate(ping)
        N_V_Speedtest_Download.postUpdate(down)
        N_V_Speedtest_Upload.postUpdate(up)
        N_V_Speedtest_Summary.postUpdate(String::format("ᐁ  %.1f Mbit/s  ᐃ %.1f Mbit/s (%.0f ms)", down, up, ping))
    }
    else if(results == "ERROR"){
        logError("Speedtest", "speedtest-cli returned an error code, see sensorReporter logs for details")
        N_V_Speedtest_Summary.postUpdate("ERROR")
    }
    else {
        logError("Speedtest", "Failed to parse results from speedtest-cli: " + results)
        N_V_Speedtest_Summary.postUpdate("Failed to Parse")
    }
    
    N_V_Speedtest_Running.postUpdate("-")
end

(Wolfgang Rosenauer) #115

Thanks a lot for this tutorial. Worked flawlessly.
One thing which is a bit unrelated but as it happens here I’m wondering if anybody knows a nice solution.
Now in the Android app on the phone in landscape mode the item overflows the text “Speedtest” and the results while in wider UIs or in landscape it looks perfectly fine. Does OpenHAB have any way to avoid that or is this an issue which would need to be handled in the app?


(davorf) #116

Hello!

As far as I know, that’s the problem in HABDroid. I’m having it with a speedtest, but also with a longer TV Shows and Movies name when using Plex binding. You could add \n at the begining, so it would start a new line, but it is useful only for a text that could fit in one line itself - in case a length of caption + item text is too long.

Best regards,
Davor


( ) #117

This is a bug with the android app. It should be able to handle longer strings, e.g. by wrapping and scrolling it. Would you please comment and ask for a solution here: https://github.com/openhab/openhab.android/issues/169


(Wolfgang Rosenauer) #118

While everything so far worked fine for me I’m now in the graphing part and somehow it seems I do not get data into influxdb. I tried to work with the other tutorial about influxdb and grafana but apparently I’m missing something.

My item definition looks like:
Group gSpeedtest <“network-icon”> (Sensors)

String SpeedtestSummary “Speedtest [%s]” <“speedtest_network”> (gSpeedtest)
Number SpeedtestResultPing “Ping [%.3f ms]” <“speedtest_next5”> (gSpeedtest, gInfluxDB)
Number SpeedtestResultDown “Downlink [%.2f Mbit/s]” <“speedtest_download”> (gSpeedtest, gInfluxDB)
Number SpeedtestResultUp “Uplink [%.2f Mbit/s]” <“speedtest_upload”> (gSpeedtest, gInfluxDB)
String SpeedtestRunning “Speedtest running … [%s]” <“speedtest_new”> (gSpeedtest)
Switch SpeedtestRerun “Start manually” <“speedtest_reload2”> (gSpeedtest)
DateTime SpeedtestResultDate “Last executed [%1$td.%1$tm.%1$tY, %1$tH:%1$tM Uhr]” <“speedtest_problem4”> (gSpeedtest)

and my persistence configuration:

Strategies {
    everyMinute : "0 * * * * ?"
    everyHour   : "0 0 * * * ?"
    everyDay    : "0 0 0 * * ?"
    default = everyMinute
}

Items {
    gInfluxDB*        : strategy = everyChange, everyHour
    power_total       : strategy = everyChange, everyHour
    pv                : strategy = everyChange, everyHour
    soc               : strategy = everyChange, everyHour
}

My influxdb only has measurements for the latter three apparently:

show databases
name: databases
name


_internal
openhab_db

show measurements
name: measurements
name


power_total
pv
soc

Any hints what to check? Probably similar to @edgi’s issue above? Was it ever fixed?


(Wolfgang Rosenauer) #119

nevermind, I missed the Group definition :frowning:


(B R) #120

davorf,
Did you ever get a more concrete answer to the speed inconsistency? I am having a similar issue with my install. I’m on 1.0.7 right now (current newest) and I’m getting consistently about 1/3 of my actual download speed. From the same server (esxi hypervisor) I can get about 98% of my speed via a windows 10 speedtest so I don’t think it has anything to do with the server or OH VM itself. I have noticed that for some reason my ping times are substantially higher via the CLI (40-200ms vs. the 24ms average) and that the test seems to stall about half way in which may be the cause of the issues. I tried 1.0.2 as you mentioned and it didn’t make any difference from what I can tell.


(Gadget Guy) #121

Thanks! This was one of the first tutorials I followed when I setup on my first install of openHAB.
It runs every hour and logs the results and I have some graphs using Grafana.


(davorf) #122

Hello!

I haven’t got any answer regarding the reason of those measuring differences. I’m still using 1.0.2 and I have pretty reliable measuring results (+/- 5% compared to SpeedTest website).

Best regards,
Davor