Speed-test Topic is solved

Others (MiLight, Hue, Toon etc...)
Post Reply
pascalbianca
Posts: 37
Joined: Monday 18 December 2017 19:20
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Susteren
Contact:

Speed-test

Post by pascalbianca » Thursday 11 January 2018 18:29

i see on different locations in google that people has https://github.com/sindresorhus/speed-test op and running.
I have installed it but at some point it goes wrong.

When i try speed-test it goes fine.

Then i follewd the script .:

Code: Select all

#!/bin/bash
#File broadband.sh
#Check your internet connection using speedtest.net
#Version 0.2 || Last Update: 15 May 2016 

speedtest=`node /home/pi/node-v5.3.0-linux-armv7l/lib/node_modules/npm/cli.js --json | jq '.'`

echo $speedtest
ping=`echo $speedtest|cut -f1 -d","|cut -f2 -d":"|cut -f1 -d"}"| tr -d ' '`
downstream=`echo $speedtest|cut -f2 -d","|cut -f2 -d":"|cut -f1 -d"}"| tr -d ' '`
upstream=`echo $speedtest|cut -f3 -d","|cut -f2 -d":"|cut -f1 -d"}"| tr -d ' '`

#Vars
domoip=xx.xx.xxx.xxx
domoport=8080
ping_idx=57
downstream=98
upstream=99

# debug
#       echo $speedtest
#       echo $ping
#       echo $downstream
#       echo $upstream

## ======= No Edit required below line ===========
curl -s -i -H "Accept: application/json" "http://$domoip:$domoport/json.htm?type=command&param=udevice&idx=$ping_idx&nvalue=0&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$domoip:$domoport/json.htm?type=command&param=udevice&idx=$downstream_idx&nvalue=0&svalue=$downstream"
curl -s -i -H "Accept: application/json" "http://$domoip:$domoport/json.htm?type=command&param=udevice&idx=$upstream_idx&nvalue=0&svalue=$upstream"
I get the next error on my screen.:

Code: Select all

{ "ping": 44, "download": 40.6, "upload": 19.9 }
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: SID=none; HttpOnly; path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: SID=none; HttpOnly; path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: SID=none; HttpOnly; path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
speed.png
speed.png (77.96 KiB) Viewed 841 times
Know i'm stuck because i can't see my mistake.
All the files are correct, but for some reason i cant get it to work in domoticz.

leonmoonen
Posts: 15
Joined: Thursday 25 May 2017 23:07
Target OS: Raspberry Pi
Domoticz version: current
Contact:

Re: Speed-test

Post by leonmoonen » Friday 12 January 2018 13:33

I have a similar script running based on the package speedtest-cli (sudo apt-get install speedtest-cli) but considering the first line of your output, this is not important for issue you are experiencing, your script obtains valid speedtest values but fails in three curl lines at the end... (I've double-checked the parsing of the json with cut and tr and that seems ok)

Some questions:
* In the script you're actually using, did you set the variable domoip to the correct IP address for your domoticz machine instead of the xx.xx.xxx.xxx?
* and 8080 is the port you are using?
* Do you have some kind of password/authorization set up for the domoticz interface?

pascalbianca
Posts: 37
Joined: Monday 18 December 2017 19:20
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Susteren
Contact:

Re: Speed-test

Post by pascalbianca » Friday 12 January 2018 21:48

Hello Leonmoonen,

my answers on your 3 questions.

* Yes i have there my ip-adress but because that i paste my code here i made this xxxxxxx to hide my orginal ip adress.
* indeed , i have 8080 in use for domoticz
* if i want to login to my domoticz board outside my ip adres i must enter a username en password.

[update]
Because you mentioned that with login name and password i tryed this in the file.:

Code: Select all

## ======= No Edit required below line ===========
curl -s -i -H "Accept: application/json" "http://$username:@password@$domoip:$domoport/json.htm?type=command&param=udevice&idx=$ping_idx&nvalue=0&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:@password@$domoip:$domoport/json.htm?type=command&param=udevice&idx=$downstream_idx&nvalue=0&svalue=$downstream"
curl -s -i -H "Accept: application/json" "http://$username:@password@$domoip:$domoport/json.htm?type=command&param=udevice&idx=$upstream_idx&nvalue=0&svalue=$upstream"
And now i don't get errors, i get only the values what must be.
But now i want to see it in domoticz and that is also a problem for me, is it possible that somebody can help step by step?

leonmoonen
Posts: 15
Joined: Thursday 25 May 2017 23:07
Target OS: Raspberry Pi
Domoticz version: current
Contact:

Re: Speed-test

Post by leonmoonen » Saturday 13 January 2018 12:20

Hi,

Can you explain in more detail what you mean with "And now i don't get errors, i get only the values what must be. But now i want to see it in domoticz and that is also a problem for me."
- where do you get these values? on the command line? The sensors show up under the Utility menu for me
- have you set up the virtual sensors for ping, downstream and upstream in Domoticz? and are their idx values correcty set up in the script (I assume so, but just checking, as I was a bit surprised by the gap in the numbers)
- how are you (intending) to run the script? automatically from a cron job? have you set that up?

As for step-by-step instructions, the wiki has a page discussing the set-up where the script is triggered by a (virtual) switch in the Domoticz GUI: https://www.domoticz.com/wiki/Bash_-_Sp ... monitoring
It uses a different package to access speedtest but you can ignore that, as we know you get the right values; you can also ignore the difference in how the variables get their value (sed vs cut/tr in your case).

If you follow hat guide w.r.t. setting up the virtual sensors and have adapted your script with the correct idx values it "should" work. If it still doesn't, pls have a look in the domoticz log (6th entry in the setup menu) immediately after manually running the script. Maybe that will give us a clue.

Once we have things running manually we can go over the cron setup (if needed).

cheers,
Leon

pascalbianca
Posts: 37
Joined: Monday 18 December 2017 19:20
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Susteren
Contact:

Re: Speed-test

Post by pascalbianca » Saturday 13 January 2018 15:29

Hello Leonmoon,

-The values i get in command line if i run the script, i don't see sensors in the utility menu
-Yes the virtual sensors for ping, downstream and upstream did i make in Domoticz and the idx i pasted in the script on there place.
-the script is running by the cron job, i had with a other script also a bit of trouble to run it in the cron job, so maybe we can walk that also for a bit step by step.
But for the record i put it so in my cron job.; @hourly /home/pi/domoticz/speedtest.sh

I also walked your wiki link step by step, but the next 2 points don't work.:
*Within Domoticz open the Setup > Log to confirm that Domoticz was informed of this data << see no data upload/download and ping i get a error.: 2018-01-13 14:47:45.312 Error: Error executing script command (/home/pi/domoticz/scripts/speedtest.sh). returned: 1024
But the script is realy true in that location.
*Within Domoticz open the Utility tab and check that data is being recorded << don't see recording

leonmoonen
Posts: 15
Joined: Thursday 25 May 2017 23:07
Target OS: Raspberry Pi
Domoticz version: current
Contact:

Re: Speed-test

Post by leonmoonen » Saturday 13 January 2018 17:04

Hi,
pascalbianca wrote:
Saturday 13 January 2018 15:29
- [...] I don't see sensors in the utility menu
-Yes the virtual sensors for ping, downstream and upstream did i make in Domoticz [...]
The fact that you do not see the sensors (even with a value of 0) in the Utility tab makes me think something may have gone wrong with the virtual sensor setup. Let's check your configuration:
(1) If you look at Setup > Hardware, do you have a dummy entry that looks like this (possibly with a different idx):
Screen Shot 2018-01-13 at 15.35.07.png
Screen Shot 2018-01-13 at 15.35.07.png (22.65 KiB) Viewed 763 times
If you don't have this, pls post a screen shot of your hardware interfaces.
(2) If you look at Setup > Devices (and search on "Custom"), do you have custom sensors that looks like this (likely with a different idx, each of these virtual sensors was made by pressing the "Create Virtual Sensor" button for the Dummy interface in Hardware and setting the Sensor Type to Custom Sensor):
Screen Shot 2018-01-13 at 15.35.55.png
Screen Shot 2018-01-13 at 15.35.55.png (51.08 KiB) Viewed 763 times
If you don't have this, pls post a screen shot of your devices, limited by a search on "Sensor". Also, it would help if you can show us the lines for the devices with idx 57, 98 and 99 (the ones you have configured in your script).

I don't understand why you get the script error in the Domoticz log if you are using cron, or have you also made the "broadband switch" to execute the script? (I've never tried that part, but I'll add one to see how this works). One common issue with running scripts from with Domoticz are permissions. I would consider a `chmod 755 /home/pi/domotics/speedtest.sh` (or alternatively `chmod a+rx /home/pi/domotics/speedtest.sh`) so that all users can read and execute the script.

[update]
The "Error executing script command"-error can be solved by adding the line "exit 0" to the end of your script. Without that line an exit code different than 0 is returned, which is interpreted by Domoticz as an error.

cheers,
Leon

pascalbianca
Posts: 37
Joined: Monday 18 December 2017 19:20
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Susteren
Contact:

Re: Speed-test

Post by pascalbianca » Sunday 14 January 2018 10:21

Hello Leon,

For your info the next snapshots.:
Hardware.:
q1.png
q1.png (16.78 KiB) Viewed 731 times
Sensors.:
q2.png
q2.png (33.76 KiB) Viewed 731 times
The broadband switch i indead used that, but i think thats not the problem or i'm wrong?

I saw that you mentiond chmod 755 /home/pi/domotics/speedtest.sh i had /home/pi/domotics/scripts/speedtest.sh so for the test i placed it also there and changed in Domticz the script to that location.

Also i placed in the script exit 0 on the end.

In my log no error annymore , but also no values.
q3.png
q3.png (6.94 KiB) Viewed 731 times
And to let you see that i placed exit 0 in my script but also to show the script so you can check if i maybe made a mistake, here the script.:

Code: Select all

#!/bin/bash

#setup
host=192.168.0.114
port=8080
user=xxxxx
pass=xxxxx
#idx for download, upload and ping
idxdl=61
idxul=60
idxpng=62
idxbb=63

# speedtest server number
# serverst=xxxx

# no need to edit
# speedtest-cli --simple --server $serverst > outst.txt
speedtest-cli --simple > speedtest.txt

download=$(cat speedtest.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat speedtest.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
png=$(cat speedtest.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')

# output if you run it manually
echo "Download = $download Mbps"
echo "Upload =  $upload Mbps"
echo "Ping =  $png ms"

# Updating download, upload and ping ..
wget -q --delete-after "http://$host/json.htm?type=command&param=udevice&idx=$idxdl&svalue=$download" >/dev/null 2>&1
wget -q --delete-after "http://$host/json.htm?type=command&param=udevice&idx=$idxul&svalue=$upload" >/dev/null 2>&1
wget -q --delete-after "http://$host/json.htm?type=command&param=udevice&idx=$idxpng&svalue=$png" >/dev/null 2>&1

# Reset Broadband switch
wget -q --delete-after "http://$host/json.htm?type=command&param=udevice&idx=$idxbb&svalue=0" >/dev/null 2>&1

# Domoticz logging
wget -q --delete-after "http://$host/json.htm?type=addlogmessage&message=speedtest.net-logging" >/dev/null 2>&1

exit 0

What strikes me is that the speedtest.txt file that is created can not be read. if I want to open it I get denied access.

[update]
I do not know what i did, did diferent thins, but now i see the values :D

leonmoonen
Posts: 15
Joined: Thursday 25 May 2017 23:07
Target OS: Raspberry Pi
Domoticz version: current
Contact:

Re: Speed-test

Post by leonmoonen » Monday 15 January 2018 3:08

Hi,

Glad to hear things work OK now :)

Just for your information: the script location should not matter, I typed that one from the top of my head but I now realize that placing things in the main domoticz directory may mean that they get deleted when you do an upgrade (I actually keep them in the directory /home/pi/scripts to avoid such issues).

Also, repeated writing of the speedtest.txt file is not so good for the SD card and increases changes for corruption. I currently have the same solution, but I'll investigate some alternatives. One option is to set up a RAM drive and write the temporary file there (see http://www.domoticz.com/wiki/Setting_up ... spberry_Pi). However, I think it should also be possible to capture the whole speedtest output in a shell variable and instead of 'cat'-ing the file you could then 'echo' that variable...

[update] After some tweaking, the following code works

Code: Select all

#version that does not write a tempfile to disk
speedtest=$(speedtest-cli --simple)
png=$(echo "$speedtest" | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(echo "$speedtest" | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(echo "$speedtest" | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
cheers,
Leon

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest