Page 2 of 3

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 21 June 2016 21:31
by Westcott
What are the files in your directory '/home/pi/domoticz/scripts/lua' ?

Re: [internet sensor] speedtest.net measures

Posted: Wednesday 22 June 2016 20:06
by curious
In '/home/pi/domoticz/scripts/lua' i have the following files
JSON.lua
script_device_test.lua ,with the code JSON = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
script_time_demo.lua
and two files using forecast.io values causing no problems

Re: [internet sensor] speedtest.net measures

Posted: Monday 27 June 2016 20:47
by curious
After a lot try and errors I succeeded in installing Korniza's procedure. :D :D
Because I use frontpagedef as homescreen I could change the format of the output.

In the original domoticz I get strange output because I could not find a proper sensor type. Which one should I use ?

Re: [internet sensor] speedtest.net measures

Posted: Friday 15 July 2016 16:22
by rednas
I am getting this in my json file:

Code: Select all

events.js:141
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'settings' of null
    at gotServers (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:522:20)
    at /usr/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:48:16
    at /usr/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:238:7
    at Parser.<anonymous> (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:484:18)
    at emitOne (events.js:77:13)
    at Parser.emit (events.js:169:7)
    at Parser.exports.Parser.Parser.parseString (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:494:16)
    at Parser.parseString (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:7:59)
    at exports.parseString (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:535:19)
    at /usr/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:236:5
Does someone know why?

Re: [internet sensor] speedtest.net measures

Posted: Friday 15 July 2016 17:03
by emme
got the same...

I think something is changed in the server side and its reply
but I'm too newbe to understand what's wrong


at the moment I'm stuck with samsung smart air remote which won't work! :(

Re: [internet sensor] speedtest.net measures

Posted: Monday 18 July 2016 10:54
by hamsterrich424
rednas wrote:I am getting this in my json file:

Code: Select all

events.js:141
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'settings' of null
    at gotServers (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:522:20)
    at /usr/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:48:16
    at /usr/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:238:7
    at Parser.<anonymous> (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:484:18)
    at emitOne (events.js:77:13)
    at Parser.emit (events.js:169:7)
    at Parser.exports.Parser.Parser.parseString (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:494:16)
    at Parser.parseString (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:7:59)
    at exports.parseString (/usr/lib/node_modules/speed-test/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:535:19)
    at /usr/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:236:5
Does someone know why?
I'm also getting this, anyone here?

Re: [internet sensor] speedtest.net measures

Posted: Monday 18 July 2016 23:37
by G3rard
I also got that message in the json file. I looked and the application also gives that error when starting from cli.

Now using speedtest-cli, see http://blog.scphillips.com/posts/2015/0 ... th-loggly/ for more information.

I made the following bash script which runs at 2:26 (change <folder> to your folder)

Code: Select all

#!/bin/sh

MSG=`speedtest-cli --simple | perl -pe 's/^(.*): (.*) (.*?)(\/s)?\n/"$1_$3": $2, /m' | cut -d',' -f 1-3`
echo "{$MSG}" >/<folder>/speed-test.json 2>&1
And the following LUA code which runs at 2:30

Code: Select all

commandArray={}

JSON = (loadfile "/volume1/@appstore/domoticz/var/scripts/lua/functions/JSON.lua")()

time = os.date("*t")
day = tonumber(os.date("%w"))

if (time.hour == 2 and time.min == 30) then
    file = io.open("/volume1/@appstore/domoticz/var/speed-test.json", "r") 
    json_text = file:read()
    speeds = JSON:decode(json_text)
    print("Ping="..speeds.Ping_ms.." ms | Download=".. speeds.Download_Mbit.." Mbps | Upload=".. speeds.Upload_Mbit.." Mbps")

    commandArray[1]={['UpdateDevice']='355|0|'..speeds.Download_Mbit}
    commandArray[2]={['UpdateDevice']='356|0|'..speeds.Upload_Mbit}
    commandArray[3]={['UpdateDevice']='357|0|'..speeds.Ping_ms}
    print("Speedtest uitgevoerd")
end

return commandArray

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 19 July 2016 9:12
by rednas
Thanks for your suggestion, I tried it.
When calling the script by hand in putty all goes well. Until I add it to my crontab.
This is what is logged:

Code: Select all

/home/pi/domoticz/scripts/speed-test.sh: 1:
/home/pi/domoticz/scripts/speed-test.sh: speedtest-cli: not found
And this is exactly my speed-test.sh:

Code: Select all

#!/bin/sh

MSG=`speedtest-cli --simple | perl -pe 's/^(.*): (.*) (.*?)(\/s)?\n/"$1_$3": $2, /m' | cut -d',' -f 1-3`
echo "{$MSG}" >/home/pi/domoticz/scripts/speed-test.json 2>&1
What am I doing wrong?

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 19 July 2016 9:44
by bizziebis
You can use the whole path like

Code: Select all

/usr/local/bin/speedtest-cli

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 19 July 2016 11:56
by Westcott
Hi Rednas,
I don't think you are doing anything wrong - it seems to be generally failing.

Is it working for anyone?

Re: [internet sensor] speedtest.net measures

Posted: Wednesday 20 July 2016 23:15
by G3rard
Westcott wrote:Hi Rednas,
I don't think you are doing anything wrong - it seems to be generally failing.

Is it working for anyone?
Rednas is refering to my post with speedtest-cli, that is another tool then speed-test which gives errors.

Re: [internet sensor] speedtest.net measures

Posted: Friday 22 July 2016 16:41
by sincze
G3rard wrote:I also got that message in the json file. I looked and the application also gives that error when starting from cli.

Now using speedtest-cli, see http://blog.scphillips.com/posts/2015/0 ... th-loggly/ for more information.

I made the following bash script which runs at 2:26 (change <folder> to your folder)

Code: Select all

#!/bin/sh

MSG=`speedtest-cli --simple | perl -pe 's/^(.*): (.*) (.*?)(\/s)?\n/"$1_$3": $2, /m' | cut -d',' -f 1-3`
echo "{$MSG}" >/<folder>/speed-test.json 2>&1
And the following LUA code which runs at 2:30

Code: Select all

commandArray={}

JSON = (loadfile "/volume1/@appstore/domoticz/var/scripts/lua/functions/JSON.lua")()

time = os.date("*t")
day = tonumber(os.date("%w"))

if (time.hour == 2 and time.min == 30) then
    file = io.open("/volume1/@appstore/domoticz/var/speed-test.json", "r") 
    json_text = file:read()
    speeds = JSON:decode(json_text)
    print("Ping="..speeds.Ping_ms.." ms | Download=".. speeds.Download_Mbit.." Mbps | Upload=".. speeds.Upload_Mbit.." Mbps")

    commandArray[1]={['UpdateDevice']='355|0|'..speeds.Download_Mbit}
    commandArray[2]={['UpdateDevice']='356|0|'..speeds.Upload_Mbit}
    commandArray[3]={['UpdateDevice']='357|0|'..speeds.Ping_ms}
    print("Speedtest uitgevoerd")
end

return commandArray
Excellent example. Easy to implement.

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 26 July 2016 15:11
by emme
sorry folks... but I have a question....

Why using a cron job to trigger the bash script while I can do the same with lua?

I'm not so linux skilled and I'm having some issue using crontab (but this is not the matter in this post).. so I changed your LUA to execute once an hour the speedtest script:

Code: Select all

commandArray = {}

JSON  = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
date = os.date("*t")
lastrun = uservariables["speedtestOra"]

 if (date.min == 1)  and (date.hour ~= tonumber(lastrun)) then
     
    commandArray['Variable:speedtestOra']= tostring(date.hour)
    os.execute("/home/pi/domoticz/scripts/speestest-json.sh")
    file = io.open("/home/pi/domoticz/scripts/speed-test.json", "r") 
    json_text = file:read()
    speeds = JSON:decode(json_text)
    print("SpeedTest --> Ping="..speeds.Ping_ms.." ms | Download=".. speeds.Download_Mbit.." Mbps | Upload=".. speeds.Upload_Mbit.." Mbps")

    commandArray[1]={['UpdateDevice']='147|0|'..speeds.Download_Mbit}
    commandArray[2]={['UpdateDevice']='148|0|'..speeds.Upload_Mbit}
    commandArray[3]={['UpdateDevice']='146|0|'..speeds.Ping_ms}
    
 end

return commandArray
I'm using a global variable named speedtestOra that stores the actual hour... than a double check on minute and hour to continue or not.
As first thing I update the hour variable, so, if the script rerun (I've seen it does) it won't be execute more times.
could this be an alternative to not using cron?
ciao
M

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 26 July 2016 16:56
by sincze
emme wrote:sorry folks... but I have a question....

Why using a cron job to trigger the bash script while I can do the same with lua?

I'm not so linux skilled and I'm having some issue using crontab (but this is not the matter in this post).. so I changed your LUA to execute once an hour the speedtest script:

Code: Select all

commandArray = {}

JSON  = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
date = os.date("*t")
lastrun = uservariables["speedtestOra"]

 if (date.min == 1)  and (date.hour ~= tonumber(lastrun)) then
     
    commandArray['Variable:speedtestOra']= tostring(date.hour)
    os.execute("/home/pi/domoticz/scripts/speestest-json.sh")
    file = io.open("/home/pi/domoticz/scripts/speed-test.json", "r") 
    json_text = file:read()
    speeds = JSON:decode(json_text)
    print("SpeedTest --> Ping="..speeds.Ping_ms.." ms | Download=".. speeds.Download_Mbit.." Mbps | Upload=".. speeds.Upload_Mbit.." Mbps")

    commandArray[1]={['UpdateDevice']='147|0|'..speeds.Download_Mbit}
    commandArray[2]={['UpdateDevice']='148|0|'..speeds.Upload_Mbit}
    commandArray[3]={['UpdateDevice']='146|0|'..speeds.Ping_ms}
    
 end

return commandArray
I'm using a global variable named speedtestOra that stores the actual hour... than a double check on minute and hour to continue or not.
As first thing I update the hour variable, so, if the script rerun (I've seen it does) it won't be execute more times.
could this be an alternative to not using cron?
ciao
M
Hi, nice idea! I like it!

I am afraid (however don't know for certain) while using LUA (your solution) domoticz will HALT untill LUA is finished.
(script runs over ,.,, seconds warning)
If you use CRON the data is generated in the background, domoticz will only read the file using LUA.

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 26 July 2016 17:08
by emme
well... first of all THANKS! :oops: :oops: :oops: I'm a newbe :P

while I'm trying to fine tune I've seen:
- It runs 3 times in 200msec (probably the before the global variable update gets recognized) but it looks that the 3 thread are running and not suspended
- I got a warning that the scripts is taking more than 10 seconds to run

here's the Status and Warning events:

Warnings:
2016-07-26 17:06:10.322 Error: EventSystem: Warning!, lua script LUA_SpeedTest has been running for more than 10 seconds
2016-07-26 17:06:20.334 Error: EventSystem: Warning!, lua script LUA_SpeedTest has been running for more than 10 seconds
2016-07-26 17:06:30.351 Error: EventSystem: Warning!, lua script LUA_SpeedTest has been running for more than 10 seconds
Status:
2016-07-26 17:05:52.522 EventSystem: reset all events...
2016-07-26 17:06:25.776 LUA: RISULTATO SPEEDTEST --> Ping=7.821 ms | Download=173.08 Mbps | Upload=18.39 Mbps
2016-07-26 17:06:25.784 EventSystem: Script event triggered: LUA_SpeedTest
2016-07-26 17:06:36.131 LUA: RISULTATO SPEEDTEST --> Ping=23.398 ms | Download=20.89 Mbps | Upload=17.78 Mbps
2016-07-26 17:06:36.137 EventSystem: Script event triggered: LUA_SpeedTest
2016-07-26 17:06:47.684 LUA: RISULTATO SPEEDTEST --> Ping=25.806 ms | Download=44.47 Mbps | Upload=18.86 Mbps
2016-07-26 17:06:47.687 EventSystem: Script event triggered: LUA_SpeedTest

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 26 July 2016 17:34
by G3rard
@emme

You have to make 2 LUA scripts. In the first script you start the bash script which will run the speedtest.
In the second script you place the code to read the speedtest values.

Below my script to run the speedtest, where speedtest-cli.sh is the bash file. See my post above for the content. It runs at 2:26.
You have to change scriptPath to the path of your bash file.

Code: Select all

---------------------------------
--Script to run speed test
--Author    : Gerard
--Date      : 23 June 2016
---------------------------------
commandArray={}

time = os.date("*t")

scriptPath = '/volume1/@appstore/domoticz/var/scripts/bash/speedtest-cli.sh'

if (time.hour == 2 and time.min == 26) then
    cmd = scriptPath .. ' &'
    os.execute(cmd)
    print("Speedtest gestart om "..time.hour..":"..time.min)
end

return commandArray
Then at 2:30 another LUA scripts runs the read the data and update the devices. See my post above for the code of that script.
The second script starts a few minutes later so I know for sure that the first script is ready.

By starting the bash file from LUA you don't get the LUA warning regarding the 10 seconds.

Re: [internet sensor] speedtest.net measures

Posted: Tuesday 26 July 2016 17:36
by emme
this would be my next step!

thanks for your help!!!

Re: [internet sensor] speedtest.net measures

Posted: Thursday 28 July 2016 21:53
by emme
it still keeps running multiple times... but I think I got a workaround...

here's what I did:

Code: Select all

function sleep(n)
  os.execute("sleep " .. tonumber(n))
end

sleep(8)

commandArray = {}
time = os.date("*t")
scriptPath = '/home/pi/domoticz/scripts/speedtest-json.sh'
cmd = scriptPath .. ' &'
if (time.min == 15 and ((time.hour == 6) or (time.hour == 18))) and (uservariables['SpeedTest-InCorso'] == "0") then
    os.execute(cmd)
    print("Speedtest Eseguito alle "..time.hour..":"..time.min)
    commandArray['Variable:SpeedTest-InCorso']="1"
end

return commandArray
I added a 8 seconds of sleep time in order to allow the previous script to complete and update the switch variable....
I tried now and it seems to work correctly

Thanks a lot for your help, support and effort!!! :P
Ciao
M

[internet sensor] speedtest.net measures

Posted: Thursday 28 July 2016 22:13
by G3rard
I don't see the need for using uservariables['SpeedTest-InCorso'] because you can just run the LUA script at a certain time.
My script only start the speedtest once at 2:26, this way the LUA script wont restart while the speedtest is still runnning. But of course you can also run it at 6:15 and 18:15 as in your script.

And where do you set uservariables['SpeedTest-InCorso'] to 0 again? Because otherwise your script will only run once because in the script uservariables['SpeedTest-InCorso'] is set to 1.

And don't use sleep functions in LUA as these scripts should not run for more then 10 seconds (search in forum for more details).

Edit: did you set the script as time script? If it's set as device script it won't work properly.

Re: [internet sensor] speedtest.net measures

Posted: Friday 29 July 2016 8:54
by emme
G3rard wrote:Edit: did you set the script as time script? If it's set as device script it won't work properly.
:o :o

uh.... maybe it's time to have another read at the manual and the wiki :oops: :oops:

it works fine now... :oops: :oops:


I use to set the variable in the other script that gets the json file, update the virtual sensors and set back the variable to 0... of course now it is not needed anymore :P
thanks!