PDA

View Full Version : controlpath in plugin



yonu
July 9th, 2016, 03:30 PM
ok this may be an odd question but I am not sure if there is a way to do this or not
in my previous plugins I used this to check to see if a control existed before updating and which worked find as the device had a location I could match up to the girder DM


control, err = deviceManager.control( "Home///"..loc.."///"..self.device.name.."///".."led1")
if control then
--print ("control ".. devices.name.. " exists")
if led1 == "0" then
deviceManager.requestControlValueChange( control.id,"0" , "lua")
--print("Off")
end
if led2 == "1" then
deviceManager.requestControlValueChange( control.id,"1" , "lua")
-- print("On")
end


The problem now comes that I don't have a location to match upto is there builtin variable I can use to fill in loc or is where a simpler way inside of the plugin.

Thanks,
Yonu

Ron
July 9th, 2016, 04:21 PM
If I understand it correctly you are looking for all controls that belong to a certain device and you have the device name and device.id.



local controls = deviceManager.controls(device.id);
table.print(controls)


should do the trick.

yonu
July 9th, 2016, 06:34 PM
nope what I am trying to do is basically match the control before it updates I have an if for each control to opdate them but am trying to write it in a way that if I change the location in Devicemanager it will still update.

Thanks,
Yonu

Ron
July 9th, 2016, 07:31 PM
use internalId for storing your own identifications. Girder doesn't care what is in there as long as it is a string.



control.internalId = "doodaad_operator_1"

yonu
July 9th, 2016, 08:21 PM
right I get that but dow does that work when it checks the control path against what is in Device Manager

like I have here for loc
"Home///"..loc.."///"..self.device.name.."///".."led1"

Thanks,
Yonu

Ron
July 9th, 2016, 08:41 PM
You really should not use the device location in your device driver code.



local location = deviceManager.locations( device.locationId )
table.print(location)


Would give you the name of the location that the device is set to.

yonu
July 9th, 2016, 09:07 PM
perfect that is what i needed

Thanks,
Yonu

yonu
July 10th, 2016, 12:02 PM
what is the proper way to require socket or socket.http in a plugins component.lua no matter how I reference it I get attempt to index field 'http' (a nil value)

Thanks,
Yonu

Ron
July 10th, 2016, 06:53 PM
Without seeing the code it's hard to say what you are doing wrong. But briefly:

Place this at the top with all the other requires before the "module" command.



local http = require('socket.http')

yonu
July 10th, 2016, 06:58 PM
Thanks that did it I apparently have when stupid I kept trying to reference it in the requires as socket instead of http

Thanks,
Yonu

yonu
July 10th, 2016, 07:11 PM
ok I am back to be a pain

what is required to use self.device.InternalId in the component.lua file or is referenced differently.

sorry for being a pain,
Yonu

Ron
July 10th, 2016, 07:25 PM
it's "internalId" with a small letter I. This is persisted in the device manager database if specified during device creation.

yonu
July 10th, 2016, 07:30 PM
sorry I typed it on the post with a I here is the line
[codelocal ipadd = self.device.internalId [/code]

I have in code if you want I can post the component.lua

Thanks,
Yonu

yonu
July 10th, 2016, 07:40 PM
Figured I would save some trouble here is the file

7012

Ron
July 10th, 2016, 08:25 PM
Probably best to send your whole code.

yonu
July 10th, 2016, 08:43 PM
the lua file in my last post is currently the whole code I wanted to get that doing before I started the rest.

Here is the link 7013

Thanks,
Yonu

Ron
July 10th, 2016, 10:04 PM
but by it self it doesn't do anything, it should have a XXX.plugin file at minimum. How are you testing the file?

yonu
July 10th, 2016, 10:54 PM
I wasn't thinking here is the zip of the whole folder ignore control I haven't messed with it it is from one of my other plugins

7014

Thanks,
Yonu

yonu
July 11th, 2016, 08:05 PM
Any thoughts I have set and started at the various lua files for the last hour and I just don't see why I am getting the error. No big deal I know you are busy just is bugging me so I figured I would ask.



Mon Jul 11 20:03:43 2016 LuaTimerObject::ontimeout / ...les/Promixis/Girder 6/lua/arduinorelay\component.lua:35: attempt to index field 'device' (a nil value)
Mon Jul 11 20:03:43 2016 stack traceback:
Mon Jul 11 20:03:43 2016 ...les/Promixis/Girder 6/lua/arduinorelay\component.lua:35: in function 'update'
Mon Jul 11 20:03:43 2016 ...les/Promixis/Girder 6/lua/arduinorelay\component.lua:103: in function <...les/Promixis/Girder 6/lua/arduinorelay\component.lua:101>


Thanks,
Yonu

Ron
July 11th, 2016, 08:21 PM
line 86 where you call update only passes "self" not the device you are expecting...

yonu
July 11th, 2016, 08:55 PM
ok I changed it to this but I still get the same error


function start(self, device)
base.start(self, device)
self.timerObj = timer.new(45000, function(t)
print("hello")--test timer
update(self, device)
end)
self.timerObj:start()
end

Thanks,
Yonu

Ron
July 12th, 2016, 08:07 AM
:-) You can't just add parameters to a function and expect them to be filled with the 'right stuff' (TM). I will look at your code more closely today and have some actual helpful feedback.

Ron
July 12th, 2016, 03:09 PM
It's probably a good idea to start with the examples/dmPlugin files. Those files subclass the Device part. In that file you can access self.internalId.

yonu
July 12th, 2016, 09:56 PM
well I feel real stupid the whole problem was because when cleaned out component.lua from one of my other plugins that used it I had inadvertently taken out
self:forEachDevice( function ( internalId, device )

Thanks Again,
Yonu

yonu
July 12th, 2016, 10:30 PM
ok I have the parsing working fine no errors at all but I have a dumb question I used this in another plugin to update a label device however I not sure if I am doing something wrong to change a toggle or not the value is always 1 or 0 on but I get no value change so just curious if there is a different setvalue for toggles. oh yes I will soon be coding the control lua just trying to get this part working first. Right now I don't care if it does anything or not other than update the dm.


local ctrl = device:findControl("led1")
--table.print (ctrl) -- test find control tor sensor tempeture
ctrl:setValue(led1) --update control to led1


Thanks,
Yonu

yonu
July 13th, 2016, 07:05 PM
ok fairly simple question I hope I know where yo place this
deviceManager.requestControlValueChange(86,led5 , "lua") but what is required to not get this error


Wed Jul 13 19:04:56 2016 BackendDevice::selfCall::start / ...les/Promixis/Girder 6/lua/arduinorelay\component.lua:76: attempt to index global 'deviceManager' (a nil value)
Wed Jul 13 19:04:56 2016 stack traceback:
Wed Jul 13 19:04:56 2016 ...les/Promixis/Girder 6/lua/arduinorelay\component.lua:76: in function 'cb'
Wed Jul 13 19:04:56 2016 ...ram Files/Promixis/Girder 6/lua/plugin\component.lua:31: in function 'forEachDevice'
Wed Jul 13 19:04:56 2016 ...les/Promixis/Girder 6/lua/arduinorelay\component.lua:36: in function 'update'
Wed Jul 13 19:04:56 2016 ...les/Promixis/Girder 6/lua/arduinorelay\component.lua:110: in function <...les/Promixis/Girder 6/lua/arduinorelay\component.lua:108>


Thanks,
Yonu

Ron
July 13th, 2016, 07:29 PM
at the top before module(...) local deviceManager = deviceManager

yonu
July 13th, 2016, 07:47 PM
Thanks that did it. Just for reference is that used in any of the default plugins in the event I get stuck later

Thanks,
Yonu

yonu
July 13th, 2016, 09:47 PM
ok I am back with another question

I couldn't find a reference anywhere so in which plugin file would I put the code for an event handler?

Thanks,
Yonu

yonu
July 13th, 2016, 10:44 PM
I got working it I just decided to stick it in and see what happened


Thanks,
Yonu

yonu
July 14th, 2016, 06:59 AM
with no errors what would cause what would cause to stop working I had everything working this included so I started coding the eventhandlers I have taken those back out and it still won't work the print works so I know it is running at least the section I have even changed the ctrl variable in the requestControl line to make it error and nothing.


local ctrl = device:findControl("b1")
print(ctrl.internalId)
deviceManager.requestControlValueChange( ctrl,led1 , "lua")


Any thoughts,
Yonu

Ron
July 14th, 2016, 08:04 AM
requestControlValueChange requires the control id, not the control object to be passed. So change to



local ctrl = device:findControl("b1")
print(ctrl.internalId)
deviceManager.requestControlValueChange( ctrl.id,led1 , "lua")

yonu
July 14th, 2016, 09:25 AM
no change I literall went so far as to put a deliberate error in after you said to change it to ctrl.id and it doesn't even give me a error sorry this is odd I just don't get why it just stopped working
[cod]
deviceManager.requestControlValueChange( ctrl.id,led1 , "lua")
[/code]

Ron
July 14th, 2016, 09:43 AM
deviceManager.requestControlValueChange is used to change the value of a control from outside of a driver/plugin. What that code does is call onRequestValueChanged on your control. So if you call that from inside that function things go off.

If you are changing from the inside your plugin all you need to do is:



control.ccontrol.hardwareValue = 1

yonu
July 14th, 2016, 09:57 AM
ok if you would be so kind to ave a quick look at this and tell me if you see something that is just plain wrong. I just noticed when I commented out deviceManager.requestControlValueChange( ctrl.id,led1 , "lua") to try the control.ccontrol.hardwareValue = 1 that I use a c++ comment tag and it never errored so I assume I have something screwy going on. I think whatever it is has to be in component.lua

Thanks,
Yonu

7016

Ron
July 14th, 2016, 10:28 AM
Here is the working version. You were pretty close. Just needed some cleanup.

yonu
July 14th, 2016, 10:40 AM
is there a specific change I am looking for in the file you uploaded? as the component and device files are blank or was the problem in control?

Thanks,
Yonu

Ron
July 14th, 2016, 10:54 AM
component.lua - removed the update function and the various calls to it, including syntax error thrown on load. Pretty empty with the exception of the timer, which doesn't do anything but print at the moment.
control.lua - formatting and parameter names on init.
plugin.lua - cleaned up includes a bit, made the names of the ArduinoRelay control, device and components unique ( added AR in front ).

Really the only thing that was crucial was the syntax error in component.lua. Girder threw an error for that when loading the plugin.

yonu
July 14th, 2016, 11:24 AM
I see the syntax changes in component I must have screwed it up when I took the eventhandler stuff back out since it was working before that.

Thanks Again,
onu

Ron
July 14th, 2016, 02:37 PM
No problem!

yonu
July 15th, 2016, 09:37 PM
is plugin ID 1035 in use just don't want t to upload a plugin with a conflicting ID

yonu
December 4th, 2018, 01:35 PM
I know everything is shutdown but is there any chance to get a file as when i click a file in a post it just gives be a back browser windows I am trying to re-download a file I lost