View Full Version : Need some guidance

May 12th, 2015, 09:37 AM
I'm working on a driver for an Elk M1 Gold panel. I've looked at the G6 docs and looked at several other Lua based plugins, but I can't seem to find many commonalities between examples.

My goal is to be able to select my plugin through the settings window, add the IP address/port number (or serial port number in the future), and have alarm events trigger actions that have been configured using the action tree. I would also like to use this code as a template for future plugins for other devices I have.

Specific questions:
- Why do some plugins have so many .lua files? example: device.lua, init.lua, control.lua
- Are certain filenames hardcoded within G6 to perform certain functions? What calls init.lua?
- What is the difference between init and start functions?

I've attached what I have thus far, but I cannot get it to connect to the M1G upon startup of Girder. What have I missed?

Thanks in advance!


May 12th, 2015, 11:33 AM
That is awesome news! Sorry about the state of the development docs. We've focused a lot more on features and user side docs up to now. We've started on a rough developer doc now.


Read through that.

1. Many lua files - Depends on their functionality. If you do not expose to the device manager it can be really simple. ( about 4 files, 1 config, 1 lua, 1 javascript and a UI file )
2. filenames are not hardcoded. Files are extracted from the *.plugin file ( see doc mentioned before ) Girder expects a certain set of functions in the Lua and Javascript files.
3. in the plugin init is the object constructor. Start is when the plugin is allowed to start sending events.

Take a look at lua\examples\plugin

May 12th, 2015, 12:34 PM
I have read through the plugin page. This answered a few questions, but created a lot more questions.

Having read through every provided Lua based plugin only created even more confusion since there doesn't seem to be any uniformity between those plugins. Some require being called by a scripting action, some require configuration via the device manager, other require configuration via the plugin page itself. I would like to adhere to a standard if one applies, or at the very least, I would like to adhere to a recommended method.

- How do I have my plugin create a new connection over the LAN upon startup of G6 without needing a scripting action to initiate that connection? I don't want to have to write code in a GUI to initiate backend code. I need to be able to write plugins and ship them to a friend who has limited tech skills. I may be working on two separate G6 installs, so simplicity is important.
- Why do some plugins use an init.lua? Nothing seems to include them so how are they referenced? Do I even care about this?
- Shouldn't a plugin be able to be loaded and start sending events to the action tree without any scripting outside of the plugin itself? Maybe this is the source of my confusion.

I've RTFM, but it leaves a lot of gaps for a newb like myself. I'll be more than happy to help write a "starting from scratch guide" if I can get G6 to do what I need. For now though, I need to get over the hump.

May 12th, 2015, 12:45 PM
1 Sure that is possible.
2. The convention that I have been trying to stick with is that init.lua holds the actually communication items if the plugin uses the transport system. It's called typically from plugin.lua ( or backend.lua ).
3. Yep

There are basically two paths.

1. You are going to expose devices to the device manager, devices are instantiated and configured from there. ( E.g. PIO-1, Global Cache )
2. You are not. No devices and config happens on the settings page. For example the WinLirc plugin.

1. Involves a lot more work and is probably not a good starting point to learn. So let's start with the WinLirc plugin as a starting point. It has config on the settings page and is really simple. Have a look at that. Then come back with questions ( or call me and I'll talk you through it ).

I think the easiest way for you to get started is by making a copy of the winlirc plugin.

May 13th, 2015, 03:10 PM
Heeding your advice, I took a third look at the WinLirc plugin. ;) I now have an Elk M1 Gold plugin that triggers emails using just the action tree with no need for a scripting action. It's incredibly basic at this point, but it's a working PoC and something to build off of.

A few questions though:
- I noticed that the winlirc plugin forwards events to some sort of messaging bus (correct term?) instead of being sent directly as an event. This took a little while to see. What's the benefit of such an approach instead of just sending the event directly?
- I would like to have pre-populated events displayed for each type of event. Examples: zone violation, zone normal, alarm state, etc... Is there an example plugin I can look at that makes use of such a thing? I would like to make an event a basic drag and drop type affair to harness the power of the GUI. I know scripting if far more powerful, but I think scripting should be an option that allows one to go beyond the basics, instead of the default.

May 13th, 2015, 03:22 PM
You can call gir.triggerEvent with the whole pub / sub pattern (http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) if you like. It decouples the hardware communications from the Girder specific stuff (usually device manager interactions), but for something this simple it's just icing.

edit checking on the events thing...

May 13th, 2015, 03:36 PM
Predefined Events,.. unfortunately not yet exposed to the Lua side of things... I will add it.

May 13th, 2015, 04:08 PM
I've added predefined events lua access in my code here. Unfortunately I just did a full release which this feature missed. I'll see if I can do a new release in a few days.

June 8th, 2015, 12:51 AM
Hi Ron,

I am looking at the pio1 plugin but I am also failing to see were init.lua is include or referenced. In plugin.lua (in your earlier post here you mention that this is normally done in plugin.lua or backend.lua) I find some of the other files that the plugin is composed of but not init.lua.

Could you give us a short explanation on how this works (maybe add it to the plugin tutorial you started)?


June 8th, 2015, 07:03 AM
The PIO-1 plugin is Device Manager based as such the pio/init.lua file isn't loaded from plugin.lua but from device.lua ( since each PIO-1 is configured as a DM device ). So if you open device.lua line 2 loads init.lua

local pio1 = require('pio1')

That is shorthand for require('pio/init.lua')

June 11th, 2015, 02:00 AM
Hi Ron,

Thanks that helped, I hope you don’t mind answering these questions as I am still trying to get to grips with object oriented programing as I really only done Lingo script (inside Macromedia Director) before and that was quite a while ago. I am also trying to learn Lua but some of these things are Girder specific so I really hope you find some time for the plugin instructions you started (although I am getting more and more but it takes time).

I tried the full version (as opposed to short hand) but I have a question. Since this is a Lua file calling another Lua file shouldn’t it be . (dot) instead of slash (both works on Windows but only if I omit the .lua ending)? Maybe for platform independency!?