Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: iPhone Lighting Sliders - Dimming to integer value & Poll check in httpd

  1. #1
    Join Date
    Sep 2007
    Posts
    9

    Default iPhone Lighting Sliders - Dimming to integer value & Poll check in httpd

    I am attempting to make a custom iPod Touch web app for Girder 4. Preliminary tests are going well with iUI for the front-end and basic SendEvents AJAX:
    Code:
    OnClick='return SendEvent("Command to Run", 18);'
    So now I am trying to take it to the next level. First order of business is variable sliders for lighting control. I'm planning to use the "range" input control for safari and AJAX to send values. Here are my questions:

    1) Has anyone tried this before and can share some wisdom?
    2) How can I poll lighting dim levels and return them via AJAX?
    3) How should I send an integer value to Girder with the SendEvent function? I assume I should use a different device code but I'm unclear on what this should be.
    4) Question 3 will allow me to trigger a script but how can I then pass that value to a script?

    Thank you in advance.

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,541

    Default

    Well there is the Girder 5 implementation of what you are trying to do
    Ron
    No support through PM

  3. #3
    Join Date
    Sep 2007
    Posts
    9

    Default Girder 5 iPhone integration

    Hi Ron,

    Thanks for your reply. I know that Girder 5 does have an iPhone implementation which I have tested on a trial. Unfortunately, I need a more customized approach for my needs. For example, Girder 5 did not have a continuous slider in my tests. It seemed to stop at predetermined positions. I also understand that there is added functionality for passing Insteon commands over AJAX but I also would not like to upgrade if at all possible. Please let me know if I can accomplish this in version 4. Thanks.

  4. #4
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,541

    Default

    You can probably do this on Girder 4 yes, I am not sure how well the web-server will hold up but it's worth a try. I suggest using the JQuery libraries, they have sliders as well.
    Ron
    No support through PM

  5. #5
    Join Date
    Sep 2007
    Posts
    9

    Default

    Hi Ron,

    Thanks for the suggestion. I understand that there are some issues with the iPhone and iPod and any drag-drop components because it uses the same motions for navigation around the page. This may have been corrected in more recent versions. For the moment, I am just testing the "range" input type. Thus far, it has been a very simple matter to pass commands to Girder
    Code:
    <form><input type="range" value="75" OnInput='return SendEvent(this.value, 18);'></input></form>
    My concern is the other questions in my post. Please let me know if you can shed any light. Thanks.

  6. #6
    Join Date
    Sep 2007
    Posts
    9

    Default Update

    So after a bit of work this weekend, here is an update:

    The iPhone / iPod Touch will not allow you to use a traditional slider in the safari mobile browser. It will work with jQueryui slides if you click anywhere on the bar, but you can not slide it with a touch and drag. I am going to attempt to program something with the SDK but if that doesn't work or becomes too time consuming, I'll just stick with the non-sliding option. In order to transmit the commands:

    1) Created a device in the device manager for "Lighting Contol" and gave it an ID of 4001

    2) Created a new "ajax_lighting.lhtml" file based on ajax_sendevent.lhtml with added variables for pld1 and pld2 in order to carry the lighting device and dim setting

    Code:
    <%
    	webserver:SetGZIP(false) 
    	webserver:SetHeader("Cache-Control: no-cache, must-revalidate")
      webserver:SetHeader("Expires: Fri, 30 Oct 1998 14:19:41 GMT")
    	local table = webserver:GetCGI()
    	if ( gir ) then
      	gir.TriggerEvent( table['event'], table['device'], table['pld1'], table['pld2'], 0)
    	end	
    %>
    3) Added a function to the girder.js file to accommodate the new variables

    Code:
    function SendLighting( event, device , pld1 , pld2 )
    {				 
       var formRequester = null;
       
    	 try
       {
          formRequester = new XMLHttpRequest();
       }
       catch (error)
       {
            
          try
          {
             formRequester = new ActiveXObject("Msxml2.XMLHTTP");
          }   
          catch (err)
          {
             try
             {
                formRequester = new ActiveXObject("Microsoft.XMLHTTP");
             }
             catch (err2)
             {
      		      formRequester = null;
      					return false;
             }
          }		
       }		
    
       formRequester.open("GET", "ajax_lighting.lhtml?event="+event+"&device="+device+"&pld1="+pld1+"&pld2="+pld2);
    	 
       formRequester.onreadystatechange = function() 
       {
          if (formRequester.readyState == 4) 
          {
    	 	     return true;
          }
       } 
    	 
       formRequester.send(null);							
       return false;
    }
    4) Created a script action triggered by a call to the "Lighting Control" Device

    Code:
    --[[
    From AJAX call: 
    
    EventDevice: Should be Lighting Control Device
    EventString: Should be "Dim"
    pld1: Target Insteon Controller
    pld2: Dim setting
    
    DEBUG
    print(EventDevice)
    print(EventString)
    print (pld1)
    print (pld2)
    --]]
    
    local deviceTable = {
    	OfficeHTPC = "00.00.00",
    	OfficeBrick = "00.00.00",
    	LivingRoomProjection = "00.00.00",
    	LivingRoomBrick = "00.00.00",
    	Kitchen = "00.00.00",
    	Hallway = "00.00.00",
    	DiningRoom = "00.00.00"
    }
    
    DeviceID=deviceTable[pld1]
    DeviceLevel = (((pld2)/3.125)* 7.96875)
    
    local device = Insteon.DeviceManager:GetDevice(DeviceID)
    assert(device,'Device not found')
    Insteon.DeviceCommands.SetLevel(DeviceID,DeviceLevel)
    
    print ("Changed " .. pld1 .. " (" .. DeviceID .. ") to " .. pld2 .. "% (" .. DeviceLevel .. ")")
    5) Called the function with the lighting slider
    Code:
    <form><input id="office_htpc" type="range" OnInput='return SendLighting("Dim", 4001, "OfficeHTPC", this.value);'></input></form>
    Still todo:
    • Create a function to poll the lighting levels and load those values into the sliders when the page loads
    • Write an iPhone native application to send these commands so I have more interface flexibility

  7. #7
    Join Date
    Sep 2007
    Posts
    9

    Default Update

    When I tested the commands I posted, I realized that the Insteon system did not perform so well with quickly updating dim commands therefore killing the possibility of real-time sliders. I adjusted so just the stop point of the slide would be sent. This system limitation probably negates the need to create an iPhone native app since I can accomplish what I need without draggable sliders. I used Jquery UI sliders with steps of 10 and just click along the bar.

    I also created the query system to update the sliders which I will include in a later post.

    The individual light changes work almost flawlessly. The master switch is another story. I wrote the following code to deal with the dim commands:

    Code:
    --[[
    From AJAX call: 
    
    EventDevice: Should be Lighting Control Device
    EventString: Should be "Dim"
    pld1: Target Insteon Controller
    pld2: Dim setting
    
    DEBUG
    print(EventDevice)
    print(EventString)
    print (pld1)
    print (pld2)
    --]]
    
    local deviceTable = {
    	OfficeHTPC = "00.00.00",
    	OfficeBrick = "00.00.00",
    	TheaterFront = "00.00.00",
    	TheaterRear = "00.00.00",
    	Kitchen = "00.00.00",
    	Hall = "00.00.00",
    	DiningRoom = "00.00.00"
    }
    
    --Translate the DeviceLevel into an Insteon compatable value
    DeviceLevel = (((pld2)/3.125)* 7.96875)
    
    if pld1=="Master" then
    	actionTable=deviceTable
    else
    	--Clear the table and only set the first value
    	actionTable = nil
    	actionTable = {onlyONE = deviceTable[pld1]}
    end
    
    for k in pairs(actionTable) do 
    	DeviceID=actionTable[k]
    
    	local device = Insteon.DeviceManager:GetDevice(DeviceID)
    	assert(device,'Device not found')
    	Insteon.DeviceCommands.SetLevel(DeviceID,DeviceLevel)
    	
    	print ("Changed " .. pld1 .. " (" .. DeviceID .. ") to " .. pld2 .. "% (" .. DeviceLevel .. ")")
    
    end
    The issue I am having now is that the system fails to execute dim commands on average 30% of the time when using the master. I believe it has something to do with the rapid succession of Insteon commands. There is no pattern to the failures. I suspect that I may have to create a delay between the commands. I can't imagine I'm the only person to have experienced this problem. Any thoughts?

    Also, if would be useful to know the Lua commands for All On and All Off. Thanks.

  8. #8
    Join Date
    Jun 2008
    Posts
    1,026

    Default

    hi

    are you using the PLC with the SDM and Girder 4?

  9. #9
    Join Date
    Sep 2007
    Posts
    9

    Default

    Quote Originally Posted by Mike C View Post
    hi

    are you using the PLC with the SDM and Girder 4?
    Hi Mike,

    Yes, I am using the PLC with SDM:

    Version: 1.01.122.278
    Plugin Version: 1.4.3
    Core App Version: 12

  10. #10
    Join Date
    Jun 2008
    Posts
    1,026

    Default

    i think that is going to give you a fair amount of grief

    the sdm does the command pairing ie it skims off extra or similar commands but it doesn't do it well.

    and the plc is unreliable.

    i know you don't want to spend the $ but the PLM with G5 is that much better. i wrote the component for the PLM in G5. the command pairing is much more sophisticated and works allowing the use of a slider with resonable results (upto 4 dim level changes per second). and the code is free.

Page 1 of 2 12 LastLast

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
  •