Error executing command / script from Domoticz

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
JezzaG
Posts: 2
Joined: Thursday 26 October 2023 13:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Error executing command / script from Domoticz

Post by JezzaG »

Hi there - looking for a bit of help please with an error that happens with a script that runs the Ookla speedtest on my Pi.

I've installed the Ookla speedtest client and it runs fine from the command line, generating a JSON response (which is ideal for me to pick apart in dzvents; dots removed / replaced due to posting restriction):

Code: Select all

pi@raspberrypi:~/speedtest $ /usr/bin/speedtest --accept-license --accept-gdpr --format=json
{"type":"result","timestamp":"2023-10-26T11:06:45Z","ping":{"jitter":0 362,"latency":5 257,"low":5 200,"high":6 603},"download":{"bandwidth":50847063,"bytes":545216888,"elapsed":11304,"latency":{"iqm":17 822,"low":4 913,"high":50 733,"jitter":0 857}},"upload":{"bandwidth":55170152,"bytes":551157241,"elapsed":10500,"latency":{"iqm":5 620,"low":4 971,"high":7 171,"jitter":0 334}},"packetLoss":0,"isp":"Gigaclear Limited","interface":{"internalIp":"192 168 1 186","name":"eth0","macAddr":"AA:AA:AA:AA:AA:AA","isVpn":false,"externalIp":"88 88 178 194"},"server":{"id":57318,"host":"speedtest zzoomm com","port":8080,"name":"Zzoomm Plc","location":"Slough","country":"United Kingdom","ip":"88 88 9 14"},"result":{"id":"e377b336-de75-4b7a-a23f-ffffffffff","url":"https://www speedtest net/result/c/e377b336-de75-4b7a-a23f-ffffffffffff","persisted":true}}
Similarly all working OK when I run it from a script:

Code: Select all

#!/bin/bash
/usr/bin/speedtest --accept-license --accept-gdpr --format=json
And and also if started from crontab with output directed to a file.

But if called from dzvents, either natively:

Code: Select all

domoticz<dot>executeShellCommand({
				command = '/usr/bin/speedtest --accept-license --accept-gdpr --format=json',
				callback = 'myResponse',
				timeout = 100,
			})
Or via a script:

Code: Select all

domoticz<dot>executeShellCommand({
				command = '/home/pi/speedtest/runSpeedtest<dot>sh',
				callback = 'myResponse',
				timeout = 100,
			})
It errors with:

Code: Select all

2023-10-25 16:06:52 045 Error: dzVents: Error: (3 1 8) Speedtest: {["isCustomEvent"]=false, ["callback"]="myResponse", ["isScene"]=false, ["isGroup"]=false, ["isTimer"]=false, ["isJSON"]=false, ["hasLines"]=false, ["statusCode"]=134, ["shellCommandResponse"]="myResponse", ["timeoutOccurred"]=false, ["isSecurity"]=false, ["baseType"]="shellcommandResponse", ["trigger"]="myResponse", ["isHTTPResponse"]=false, ["dump"]=function, ["isXML"]=false, ["statusText"]="terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_M_construct null not validAborted", ["data"]="", ["isSystem"]=false, ["ok"]=false, ["isVariable"]=false, ["isHardware"]=false, ["errorText"]="terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_M_construct null not validAborted", ["isShellCommandResponse"]=true, ["isDevice"]=false}
If I add some debug code to the bash script, I know it is being run - it's the subsequent execution of /usr/bin/speedtest that is erroring, but only if originally called from dzvents.

Any help appreciated.
JezzaG
Posts: 2
Joined: Thursday 26 October 2023 13:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing command / script from Domoticz

Post by JezzaG »

After further trawling of the internet, there is some suggestion from other forums unrelated to Domoticz suggesting it is due to some environment variables not being set similarly to when it is run as cron / tty. In particular $HOME needing a home directory to for the licence acceptance. But tried setting that to /home/pi (it's null when the script is called) but it didn't work.

However the following does work:

command = 'runuser -l pi -c "/usr/bin/speedtest --accept-license --accept-gdpr --format=json"'

So fixed sufficiently for me, but interested to know if anyone knows why; especially as it works if I su to root and run from a terminal.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest