Re: [internet sensor] speedtest.net measures
Posted: Tuesday 21 June 2016 21:31
What are the files in your directory '/home/pi/domoticz/scripts/lua' ?
Open source Home Automation System
https://forum.domoticz.com/
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
I'm also getting this, anyone here?rednas wrote:I am getting this in my json file:Does someone know why?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
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
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
Code: Select all
/home/pi/domoticz/scripts/speed-test.sh: 1:
/home/pi/domoticz/scripts/speed-test.sh: speedtest-cli: not found
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
Code: Select all
/usr/local/bin/speedtest-cli
Rednas is refering to my post with speedtest-cli, that is another tool then speed-test which gives errors.Westcott wrote:Hi Rednas,
I don't think you are doing anything wrong - it seems to be generally failing.
Is it working for anyone?
Excellent example. Easy to implement.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)And the following LUA code which runs at 2:30Code: 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
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
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
Hi, nice idea! I like it!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:
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.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
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
Status: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
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
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
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
G3rard wrote:Edit: did you set the script as time script? If it's set as device script it won't work properly.