[SOLVED] debug commandArray

Moderator: leecollings

Post Reply
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

[SOLVED] debug commandArray

Post by jmleglise »

Hi,

Does anybody know how to print the content of commandArray ?

In a very big LUA script, I prepare a lot of command in commandArray like this :

Code: Select all

	commandArray[1]={['device']='Off'} 
	commandArray[2]={['device'']='Stopped AFTER 5'}
	commandArray[3]={['device']='Off AFTER 300'}
	commandArray[4]={['deviceX']='Off'}
	...
	return commandArray

But I have a bug, and I would like to check what I finally have in commandArray
Last edited by jmleglise on Wednesday 27 April 2016 21:53, edited 1 time in total.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: debug commandArray

Post by jvdz »

This should work at the end of the script:

Code: Select all

for i, v in pairs(commandArray) do
   print('### ++++++> Device Changes in commandArray: '..i..':'..v)
end

return commandArray
EDIT:this works for the shown format:

Code: Select all

commandArray = {}

commandArray[1]={['device']='Off'}
commandArray[2]={['device']='Stopped AFTER 5'}
commandArray[3]={['device']='Off AFTER 300'}
commandArray[4]={['device']='Off'}

for i, v in pairs(commandArray) do
   print('### ++++++> Device Changes in commandArray: '..i..':' .. v["device"])
end


Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: debug commandArray

Post by jmleglise »

Thank you. You put me on the right way !

As my commandArray is filled with different device like this :
commandArray[1]={['motion']='On'}
commandArray[2]={['temp']='Off'}
commandArray[3]={['door']='On'}

the complete solution is :

Code: Select all

for i, v in pairs(commandArray) do
	for namedevice, t in pairs(v) do
		print('### ++++++> Device Changes in commandArray: '..i..namedevice.. v[namedevice])
	end 
end
I did not understand everything. But that works !
:-)
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: debug commandArray

Post by jvdz »

Just to make this work for both formats of responses in commmandArray:

Code: Select all

commandArray["test"]='Off'
commandArray["test3"]='Off AFTER 300'
commandArray[1]={['tdevice']='Off'}
commandArray[2]={['adevice']='Stopped AFTER 5'}
commandArray[3]={['cdevice']='Off AFTER 300'}
commandArray[4]={['bdevice']='Off'}

print('### ++++++> Device Changes in commandArray: ')
for i, v in pairs(commandArray) do
   if type(v) == "table" then
	   for namedevice, t in pairs(v) do
		  print('### '..i.."="..namedevice.."->".. v[namedevice])
	   end
	else
	  print('### '..i.."->".. v)
	end
end
Jos :)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest