Re: How to monitor your internet connection with virtual custom sensors
Posted: Friday 23 December 2016 10:15
I created a fairly similar script for a differtent purpose, maybe you guys like it as well: viewtopic.php?f=21&t=14591
Open source Home Automation System
https://forum.domoticz.com/
Place your script and the command you use also here so we can check.johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.
But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax
Any idea on what I do wrong?
Ok, here is first the code and after that is the command line.mikeoo wrote:Place your script and the command you use also here so we can check.johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.
But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax
Any idea on what I do wrong?
Code: Select all
#!/bin/bash
#setup
port=8080
username=xxxx
password=xxxx
host=localhost
pingidx=239
downloadidx=241
uploadidx=240
# 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"
Try to change host=localhost to host=ip-adres of domoticz and test if that change something.johan99 wrote:Ok, here is first the code and after that is the command line.mikeoo wrote:Place your script and the command you use also here so we can check.johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.
But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax
Any idea on what I do wrong?
command in windows (cmd runned in admin mode): python speedtest.shCode: Select all
#!/bin/bash #setup port=8080 username=xxxx password=xxxx host=localhost pingidx=239 downloadidx=241 uploadidx=240 # 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"
Nice one'sgjaa wrote:I've made some icons (I don't like the default Icon )
One for up and download (speed)
and one for ping (ping)
When i use the IP I get this error:mikeoo wrote:johan99 wrote:mikeoo wrote: Try to change host=localhost to host=ip-adres of domoticz and test if that change something.
You can try the use a different editor. Lot of Windows editors give problems with linux files and to be sure try an other one. Because it say that er is a problem it looks like notepad++ does something with the file. Try Sublime Text https://sublimetext.com/3 that one is working fine with linux filesjohan99 wrote:When i use the IP I get this error:mikeoo wrote:johan99 wrote:
File "speedtest2.sh", line 7
host=192.168.0.188
^
SyntaxError: invalid syntax
I says the zero in the adress is the problem, dont know why, the adress is correct. When I edit the file i use a Windows PC and notepad++ and choose unix EOL.
How this icons can be added ?gjaa wrote:I've made some icons (I don't like the default Icon )
One for up and download (speed)
and one for ping (ping)
I found the solution in the wikidtech wrote:How this icons can be added ?gjaa wrote:I've made some icons (I don't like the default Icon )
One for up and download (speed)
and one for ping (ping)
I think that you need to modify those, Device (Ping, Download and Upload) > Edit > Axis label (add ms or Mbp/s depending device)
gjaa wrote:I've made some icons (I don't like the default Icon )
One for up and download (speed)
and one for ping (ping)
Code: Select all
#!/bin/bash
#setup
host=192.168.10.21
port=8084
pingidx=8
downloadidx=6
uploadidx=7
# no need to edit
/volume1/homes/admin/Speedtest/speedtest-cli --server 5302 > 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://$host:$port/json.htm?type=command¶m=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command¶m=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command¶m=udevice&idx=$uploadidx&svalue=$upload"