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: 58
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: 2100
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: 49
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: 299
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: 49
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: 909
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 3.8875
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: 143
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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest