Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Request Lua Variable from Webserver

  1. #1
    Join Date
    May 2001
    Posts
    697

    Default Request Lua Variable from Webserver

    I use the following to send events to webserver ajax_sendevent.lhtml?event=digitalout&device=232

    how would i request a variable like that in the scripting html example

    scripting.lhtml

    would this work

    ajax_scripting.lhtml?variable=_VERSION

    The variable would then be returned in the webpage

    Thanks
    Last edited by rickd; August 11th, 2011 at 10:10 PM.
    Rickd

  2. #2
    Join Date
    May 2001
    Posts
    697

    Default

    ajaxreq.lhtml?Data=_VERSION

    This works now i can get any variable back nice
    Rickd

  3. #3
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    Here's some other code that might help
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

  4. #4
    Join Date
    May 2001
    Posts
    697

    Default Can code enable update variable ongoinf

    This code looksninteresting ...so currently to get an update I have to request the lua variable using the http request this then returns data to irule.
    How can I make the variable be updated and pushed from girder via apolling approach?

    Will this code enable this update without any chAnge on client side or need for http request to b pushed from client first
    Last edited by rickd; August 17th, 2011 at 07:28 PM.
    Rickd

  5. #5
    Join Date
    Oct 2005
    Posts
    307

    Default

    HTTP servers function via client requests, so there is no way to push data to a HTTP client without a request. To allow Girder to push updates to iRule, iRule would need to support something like a TCP connection or receive UDP broadcast.

  6. #6
    Join Date
    May 2001
    Posts
    697

    Default How to use tcp

    Ok thanks that is what I thought ....so is there a simple tcp example showing data output out of a port. I just want to send simple text from a port irule can b configured to listen to that ip address and port.

    So I need code to setup port to send data out that port as this will enable girder to push updates to irule

    Thanks in advance
    Rickd

  7. #7
    Join Date
    Oct 2005
    Posts
    307

    Default

    In the manual, there is an example for a socket that echos telnet requests. iRule needs to initiate the request, so Girder doesn't have to hunt for devices to send the broadcasts. Let me know if you need help with the lua code...

  8. #8
    Join Date
    May 2001
    Posts
    697

    Default

    Great thanks that works well just need a little more help.

    How do i make it so that I can send data from girder that I want rather than just echo the data sent from irule or terminal as both work.

    I need a way to add pushing my data out to the irule client or terminal ..I know that it can just not sure how to do that. Can you provide example?

    Code:
    function mycbserver(p1,p2)
    			if ( p2 == transport.constants.event.CONNECTIONCLOSED ) then
    				print("Connection Closed")
    				return
    			end
    	if ( p2 == transport.constants.event.NEWCONNECTION ) then
    				print("New Incoming Connection")
    				p1:Callback(transport.constants.parser.TERMINATED,'\n', 3000, function (cp1,cp2)
    		if ( cp2 == transport.constants.event.CONNECTIONCLOSED ) then
    				print("Client Connection Closed")
    				table.print(clients[p1])
    				p1:Close()
    				clients[p1]=nil
    				return
    			end
    	if ( cp2 == transport.constants.event.CONNECTIONESTABLISHED ) then
    			if ( cp1 == 0 ) then
    				print("New Client Connection")
    				p1:Write("welcome to our echo telnet server!\r\n")
    				clients[p1]=true
    				
    			else
    				print("New Client Connection Failed: ")
    				p1:Close()
    				clients[p1]=nil
    			end
    		return
    	end
    		print(cp1)
    		
    		p1:Write(cp1 .. '\r\n')
    	end)
    	return
    	end
    end
    if ( clients ) then
    	for c,v in pairs(clients ) do
    	c:Close()
    	end
    end
    if ( c5 ) then
    	c5:Close()
    end
    clients = {}
    	c5 = transport.New(transport.constants.transport.GIPLISTEN)
    if not c5:Open(nil, 12345) then
    	print('Could not start listening')
    	c5:Close();
    	c5 = nil;
    end
    c5:Callback(transport.constants.parser.TERMINATED, '\r\n', 1000, mycbserver)
    print('Listening for connections on port 12345, use telnet localhost 12345 from the commandline')
    thanks Rick
    Last edited by rickd; August 21st, 2011 at 06:54 PM.
    Rickd

  9. #9
    Join Date
    Oct 2005
    Posts
    307

    Default

    If I remember the example correctly, it builds a table of connections, so a separate script action like should give you a broadcast to all the connected devices:
    <code>
    for i in clients do
    if (clients[i] ~= nil) then
    i:Write("status update...")
    end
    end
    </code>

  10. #10
    Join Date
    May 2001
    Posts
    697

    Default

    Thanks it seems that table is blank it is not working? see code in post above. The table print returns {-- #0 } --#0
    Last edited by rickd; August 21st, 2011 at 07:38 PM.
    Rickd

Page 1 of 4 123 ... 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
  •