Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1
    Senior Member
    Join Date
    Oct 2008
    Location
    Huntingdon, UK
    Posts
    550

    Controller-Server Communication: Help Please!

    Hi,
    I've written an applet for the Controller that has a dedicated, small (but growing) following. I am at the stage now where I want to move my project from the "get it working" phase to the "make it easy" phase. Currently the applet is installed manually via SCP and, at the same time, the end-user places their personalised configuration files into the applet's folder.

    I want to move to using a repo for installation but I believe that updating via a repo will replace/remove the users' config files such that the applet's folder on the Controller will become an exact copy of the contents of the repo's zip file with any pre-existing files removed, is this correct?

    So, What I want to do is to have the users' config files stored on the SBS server somewhere and then have the applet be able to read/download them over the network. I've had a look around and I think it involves json and CLI but I'm completely clueless about it.

    Is it possible for a lua applet to access files stored on the server? If so, how?

    Any help much appreciated.

  2. #2
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    10,318
    Quote Originally Posted by indifference_engine View Post
    I want to move to using a repo for installation but I believe that updating via a repo will replace/remove the users' config files such that the applet's folder on the Controller will become an exact copy of the contents of the repo's zip file with any pre-existing files removed, is this correct?
    Partly correct, it replaces the plugin folder completely with what's in the zip. However, settings will not be stored in the plugin folder if you handle them with code like this:
    Code:
    self:getSettings()["somesetting"] = "somevalue"
    self:storeSettings()
    These settings are stored under /etc/squeezeplay which will survive an applet upgrade.

    Quote Originally Posted by indifference_engine View Post
    So, What I want to do is to have the users' config files stored on the SBS server somewhere and then have the applet be able to read/download them over the network. I've had a look around and I think it involves json and CLI but I'm completely clueless about it.
    If you really want to store them on the server for some reason, you can use the "pref" command. It would probably be even more appropriate to use "playerpref" but I'm not sure if that works for a Controller since it might not be a player known by the server unless you have activated audio playback on the Controller.

    Anyway, to use the "pref" command, you would do something like this to read a preference from the server and store it in the local settings on the Controller:
    Code:
    server:userRequest(
    	function(chunk, err)
    		if err then
    			log:warn(err)
    		elseif chunk.data then
    			local value = chunk.data["_p2"]
    			self:getSettings()["somesetting"] = value
    			self:storeSettings()
    		end
    	end,
    	player and player:getId(),
    	{ 'pref', 'plugin.someplugin:somesetting','?'}
    )
    And I think a write operation would look something like this:
    Code:
    server:userRequest(
    	function(chunk, err)
    		if err then
    			log:warn(err)
    		elseif chunk.data then
    			-- Probably some verification code, not sure how success is returned
    		end
    	end,
    	player and player:getId(),
    	{ 'pref', 'plugin.someplugin:somesetting','somevalue'}
    )
    Quote Originally Posted by indifference_engine View Post
    Is it possible for a lua applet to access files stored on the server? If so, how?
    As specified above, it's possible to store settings but I don't think it's possible to upload a binary file to the server.

    Of course, you don't need to store it on the server at all if you just want it to survive an applet upgrade. To make it survive a factory reset on the other hand, you would need to store it on the server. Most(all?) applets only store their settings locally on the Controller.
    Erland Isaksson (My homepage)
    (Developer of many plugins/applets (both free and commercial).
    If you like to encourage future presence on this forum and/or third party plugin/applet development, consider purchasing some plugins)
    You may also want to try my Android apps Squeeze Display and RSS Photo Show
    Interested in the future of music streaming ? ickStream - A world of music at your fingertips.

  3. #3
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    10,318

    Controller-Server Communication: Help Please!

    indifference_engine;545194 Wrote:
    >
    > I want to move to using a repo for installation but I believe that
    > updating via a repo will replace/remove the users' config files such
    > that the applet's folder on the Controller will become an exact copy of
    > the contents of the repo's zip file with any pre-existing files removed,
    > is this correct?
    >

    Partly correct, it replaces the plugin folder completely with what's in
    the zip. However, settings will not be stored in the plugin folder if
    you handle them with code like this:

    Code:
    --------------------

    self:getSettings()["somesetting"] = "somevalue"
    self:storeSettings()

    --------------------

    These settings are stored under /etc/squeezeplay which will survive an
    applet upgrade.

    indifference_engine;545194 Wrote:
    >
    > So, What I want to do is to have the users' config files stored on the
    > SBS server somewhere and then have the applet be able to read/download
    > them over the network. I've had a look around and I think it involves
    > json and CLI but I'm completely clueless about it.
    >

    If you really want to store them on the server for some reason, you can
    use the "pref" command. It would probably be even more appropriate to
    use "playerpref" but I'm not sure if that works for a Controller since
    it might not be a player known by the server unless you have activated
    audio playback on the Controller.

    Anyway, to use the "pref" command, you would do something like this to
    read a preference from the server and store it in the local settings on
    the Controller:

    Code:
    --------------------

    server:userRequest(
    function(chunk, err)
    if err then
    log:warn(err)
    elseif chunk.data then
    local value = chunk.data["_p2"]
    self:getSettings()["somesetting"] = value
    self:storeSettings()
    end
    end,
    player and player:getId(),
    { 'pref', 'plugin.someplugin:somesetting','?'}
    )

    --------------------


    And I think a write operation would look something like this:

    Code:
    --------------------

    server:userRequest(
    function(chunk, err)
    if err then
    log:warn(err)
    elseif chunk.data then
    -- Probably some verification code, not sure how success is returned
    end
    end,
    player and player:getId(),
    { 'pref', 'plugin.someplugin:somesetting','somevalue'}
    )

    --------------------


    indifference_engine;545194 Wrote:
    >
    > Is it possible for a lua applet to access files stored on the server?
    > If so, how?
    >

    As specified above, it's possible to store settings but I don't think
    it's possible to upload a binary file to the server.

    Of course, you don't need to store it on the server at all if you just
    want it to survive an applet upgrade. To make it survive a factory
    reset on the other hand, you would need to store it on the server.
    Most(all?) applets only store their settings locally on the Controller.


    --
    erland

    Erland Isaksson
    'My homepage' (http://erland.isaksson.info) (Install my plugins through
    Extension Downloader)
    (Developer of 'TrackStat, SQLPlayList, DynamicPlayList, Custom Browse,
    Custom Scan, Custom Skip, Multi Library, Title Switcher and Database
    Query plugins'
    (http://wiki.erland.isaksson.info/ind...ory:SlimServer))
    ------------------------------------------------------------------------
    erland's Profile: http://forums.slimdevices.com/member.php?userid=3124
    View this thread: http://forums.slimdevices.com/showthread.php?t=78540


  4. #4
    Senior Member
    Join Date
    Oct 2008
    Location
    Huntingdon, UK
    Posts
    550
    Thanks once again Erland, There's some interesting stuff there but unfortunately I don't think it's going to be of any use to me, I need text files. I guess a solution would be for me to load the text files into the controller's settings table to protect the contents from an upgrade but that still requires the user to SCP onto the controller to put the files there in the first place and I'm trying to avoid that.

    Another solution might be a plugin on the server that reads the text files (also on the server) and loads the text into the server's settings table. The controller could then read the text out of the server's settings table as you described. I presume that would work as long as line terminators are maintained in the settings table?? This sounds ugly to me as it would require a plugin and an applet and I know nothing about plugins so I think that road is closed to me

    Sudden thought: Could the controller access files without going through SBS if they were in a shared folder (SMB) on the network?
    Last edited by indifference_engine; 2010-05-10 at 16:46.

  5. #5
    Senior Member
    Join Date
    Oct 2008
    Location
    Huntingdon, UK
    Posts
    550

    Controller-Server Communication: Help Please!

    Thanks once again Erland, There's some interesting stuff there but
    unfortunately I don't think it's going to be of any use to me, I need
    text files. I guess a solution would be for me to load the text files
    into the controller's settings table to protect the contents from an
    upgrade but that still requires the user to SCP onto the controller to
    put the files there in the first place and I'm trying to avoid that.

    Another solution might be a plugin on the server that reads the text
    files (also on the server) and loads the text into the server's
    settings table. The controller could then read the text out of the
    server's settings table as you described. I presume that would work as
    long as line terminators are maintained in the settings table?? This
    sounds ugly to me as it would require a plugin and an applet and I know
    nothing about plugins so I think that road is closed to me


    --
    indifference_engine
    ------------------------------------------------------------------------
    indifference_engine's Profile: http://forums.slimdevices.com/member.php?userid=20698
    View this thread: http://forums.slimdevices.com/showthread.php?t=78540


  6. #6
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    10,318
    Quote Originally Posted by indifference_engine View Post
    Thanks once again Erland, There's some interesting stuff there but unfortunately I don't think it's going to be of any use to me, I need text files. I guess a solution would be for me to load the text files into the controller's settings table to protect the contents from an upgrade but that still requires the user to SCP onto the controller to put the files there in the first place and I'm trying to avoid that.
    If you only want to read files from the server, I think it might be possible, it get more complex if you also want to write files to the server. I know images are automatically available through HTTP if they are put inside the HTML directory, that might also works for text files. If you want to read them from an external directory, it gets more complex, then you need a plugin that implements a web handler that reads the file when the applet asks for a specific HTTP url. I have some code for this in the Custom Browse plugin which can show the contents of a text file over HTTP (basically in the web ui).

    Quote Originally Posted by indifference_engine View Post
    Another solution might be a plugin on the server that reads the text files (also on the server) and loads the text into the server's settings table. The controller could then read the text out of the server's settings table as you described. I presume that would work as long as line terminators are maintained in the settings table?? This sounds ugly to me as it would require a plugin and an applet and I know nothing about plugins so I think that road is closed to me
    I think it should preserve the line terminators and you don't need a plugin, you can use the "pref" command I listed in the previous post. "plugin.someplugin" is just a namespace that means it will be stored in prefs/plugin/someplugin.pref on the server side.

    Quote Originally Posted by indifference_engine View Post
    Sudden thought: Could the controller access files without going through SBS if they were in a shared folder (SMB) on the network?
    No, unfortunately there isn't a SMB client in the Squeezebox software.

    It's hard to give you specific suggestions when I really don't know what you like to do, for example:
    - Do you only want to read files from the server or are we also talking about writing files to the server ?
    - If we are talking about writing files, I'm guessing it means that the user can edit the file from the Controller ?
    - What are you doing with the information on the applet side, is there a need for an applet or would all this be possible to implement as a server plugin that just provides the information in a menu ? Most menus shown in SqueezePlay are currently implemented on the server side and just displayed through the generic menu code in SqueezePlay.
    - Does it have to work with MySB.com or TinySC on the Touch or is it ok to require the user to have a local SBS installed on a computer ?
    Erland Isaksson (My homepage)
    (Developer of many plugins/applets (both free and commercial).
    If you like to encourage future presence on this forum and/or third party plugin/applet development, consider purchasing some plugins)
    You may also want to try my Android apps Squeeze Display and RSS Photo Show
    Interested in the future of music streaming ? ickStream - A world of music at your fingertips.

  7. #7
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    10,318

    Controller-Server Communication: Help Please!

    indifference_engine;545316 Wrote:
    >
    > Thanks once again Erland, There's some interesting stuff there but
    > unfortunately I don't think it's going to be of any use to me, I need
    > text files. I guess a solution would be for me to load the text files
    > into the controller's settings table to protect the contents from an
    > upgrade but that still requires the user to SCP onto the controller to
    > put the files there in the first place and I'm trying to avoid that.
    >

    If you only want to read files from the server, I think it might be
    possible, it get more complex if you also want to write files to the
    server. I know images are automatically available through HTTP if they
    are put inside the HTML directory, that might also works for text
    files. If you want to read them from an external directory, it gets
    more complex, then you need a plugin that implements a web handler that
    reads the file when the applet asks for a specific HTTP url. I have some
    code for this in the Custom Browse plugin which can show the contents of
    a text file over HTTP (basically in the web ui).

    indifference_engine;545316 Wrote:
    >
    > Another solution might be a plugin on the server that reads the text
    > files (also on the server) and loads the text into the server's
    > settings table. The controller could then read the text out of the
    > server's settings table as you described. I presume that would work as
    > long as line terminators are maintained in the settings table?? This
    > sounds ugly to me as it would require a plugin and an applet and I know
    > nothing about plugins so I think that road is closed to me
    >

    I think it should preserve the line terminators and you don't need a
    plugin, you can use the "pref" command I listed in the previous post.
    "plugin.someplugin" is just a namespace that means it will be stored in
    prefs/plugin/someplugin.pref on the server side.

    indifference_engine;545316 Wrote:
    >
    > Sudden thought: Could the controller access files without going through
    > SBS if they were in a shared folder (SMB) on the network?
    >

    No, unfortunately there isn't a SMB client in the Squeezebox software.

    It's hard to give you specific suggestions when I really don't know
    what you like to do, for example:
    - Do you only want to read files from the server or are we also talking
    about writing files to the server ?
    - If we are talking about writing files, I'm guessing it means that the
    user can edit the file from the Controller ?
    - What are you doing with the information on the applet side, is there
    a need for an applet or would all this be possible to implement as a
    server plugin that just provides the information in a menu ? Most menus
    shown in SqueezePlay are currently implemented on the server side and
    just displayed through the generic menu code in SqueezePlay.
    - Does it have to work with MySB.com or TinySC on the Touch or is it ok
    to require the user to have a local SBS installed on a computer ?


    --
    erland

    Erland Isaksson
    'My homepage' (http://erland.isaksson.info) (Install my plugins through
    Extension Downloader)
    (Developer of 'TrackStat, SQLPlayList, DynamicPlayList, Custom Browse,
    Custom Scan, Custom Skip, Multi Library, Title Switcher and Database
    Query plugins'
    (http://wiki.erland.isaksson.info/ind...ory:SlimServer))
    ------------------------------------------------------------------------
    erland's Profile: http://forums.slimdevices.com/member.php?userid=3124
    View this thread: http://forums.slimdevices.com/showthread.php?t=78540


  8. #8
    Senior Member
    Join Date
    Oct 2008
    Location
    Huntingdon, UK
    Posts
    550
    If you only want to read files from the server, I think it might be possible, it get more complex if you also want to write files to the server. I know images are automatically available through HTTP if they are put inside the HTML directory, that might also works for text files.
    That sounds promising as I do only need to read the files.

    Let me explain in a little more detail:
    The applet (SqueezeIR) is specific to the controller, running it on desktop Squeezeplay, touch or radio just wouldn't make sense although I am aware that a future product may benefit. The applet uses text datafiles from the lirc project as its command source and a hand-coded xml config file. Currently the user downloads the lirc files and their custom xml onto the controller with SCP. The configuration of the applet is far too complex to be achieved on the controller itself.

    I want to move away from SCP to a repo but I don't want the user to have to use SCP to re-deploy their lirc and xml files after every upgrade as that defeats the purpose. So, my idea is to use a repo to install the applet (easy) then have the applet pull the xml and lirc files from the server when it starts. That way, the user just edits the config files on the server and leaves them there which is a step in the right direction. Ultimately, I would like to have a plugin that presented a GUI for xml creation but that's a long way off.

    If, as you hint, the user can just drop the xml and lirc files into the server's html directory and the controller can read them then that will be fine.

    I guess that makes for two more questions:
    Are the contents of the html folder preserved following a server upgrade?
    How do I make http requests from the controller to get to the files in the html folder?

    Thanks once again.

    edit: I've done a quick test and found that if I put the files in HTML/<applet name>/html/ on the server then they are viewable in the web-browser so the http solution should be open It looks like it will not serve up any arbitrary file extension but only a pre-defined selection (due to MIME??) but that's ok, I can use *.txt or *.xml for everything. Even better, I can use sub-folders to store multiple configs (eg test & live)!
    Last edited by indifference_engine; 2010-05-11 at 03:31.

  9. #9
    Senior Member
    Join Date
    Oct 2008
    Location
    Huntingdon, UK
    Posts
    550

    Controller-Server Communication: Help Please!

    > If you only want to read files from the server, I think it might be
    > possible, it get more complex if you also want to write files to the
    > server. I know images are automatically available through HTTP if they
    > are put inside the HTML directory, that might also works for text
    > files.

    That sounds promising as I do only need to read the files.

    Let me explain in a little more detail:
    The applet (SqueezeIR) is specific to the controller, running it on
    desktop Squeezeplay, touch or radio just wouldn't make sense although I
    am aware that a future product may benefit. The applet uses text
    datafiles from the lirc project as its command source and a hand-coded
    xml config file. Currently the user downloads the lirc files and their
    custom xml onto the controller with SCP. The configuration of the
    applet is far too complex to be achieved on the controller itself.

    I want to move away from SCP to a repo but I don't want the user to
    have to use SCP to re-deploy their lirc and xml files after every
    upgrade as that defeats the purpose. So, my idea is to use a repo to
    install the applet (easy) then have the applet pull the xml and lirc
    files from the server when it starts. That way, the user just edits
    the config files on the server and leaves them there which is a step in
    the right direction. Ultimately, I would like to have a plugin that
    presented a GUI for xml creation but that's a long way off.

    If, as you hint, the user can just drop the xml and lirc files into the
    server's html directory and the controller can read them then that will
    be fine.

    I guess that makes for two more questions:
    Are the contents of the html folder preserved following a server
    upgrade?
    How do I make hhtp requests from the controller to get to the files in
    the html folder (assuming they can be served)?

    Thanks once again.


    --
    indifference_engine
    ------------------------------------------------------------------------
    indifference_engine's Profile: http://forums.slimdevices.com/member.php?userid=20698
    View this thread: http://forums.slimdevices.com/showthread.php?t=78540


  10. #10
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    10,318
    Quote Originally Posted by indifference_engine View Post
    Are the contents of the html folder preserved following a server upgrade?
    I'm not sure what the server upgrade does, it might delete them so you probably want to try this and see what happens. To make it safe you should probably implement a simple plugin that can get the files from a directory outside the SBS installation directory and serve them to the applet through HTTP.

    Quote Originally Posted by indifference_engine View Post
    How do I make http requests from the controller to get to the files in the html folder?
    See this post:
    http://forums.slimdevices.com/showth...614#post537614

    It's about loading images over HTTP, but you should be able to use the same principle to load text files.
    Erland Isaksson (My homepage)
    (Developer of many plugins/applets (both free and commercial).
    If you like to encourage future presence on this forum and/or third party plugin/applet development, consider purchasing some plugins)
    You may also want to try my Android apps Squeeze Display and RSS Photo Show
    Interested in the future of music streaming ? ickStream - A world of music at your fingertips.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •