Page 12 of 13

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 22:26
by Rolandet
FireWizard wrote: Wednesday 06 May 2020 23:41 Hi,

You can install the Ookla speedtest directly on the Pi4.

Regards
I'm running into a little weird thing with that ookla version
Somehow the cronjob runs, but it doesn't update the output file nore my devices in Domoticz
Anyone have the same issue?

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 22:48
by Bigted
Rolandet wrote: Wednesday 27 May 2020 22:26
I'm running into a little weird thing with that ookla version
Somehow the cronjob runs, but it doesn't update the output file nore my devices in Domoticz
Anyone have the same issue?
Does it update the file and sensors if you run it manually

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 22:52
by FireWizard
Hi,

Did you run speedtest-cli manually.
You have to do it once in order to accept their licence.
If you have done that, it will run without asking to accept a licence.

Regards

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 22:54
by Rolandet
Bigted wrote: Wednesday 27 May 2020 22:48
Rolandet wrote: Wednesday 27 May 2020 22:26
I'm running into a little weird thing with that ookla version
Somehow the cronjob runs, but it doesn't update the output file nore my devices in Domoticz
Anyone have the same issue?
Does it update the file and sensors if you run it manually


Yes they do. No problem there




FireWizard wrote: Wednesday 27 May 2020 22:52 Hi,

Did you run speedtest-cli manually.
You have to do it once in order to accept their licence.
If you have done that, it will run without asking to accept a licence.

Regards
Did that, numerous times.



Tnx for your responses.

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 23:05
by FireWizard
Hi,

@Rolandet,

Okay, so it is only the cronjob that doesn't work.

Did you use for all programs the full path?
Cron runs in its own environment and is not aware of any variables, such as $PATH

Regards

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 23:07
by Rolandet
FireWizard wrote: Wednesday 27 May 2020 23:05 Hi,

@Rolandet,

Okay, so it is only the cronjob that doesn't work.

Did you use for all programs the full path?
Cron runs in its own environment and is not aware of any variables, such as $PATH

Regards
Yeah i run the cronjob as pi

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 23:15
by FireWizard
@Rolandet

How does your crontab look like.

Regards

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 23:17
by Rolandet
FireWizard wrote: Wednesday 27 May 2020 23:15 @Rolandet

How does your crontab look like.

Regards

Code: Select all

* * * * * /home/pi/domoticz/scripts/st2domo.sh
I've set it to every minute, so i can debug :) and with the 'faulty' version, this works fine

23:30h. SLeepy time. Time to dream of speedy internet. I'll read your answers tomorrow, tnx :)

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 23:25
by FireWizard
@Rolandet

Can you also post the contents of st2domo.sh?
I assume this file is executable?

Regards

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 23:27
by Rolandet

Code: Select all


#!/bin/bash

#setup
host=192.168.178.20
port=8080
username=myUserName
password=MyPassword
pingidx=58
downloadidx=60
uploadidx=59

# no need to edit
speedtest-cli --simple > output.txt
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(cat output.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat output.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')

#output if you run it manually
echo "ping = $ping ms"
echo "download = $download Mbps"
echo "upload =  $upload Mbps"

curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$uploadidx&svalue=$upload"
it's chmod:

Code: Select all

-rwxr-xr-x 1 pi pi   969 May 19 21:54 st2domo.sh

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 23:29
by Rolandet
oh one other thing. I've been installing the right and 'wrong' version of speedtest-cli, removing, reinstalling etc etc

How can I be sure i've removed everything, to start fresh?

apt-get remove speedtest-cli enough?


I don't want to re-install my sd, cause I have an Atag one, and that's a real b**** to connect, and it finally works :)

Re: How to monitor your internet connection with virtual custom sensors

Posted: Wednesday 27 May 2020 23:44
by FireWizard
@Rolandet

How did you install speedtest-cli?

apt-get install? Then it is okay

Regards

Re: How to monitor your internet connection with virtual custom sensors

Posted: Thursday 28 May 2020 17:52
by Rolandet
FireWizard wrote: Wednesday 27 May 2020 23:44 @Rolandet

How did you install speedtest-cli?

apt-get install? Then it is okay

Regards
Well, as we Dutch like to say 'Krijg nou tiete' It's working
Last night, right before bed I set the cronjab back to @hourly, and whadda-ya-know, it works !


Thanks for looking into this guys.

Re: How to monitor your internet connection with virtual custom sensors

Posted: Monday 22 March 2021 11:00
by Chris12
Hi, I read the last few pages of this topic and searched for a solution to monitor my internet connection using a VPN connected provider.
But I could not find it what I'm looking for.

I want to monitor if my internet connection is connected with a VPN, so when the VPN is down I want to see that and get an alarm/message etc.
The VPN provider I have got rotates my VPN connection several times per day/week to get the best/fastest connection available all the time.
Sometimes the VPN connection fails, and I want to know when it does (without looking in my router to see if the VPN is (dis)connected)

My VPN connection is setup in my ASUS RT-AC86U (running asuswrt-merlin firmware) using openVPN, so all my internet traffic is always via this VPN.

I'm not sure this is the right place to look for a solution, if anybody has any other ideas feel free to post them or sent me a PM.
In the meantime I'm checking out the LUA forum as well as the status detection method mentioned there does actually looks into the asus config, so maybe that's the way to go.

Re: How to monitor your internet connection with virtual custom sensors

Posted: Monday 22 March 2021 11:12
by sincze
Moving from 2.7 -> 3.4.4. requires you to modify the necessary library names indeed. But you can use Python27 next to Python 3.4.4. without issue. So Should be possible to still use the old python version.

Re: How to monitor your internet connection with virtual custom sensors

Posted: Monday 22 March 2021 14:38
by AllesVanZelf
Thank you @safi78
I got it running. I first had some problems. The script was running well from commandline but not from crontab.
Finally I found out that I had to comment out these lines from the script:

Code: Select all

#output if you run it manually
#echo "ping = $ping ms"
#echo "download = $download Mbps"
#echo "upload =  $upload Mbps"
Then the script is working from crontab.

Re: How to monitor your internet connection with virtual custom sensors

Posted: Sunday 18 April 2021 14:27
by sundodger
Hi all, trying to set this up on my Domoticz.
However when i try to run the script in Thonny to test it i get a syntax error on the IP address of my Domotcz machine.
See below.
I have no clue as to what would cause this, Any ideas?
Thanks.
Python 3.7.3 (/usr/bin/python3)
>>> %Run speedtest.sh
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/speedtest.sh", line 4
host=192.168.1.150
^
SyntaxError: invalid syntax
>>>

Re: How to monitor your internet connection with virtual custom sensors

Posted: Sunday 18 April 2021 16:10
by Rolandet
can you post your entire script ? (minus the password ;) )

Re: How to monitor your internet connection with virtual custom sensors

Posted: Sunday 18 April 2021 18:40
by sundodger

Code: Select all

#!/bin/bash

#setup
host=192.168.1.150
port=8080
username=xxx
password=xxxx
pingidx=83
downloadidx=82
uploadidx=84

# no need to edit
speedtest-cli --simple > output.txt
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(cat output.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat output.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')

#output if you run it manually
echo "ping = $ping ms"
echo "download = $download Mbps"
echo "upload =  $upload Mbps"

curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$uploadidx&svalue=$upload"

Re: How to monitor your internet connection with virtual custom sensors

Posted: Sunday 18 April 2021 18:59
by Rolandet
I don't see anything wrong with the script at first glance.

Have you tried running it as a single shell scrip?