Results 1 to 10 of 40

Thread: web server; sending events and polling lua variables

Threaded View

  1. #1
    Join Date
    Jul 2007

    Default web server; sending events and polling lua variables

    While creating some JQuery webpages using Girder I ran into the update and polling issues that many have run into before. I collected all the bits and pieces together to get my thingy to work. But figured I might better make something reusable.

    So here's the result, from several other posts;
    So it simplifies polling for updates, added to Shauns code the full 4 payloads for events created from javascript, included the 'cache : false' option for the ajax request to get a lua value (ran into the browser serving lua values from its cache, which obviously don't change)

    Any way this is the javascript I created;

    Creates a 'girder' namespace with the following methods/functions
    Gets a Lua variable from Girder, independent of the recurring update
    Takes 2 parameters;
    1) string with the name of the lua variable to get from Girder
    2) callback function for the returned results. This will be the callback
    for the JQuery $.ajax method, see JQuery docs for parameters for this callback.
    Sends an event to Girder. Takes 6 parameters;
    1) string with the eventstring
    2) integer with the Device ID for which the event is raised (optional, defaults to 18, Girder)
    3) 4 strings with the 4 payloads (optional, absence results in string value 'undefined' )
    Returns a new updater object, see below
    Updater object
    Runs a recurring update sequence (polling) that gets data from Girder and calls a callback function if the returned data was changed since the last request. Multiple updaters can run simultaneously, but if you get more than a few, you're better of using JSON to store a table in a single lua varaiable and get updates for the entire table at once.
    Object methods;
    Starts the polling sequence according to the provided parameters.
    Takes 3 parameters;
    1) string with the name of the lua variable to get from Girder
    2) integer with the interval in milliseconds between updates
    3) callback function when an updated value arrives, has 2 parameters
    a) data received during last update
    b) previously received data
    Stops the previously started updater
    2 additional files are required (these are NOT the standard distributed ones);
    - ajaxreq.lhtml
    - ajax_sendevent.lhtml

    The shortest possible way to get polling lua variables from Girder going;
    $(document).ready(function() {
     var GoUpdate = function (newData, oldData) {
      // do what needs to be done here, will only be called when the data has changed
     girder.NewUpdater().Start( 'mytest.value', 5000, GoUpdate );
    This will poll the value of 'mytest.value' every 5 seconds and if the value changed from the previous poll, the GoUpdate function will be executed

    I hope it can be made into something generically usefull. So please comment on this, see the attachment for an example.
    Last edited by Tieske8; May 18th, 2011 at 12:58 PM. Reason: Removed the attachment, added an updated version in a later post.
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

Tags for this Thread

Posting Permissions

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