ExecuteShellCommand Callback always nil (Solved)  [Solved]

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

Moderator: leecollings

Post Reply
etmrugl
Posts: 8
Joined: Tuesday 18 October 2016 21:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

ExecuteShellCommand Callback always nil (Solved)

Post by etmrugl »

if I enter the command:
pi@domoticz1:~ $ hcitool name <mac_address_of_my_phone>
it will give me the Bluetooth name of my phone (if within reach)

If I try in a script:

Code: Select all

return {
        on = {
               timer = {
			'every minute',
		},
        shellCommandResponses = {
            scriptVar,
        },
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'Ben ik thuis',
	},
	execute = function(domoticz, item)
		domoticz.log('Timer event was triggered by ' .. item.trigger, domoticz.LOG_INFO)
		if item.isTimer then
			domoticz.log('Item is Timer')
			domoticz.executeShellCommand(
            {
                command = 'hcitool name xx:xx:xx:xx:xx:xx',
                callback = scriptVar,
                timeout = 20,
            })
		elseif item.isShellCommandResponse then
			domoticz.log('Response from shell command')
		end
		domoticz.utils.dumpTable(item)
	end
}
The callback is always nil and shellCommandResponses is never triggered.
the log:
Spoiler: show
2021-05-16 17:08:00.416 Status: dzVents: Info: Ben ik thuis: ------ Start external script: BenIkThuisv_0_2.lua:, trigger: "every minute"
2021-05-16 17:08:00.416 Status: dzVents: Info: Ben ik thuis: Timer event was triggered by every minute
2021-05-16 17:08:00.416 Status: dzVents: Info: Ben ik thuis: Item is Timer
2021-05-16 17:08:00.416 Status: dzVents: Debug: Ben ik thuis: ExecuteShellCommand: command = hcitool name xx:xx:xx:xx:xx:xx
2021-05-16 17:08:00.417 Status: dzVents: Debug: Ben ik thuis: ExecuteShellCommand: callback = nil
2021-05-16 17:08:00.417 Status: dzVents: Debug: Ben ik thuis: ExecuteShellCommand: timeout = 20
2021-05-16 17:08:00.417 Status: dzVents: Debug: Ben ik thuis: ExecuteShellcommand: path = /home/pi/domoticz/scripts/dzVents/data/
2021-05-16 17:08:00.417 Status: dzVents: > isShellCommandResponse: false
2021-05-16 17:08:00.417 Status: dzVents: > isDevice: false
2021-05-16 17:08:00.417 Status: dzVents: > isScene: false
2021-05-16 17:08:00.417 Status: dzVents: > isGroup: false
2021-05-16 17:08:00.417 Status: dzVents: > isHTTPResponse: false
2021-05-16 17:08:00.417 Status: dzVents: > isSystem: false
2021-05-16 17:08:00.417 Status: dzVents: > baseType: timer
2021-05-16 17:08:00.417 Status: dzVents: > isTimer: true
2021-05-16 17:08:00.417 Status: dzVents: > dump()
2021-05-16 17:08:00.417 Status: dzVents: > trigger: every minute
2021-05-16 17:08:00.417 Status: dzVents: > isSecurity: false
2021-05-16 17:08:00.417 Status: dzVents: > isHardware: false
2021-05-16 17:08:00.417 Status: dzVents: > isVariable: false
2021-05-16 17:08:00.417 Status: dzVents: > isCustomEvent: false
2021-05-16 17:08:00.417 Status: dzVents: Info: Ben ik thuis: ------ Finished BenIkThuisv_0_2.lua
Domoticz 2021.1 (build 13251)
dzVents Version: 3.1.8

What am I doing wrong here?
Last edited by etmrugl on Sunday 16 May 2021 19:19, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: ExecuteShellCommand Callback always nil

Post by waaren »

etmrugl wrote: Sunday 16 May 2021 17:14 What am I doing wrong here?
You forgot to give the variable scriptVar a value and therewith it is always nil.
try

Code: Select all

local scriptVar = 'something'

return {
        on = {
               timer = {
			'every minute',
		},
        shellCommandResponses = {
            scriptVar,
        },
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'Ben ik thuis',
	},
	execute = function(domoticz, item)
		domoticz.log('Timer event was triggered by ' .. item.trigger, domoticz.LOG_INFO)
		if item.isTimer then
			domoticz.log('Item is Timer')
			domoticz.executeShellCommand(
            {
                command = 'hcitool name xx:xx:xx:xx:xx:xx',
                callback = scriptVar,
                timeout = 20,
            })
		elseif item.isShellCommandResponse then
			domoticz.log('Response from shell command')
		end
		domoticz.utils.dumpTable(item)
	end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
etmrugl
Posts: 8
Joined: Tuesday 18 October 2016 21:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: ExecuteShellCommand Callback always nil  [Solved]

Post by etmrugl »

Thank you! That did the trick.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest