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.
Jumper3126
Posts: 67
Joined: Thursday 31 December 2015 16:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: monitor internet connection with virtual sensors

Post by Jumper3126 » Monday 04 December 2017 20:49

Derik wrote:
Sunday 23 October 2016 20:05
safi78 wrote:backup, backup backup ;)

Anyway, you can always create a 'ram-drive' to redirect this stuff to? Saves you disk-trashing :)
Backup is not the problem....

Code: Select all

0 1 * * * sudo ~/domoticz/scripts/domoticz_backup.sh
5 1 * * 6 sudo ~/domoticz/scripts/scripts_backup.sh
10 1 * * 6 sudo ~/domoticz/scripts/domoticz_map_backup.sh
1 1 1 * * sudo ~/domoticz/scripts/raspberry_backup.sh
Only everytime the work/time...
And Domoticz is going so fast that i do not every time how anything is working..
1 person says to me... when you can hold your card clean why don;t you do that
Hi Derik
I'm curious what those 4 different scripts backup exactly. Feel to share them?

User avatar
Derik
Posts: 2173
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post by Derik » Monday 04 December 2017 23:32

Code: Select all

#!/bin/bash

## LOCAL/FTP/SCP/MAIL PARAMETERS
    SERVER="192.168.5.10"         # IP of Network disk, used for: ftp mail scp
    USERNAME="root"         # FTP username of Network disk used for: ftp mail scp
    PASSWORD="root"               # FTP password of Network disk used for: ftp mail scp
    DESTDIR="/opt/backup"      # used for: local
    DOMO_IP="192.168.5.10"      # Domoticz IP used for all
    DOMO_PORT="8080"         # Domoticz port used for all
## END OF USER CONFIGURABLE PARAMETERS

    TIMESTAMP=`/bin/date +%Y%m%d%H`
    BACKUPFILEDIR="Xu4_Domoticz-map_$TIMESTAMP.tar.gz" # verander  domoticz_xx_  en je backup krijgt deze naam.
 
    ### Create backup and ZIP it
    tar -zcvf /tmp/$BACKUPFILEDIR /home/domoticz/
    
    ### Send to Network disk through FTP
    curl -s --disable-epsv -v -T"/tmp/$BACKUPFILEDIR" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/media/hdd/Domoticz_backup/"
                                                    
    ### Remove temp backup file
    /bin/rm /tmp/$BACKUPFILEDIR

    ### Done!

Try this one with a cron like you see in your post :-)
Change the stuff you want..

When you have this the other are coming:-)
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

matzeb74
Posts: 51
Joined: Sunday 07 January 2018 20:23
Target OS: Raspberry Pi
Domoticz version: newest
Location: Stuttgart
Contact:

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

Post by matzeb74 » Wednesday 24 January 2018 0:52

For me it won´t work. Nothing to see in Domoticz. All shows 0.

In shell:

Code: Select all

domoticz@domoticz:~/scripts $ sudo ./speedtest.sh
ping = 33.913 ms
download = 23.22 Mbps
upload =  19.28 Mbps
My script in Folder /home/domoticz/scripts/

Code: Select all

#!/bin/bash

#setup
host=192.168.178.74
port=1883
username=******
password=*****
pingidx=34
downloadidx=35
uploadidx=36

# 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"

So i see the script works. The output.txt is there, but all three Virtual Devices show 0.0 or 0

freijn
Posts: 387
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

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

Post by freijn » Wednesday 24 January 2018 10:55

I guess in your script the username and passwords are not ******* ( just checking! )

Also, is the port correct?

try

Code: Select all

http://blabla:blablabla@192.168.178.74:1883/json.htm?type=command&param=udevice&idx=34&svalue=100"
What happens?

matzeb74
Posts: 51
Joined: Sunday 07 January 2018 20:23
Target OS: Raspberry Pi
Domoticz version: newest
Location: Stuttgart
Contact:

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

Post by matzeb74 » Wednesday 24 January 2018 23:35

Ah. Thank You. 1883 is the Port for mqtt. Now changed to the domoticz Port and it works. Many thanks!!!

rlschulz
Posts: 16
Joined: Sunday 25 October 2015 17:33
Target OS: Windows
Domoticz version: 3.5877
Contact:

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

Post by rlschulz » Monday 29 January 2018 4:04

I tried modify the script slightly to display my public IP. However domoticz seems to be seeing it as a decimal number and only displaying the first to octets. Is there a way to tell Domoticz to see the IP as text?

ip=$(curl -s https://api.ipify.org)

#output if you run it manually
echo "My public IP address is: $ip"
***.***.***.***
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$ipidx&svalue=$ip"

The sensor displays ***.*** when you look in the current states is shows ***.**** which I am assuming means it saw this as a decimal number and rounded it to 4 digits.

User avatar
sincze
Posts: 979
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

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

Post by sincze » Tuesday 30 January 2018 22:57

Today I figured out why my speedtest-cli results were so low. Only around 90 MBIT.
Figures ofcourse If you only have a 100mbit raspberry. :D
I moved all to my Synology (1000 mbit port).

To achieve it.. Download:

Code: Select all

wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
chmod +x speedtest-cli
In addition I downloaded speedtest-csv (just lazy) from
https://github.com/HenrikBengtsson/spee ... master/bin
Also this script needs:

Code: Select all

chmod +x speedtest-csv
Speedtest-csv uses speedtest-cli.

After that just create a speedtest.sh file with the contents as shown below.
Also chmod +x speedtest.sh as well.

Code: Select all

#!/bin/sh

DOMO_IP="***.***.***.***"  # Domoticz IP Address
DOMO_PORT="8080"        # Domoticz Port
UPLOAD_IDX="***"        # Upload IDX
DOWNLOAD_IDX="***"      # Download IDX
PING_IDX="***"          # Ping IDX

# DO NOT MODIFIY PAST HERE !

input=$(/var/services/homes/yourhome/speedtest-csv --sep ',')

ping=$(echo $input | cut -f7 -d ',')
download=$(echo $input | cut -f8 -d ',')
upload=$(echo $input | cut -f9 -d ',')

if [ -z "$ping" ]; then
   echo "Empty Variable $ping"
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$PING_IDX&nvalue=0&svalue=$ping"
fi

if [ -z "$upload" ]; then
   echo "Empty Variable $upload"
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$UPLOAD_IDX&nvalue=0&svalue=$upload"
fi

if [ -z "$download" ]; then
   echo "Empty Variable $download"
else
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DOWNLOAD_IDX&nvalue=0&svalue=$download"
fi
From the synology task scheduler you can execute the domoticz.sh every x time or so. Now my results look more for what I pay for. :lol:
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

mikeoo
Posts: 153
Joined: Sunday 22 March 2015 8:35
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Holland
Contact:

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

Post by mikeoo » Thursday 15 February 2018 16:44

sincze wrote:
Tuesday 30 January 2018 22:57
Today I figured out why my speedtest-cli results were so low. Only around 90 MBIT.
Figures ofcourse If you only have a 100mbit raspberry. :D
I moved all to my Synology (1000 mbit port).
Tnx working much better with the NAS indeed.

Made a adjustment because your script was missing the location of the script on the NAS so made that a bit more clear.

Code: Select all

#!/bin/sh
DOMO_IP="***.***.***.***""  # Domoticz IP Address
DOMO_PORT="xxxx"          # Domoticz Port
UPLOAD_IDX="xxxx"          # Upload IDX
DOWNLOAD_IDX="xxxx"     # Download IDX
PING_IDX="xxx"                 # Ping IDX

input=$(/var/services/homes/domoticz/speedtest/speedtest-csv --sep ',') #adjust this line to the right location were your put the script.

# DO NOT MODIFIY PAST HERE !

ping=$(echo $input | cut -f7 -d ',')
download=$(echo $input | cut -f8 -d ',')
upload=$(echo $input | cut -f9 -d ',')

if [ -z "$ping" ]; then
   echo "Empty Variable $ping"
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$PING_IDX&nvalue=0&svalue=$ping"
fi

if [ -z "$upload" ]; then
   echo "Empty Variable $upload"
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$UPLOAD_IDX&nvalue=0&svalue=$upload"
fi

if [ -z "$download" ]; then
   echo "Empty Variable $download"
else
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DOWNLOAD_IDX&nvalue=0&svalue=$download"
fi

Erwin92
Posts: 16
Joined: Saturday 26 November 2016 20:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Erwin92 » Saturday 14 July 2018 15:24

Hi Guys,

I'm using this script for a long time at my Raspberry Pi, and It works really great!
At this moment I'm trying to setup Domoticz at my Synology NAS by Docker, I'm using a virtual linux machine to run the speedtest and script.

But there is something really strange, when I'm running the script only the ping value could send to Domoticz (running in Docker) the download and upload value couldn't? I double checked the IDX values, and also made a new virtual sensor with a new IDX but I still doesn't work.
When I change the script and send the values to my Domoticz running on a Raspberry every value will be updated, so the script and the speedtest are okay.

Could anyone help me with this problem?

mphilipp
Posts: 5
Joined: Thursday 29 December 2016 16:58
Target OS: Raspberry Pi
Domoticz version:
Location: Gorinchem, Netherlands
Contact:

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

Post by mphilipp » Wednesday 17 October 2018 21:30

Aparently, I'm the only one that runs Domoticz using SSL... :)
When it didn't work, I looked at the command to start the Domoticz daemon and noticed 'SSLWWW 443', so I tried the curl line on it's own on the command line, with the -v (verbose) switch and saw the 'connection refused' message in the output. When I tried https and port 443, I got a certificate error because it is self-signed. That can be fixed with the '--insecure' switch. So, I ended up with this line in the script:

Code: Select all

curl --insecure -s -i -H "Accept: application/json" "https://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
I think about splitting the script up in two parts: one for the ping test and one for the bandwith test. The ping test is one that I 'd like to run more often and the bandwidth test can be run every 30 minutes or once an hour.

[edit]
Bugger...speedtest always runs all tests, so splitting up is useless. Ok, sofar for the splitting idea... :lol:

A bit later (when I have more time), I might try to run the speedtest on my router. I've got a Asus router with Merlin firmware which enables me to run custom scripts. Maybe even speedtest is available so I can run it on the router, which gives me the best indication of the true speed. I can write the output.txt on a shared location so Domoticz can pick it up. But that's for later...

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests