PDA

View Full Version : Execute script on server from lua applet on Squeezeplay (or Duet Controller)



virx71
2016-05-27, 17:40
Hello everybody,
I'm trying to learn more about the lua applets by modifying an existing one.
I succeded in launching a script from inside a controller by simply calling os.execute() and/or io.popen() and I can.

Now I'm trying to launch a script from the Squeezeplay/Controller on the LMS server; I'd like to run a bash/sh script or a simple command with parameters.

Should I use the Framework:pushAction() function? I succeded in registering a custom Action with jive.ui.Framework:registerAction("someaction")
but then when I call Framework:pushAction("someaction") the default bump listener occurs
(from Framework.lua file: "By default, a bump listener is added so that if nothing else responds, a bump will occur")

It's quite hard to find information about how achieve this, could anybody please point me to the right direction/solution?

Thanks,
V.

mherger
2016-05-30, 01:10
> Now I'm trying to launch a script from the Squeezeplay/Controller on the
> LMS server; I'd like to run a bash/sh script or a simple command with
> parameters.

You won't be able to do this without a server side plugin. It would have
to define a CLI command to trigger the action you want to run on the server.


--

Michael

virx71
2016-05-30, 02:52
Thank you Michael,
besides the wiki, do you know if a sample (working) "dummy" plugin exists to start learning something more about this?

Have a nice day,
V.

mherger
2016-05-31, 00:08
> besides the wiki, do you know if a sample (working) "dummy" plugin
> exists to start learning something more about this?

Depends of what you define as "this". Plugins really vary a lot in what
they do. Do you want to only provide a CLI hook for your applet? Or
would you want to provide the menu from the plugin (not the applet)?
What features in general would you like to implement in that plugin?

--

Michael

virx71
2016-06-02, 09:37
Hello Michael,
many thanks for your interest in reading and answering my questions, I really appreciate.

You're right, it's better that I explain more of what's going on: my mock-up solutions are growing in a somehow "ugly" way but they're at least working.
Just to give you an overall picture of what I did:

After all the problems I had with an USB HD connected to a Raspberry PI (database corruption etc) I migrated to a Banana Pi with SATA support.
The next step has been setting up the SqueezeIR plugin which was not easy at the beginning but now it's great to handle
the controller and use it as a remote for any IR device possible (though each time there's a big xml config file to modify).

I have also many RF devices and X10 ones as well so I wanted to set up RF transmission.
So I configured rcswitch (for the kind of "supermarket" RF controlled plugs) and Heyu/Bottlerocket for the X10 devices
using both a modded Firecracker and a simple RF emitter.
And finally I tried to use many plugins to trigger different actions ("Power Center", "Server Power Control" and the old/unusable "Execute Scipt")

I've been happy for a while but all these plugins lack the ergonomy of SqueezeIR which has the great plus of having an IRoP option to trigger an IR command
through an http link. So I started digging into SqueezeIR with no knowledge of lua at all and finally got a way to have a SqueezeIR menu item trigger a script
locally on the controller and do something.

After your first reply I then configured a web server on the LMS to accept some http calls and with a php script execute actions "server side".
Still a mock-up, still ugly but it works: I can finally do things which I'm unable to achieve through perl or lua because of a lack of competence/knowledge.

Then my question about a sample plugin to start learning more about perl, lua and LMS.

The thing I'd love to have is a server side plugin (unfortunately SqueezeIR is only a lua applet) with configurable menus and commands executed both on the cotroller or the server.

Just to give you an example now I have on each controller of the apartment the IR setup for my Samsung TV, multimedia player, electric curtains, RGB leds and X10/RF commands to turn lights on/off (even my lan printer) and the commands to restart the LMS or the BananaPi or the Controller or my fritzbox router.

It's a mock-up, it's ugly but at least it works and it's quite ergonomic.
I wish I could learn how to improve this in a more robust solution.

The best thing maybe could be to improve SqueezeIR and migrate it from the status of "applet" to that of real plugin,
please let me know what do you think about all this.

Have a nice day,
Virginio

mherger
2016-06-03, 02:30
Ok, let me summarize this: you want to have an easily customizable menu
on the controller which can trigger local actions (on the Controller
itself) as well as on the server (LMS). Is this correct?

Unfortunately that's not going to be an easy task. Because menus are
either created on the server side using the "SlimBrowse" protocol, but
then they cannot trigger any action to be executed on the Controller.
See this bug report/feature request from many years ago:

http://bugs.slimdevices.com/show_bug.cgi?id=9914

Or you implement the menu in Lua on the Controller and a plugin to run
on the server side separately. But this way you won't be able to easily
customize the menu through the web UI. Lua would have to send commands
to LMS, which then would trigger some action on the server (as defined
in your plugin).

That's a lot to learn, I must admit. And I'm not sure you're willing to
go there... But let me know if you choose to give it a try anyway. I'll
certainly be able to help with the LMS side of things. Unfortunately not
so much for the Lua part.

--

Michael

virx71
2016-06-07, 12:24
Hello Michael,
sorry for the late reply, busy week end and following days.

Yes I'd like to learn more about Slimbrowse protocol, and the second option you described might be the easiest to start with.
Very interesting discussion about bug 9914. I wonder if Erland's question got an answer, it might be really nice to do what he imagined.

Erland Isaksson 2009-08-18 21:38:31 UTC
I have a problem that might be related to this.
I'd like to be able to open a browse menu for a specific artist or album from my own applet.

The SqueezeIR lua applet might already be a good start:
It's config file is an xml file placed on the server, the applet has an option to load the xml file from the server and then "builds" a lua file with all the remotes configurations and the menus hierarchy.
Just to give an idea I put my modded applet with the xml file I'm currently using (still work in progress) here (https://app.box.com/s/sw2nxavlrkme6452eh4yancuyu0j0ak2). My mod in SqueezeIRApplet.lua file is from line 497 to 509.

I suppose it would not be impossible to add an LMS plugin part to the applet and create an editor embedded in LMS gui.
I'd be happy to give it a try even if the time for this won't be a lot, but summer is ahead and it might be fun
to learn and test new things. I'd be glad to have your advise about where to start from.

Talk to you soon,
Virginio

mherger
2016-06-08, 02:34
> The SqueezeIR lua applet might already be a good start:
> It's config file is an xml file placed on the server, the applet has an

Oh, didn't know the configuration file was served by the server. In this
case you could indeed implement some GUI on the server to modify the
configuration. And you could implement hooks (CLI commands) to trigger
an action on the server.

But overall this is no easy task, and not the typical plugin you'll find
a few to pick ideas from... a relatively simple plugin defining custom
CLI commands is LineIn.
https://github.com/Logitech/slimserver/blob/public/7.9/Slim/Plugin/LineIn/Plugin.pm#L50
defines a few commands.

The CLI plugin otoh defines a most simple settings page with just a
single value
(https://github.com/Logitech/slimserver/blob/public/7.9/Slim/Plugin/CLI/Settings.pm)

--

Michael