Page 10 of 13
Re: monitor internet connection with virtual sensors
Posted: Monday 04 December 2017 19:49
by Jumper3126
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?
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 04 December 2017 22:32
by Derik
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:-)
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 23 January 2018 23:52
by matzeb74
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¶m=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=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
Re: How to monitor your internet connection with virtual custom sensors
Posted: Wednesday 24 January 2018 9:55
by freijn
I guess in your script the username and passwords are not ******* ( just checking! )
Also, is the port correct?
try
What happens?
Re: How to monitor your internet connection with virtual custom sensors
Posted: Wednesday 24 January 2018 22:35
by matzeb74
Ah. Thank You. 1883 is the Port for mqtt. Now changed to the domoticz Port and it works. Many thanks!!!
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 29 January 2018 3:04
by rlschulz
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¶m=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.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 30 January 2018 21:57
by sincze
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.
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:
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¶m=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¶m=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¶m=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.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Thursday 15 February 2018 15:44
by mikeoo
sincze wrote: ↑Tuesday 30 January 2018 21: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.
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¶m=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¶m=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¶m=udevice&idx=$DOWNLOAD_IDX&nvalue=0&svalue=$download"
fi
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 14 July 2018 15:24
by Erwin92
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?
Re: How to monitor your internet connection with virtual custom sensors
Posted: Wednesday 17 October 2018 21:30
by mphilipp
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¶m=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...
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...
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 01 June 2019 14:53
by roblom
I use this script on my Synology NAS and it works perfect. There is only one problem, when there is no internet connection the value in domoticz isn't updated to 0 but stays at the last value. Has somebody a solution for this?
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 01 June 2019 21:02
by sincze
Have a virtual switch or variable that contains the result of ping to 8.8.8.8. if you have a ping you have internet... If no ping.... Update sensors to 0
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 02 June 2019 16:53
by roblom
I've added a ping to the script.
Code: Select all
....
#Server to ping
test_ip="8.8.8.8"
test_count=1
if ping -c ${test_count} ${test_ip} > /dev/null; then
echo "Online"
speedtest-cli --simple --server $serverst > 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')
else
echo "Offline"
download=0
upload=0
png=0
fi
....
And in order to make the ping command work for non root users I ran in the command line of my synology:
Now when there is no reaction from the 8.8.8.8 the values are set to 0 and updated in domoticz.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 02 June 2019 17:04
by sincze
Hahaha Nice you fixed it.
Nice job.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 04 June 2019 11:40
by alacran
Hello all,
just perform a refresh install for my domoticz.
Try to launch my test_internet.sh but I met some trouble.
output.txt is well created but I have got this error message and my devices are not update...
pi@raspberrypi:~/domoticz/scripts/Perso $ ./test_internet.sh
ping = 65.448 ms
download = 9.34 Mbps
upload = 1.39 Mbps
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; 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: DMZSID=none; HttpOnly; 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: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>pi@raspberrypi:
Have you got any ideas?
Thank you
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 04 June 2019 11:45
by sincze
Did you add 127.0.0.1 to your domoticz settings so local access is possible without username and password??
It seems updating your devices is the problem.
alacran wrote: ↑Tuesday 04 June 2019 11:40
Hello all,
just perform a refresh install for my domoticz.
Try to launch my test_internet.sh but I met some trouble.
output.txt is well created but I have got this error message and my devices are not update...
pi@raspberrypi:~/domoticz/scripts/Perso $ ./test_internet.sh
ping = 65.448 ms
download = 9.34 Mbps
upload = 1.39 Mbps
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; 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: DMZSID=none; HttpOnly; 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: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>pi@raspberrypi:
Have you got any ideas?
Thank you
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 04 June 2019 11:52
by alacran
Hello,
Thank you for your answer.
Yes, I already add 127.0.0.1 and 192.168.0.* with no autentication required.
With the "401 Unauthorized" error message, I thought about it.
But I add user and password information too in the .sh script, to test it.
Whitout success...
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 04 June 2019 12:12
by sincze
If you try to update your sensors via a browser (copy the filled url to the browser) same result ?? or does that work??
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 04 June 2019 22:07
by alacran
OK...
Does not work with a browser.
Just a wrong password associate to a bad configuration...
I tried to restore an old backup.db file and all seemed to go wrong...
Issue solved.
Thank you
Re: How to monitor your internet connection with virtual custom sensors
Posted: Thursday 06 June 2019 14:51
by alacran
Hello
for an other script, I needed to update Python from 2.7 (if I remember well) to 3.4.4.
Since that, my speed_test.sh did not work.
When I trie to execute it, I've got this error message:
pi@Domoticz:~/domoticz/scripts/Perso $ ./test_internet.sh
Traceback (most recent call last):
File "/usr/bin/speedtest-cli", line 6, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
Is there a difference between Python version?
How can I solved it?
Thank you