How to monitor your internet connection with virtual custom sensors

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post 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?
Custodes Septentrionum
Bigted
Posts: 68
Joined: Friday 12 December 2014 14:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Contact:

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

Post 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
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

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

Post 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
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post 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.
Custodes Septentrionum
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

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

Post 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
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post 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
Custodes Septentrionum
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

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

Post by FireWizard »

@Rolandet

How does your crontab look like.

Regards
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post 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 :)
Custodes Septentrionum
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

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

Post by FireWizard »

@Rolandet

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

Regards
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post 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
Custodes Septentrionum
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post 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 :)
Custodes Septentrionum
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

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

Post by FireWizard »

@Rolandet

How did you install speedtest-cli?

apt-get install? Then it is okay

Regards
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post 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.
Custodes Septentrionum
Chris12
Posts: 238
Joined: Tuesday 18 August 2020 8:41
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: NL
Contact:

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

Post 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.
Domoticz beta | Dashticz beta | Synology DS415+ | Wall tablet Teclast 11.6inch (Android) | TADO v3 controlled heating
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post 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.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

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

Post 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.
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
sundodger
Posts: 29
Joined: Sunday 11 August 2019 17:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
>>>
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post by Rolandet »

can you post your entire script ? (minus the password ;) )
Custodes Septentrionum
sundodger
Posts: 29
Joined: Sunday 11 August 2019 17:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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"
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

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

Post by Rolandet »

I don't see anything wrong with the script at first glance.

Have you tried running it as a single shell scrip?
Custodes Septentrionum
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest