[internet sensor] speedtest.net measures

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: [internet sensor] speedtest.net measures

Post by Westcott »

What are the files in your directory '/home/pi/domoticz/scripts/lua' ?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: [internet sensor] speedtest.net measures

Post 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
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: [internet sensor] speedtest.net measures

Post 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 ?
rednas
Posts: 132
Joined: Tuesday 20 October 2015 12:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: [internet sensor] speedtest.net measures

Post 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?
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [internet sensor] speedtest.net measures

Post 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! :(
The most dangerous phrase in any language is:
"We always done this way"
hamsterrich424
Posts: 1
Joined: Monday 18 July 2016 10:34
Target OS: Windows
Domoticz version:
Contact:

Re: [internet sensor] speedtest.net measures

Post 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?
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: [internet sensor] speedtest.net measures

Post 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
Not using Domoticz anymore
rednas
Posts: 132
Joined: Tuesday 20 October 2015 12:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: [internet sensor] speedtest.net measures

Post 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?
User avatar
bizziebis
Posts: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: [internet sensor] speedtest.net measures

Post by bizziebis »

You can use the whole path like

Code: Select all

/usr/local/bin/speedtest-cli
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: [internet sensor] speedtest.net measures

Post by Westcott »

Hi Rednas,
I don't think you are doing anything wrong - it seems to be generally failing.

Is it working for anyone?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: [internet sensor] speedtest.net measures

Post 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.
Not using Domoticz anymore
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: [internet sensor] speedtest.net measures

Post 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.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [internet sensor] speedtest.net measures

Post 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
The most dangerous phrase in any language is:
"We always done this way"
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: [internet sensor] speedtest.net measures

Post 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.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [internet sensor] speedtest.net measures

Post 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
The most dangerous phrase in any language is:
"We always done this way"
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: [internet sensor] speedtest.net measures

Post 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.
Last edited by G3rard on Tuesday 26 July 2016 17:38, edited 2 times in total.
Not using Domoticz anymore
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [internet sensor] speedtest.net measures

Post by emme »

this would be my next step!

thanks for your help!!!
The most dangerous phrase in any language is:
"We always done this way"
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [internet sensor] speedtest.net measures

Post 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
The most dangerous phrase in any language is:
"We always done this way"
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

[internet sensor] speedtest.net measures

Post 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.
Not using Domoticz anymore
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [internet sensor] speedtest.net measures

Post 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!
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest