Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: Request Lua Variable from Webserver

  1. #21
    Join Date
    May 2001
    Posts
    697

    Default Thanks and works well

    Tested with iRule and works a treat.

    How would I add a simple event pump from irule client say for example

    Data sent is "Transport.play"

    and trigger an event with that name in girder

    Thanks so much will share with other girder irule users
    Rickd

  2. #22
    Join Date
    May 2001
    Posts
    697

    Default

    Code:
    function iruleTCPserver(p1,p2)
    	if ( p2 == transport.constants.event.CONNECTIONCLOSED ) then
    		print("#1 response PROBABLY WILL NOT HAPPEN...")
    		return
    	end
    	if ( p2 == transport.constants.event.NEWCONNECTION ) then
    		print("New iRule Connection.")
    		iruleTCPclients[p1]=true
    		gir.TriggerEvent("irule_send", "100", 0)
    		p1:Callback(transport.constants.parser.TERMINATED,'\n', 2000, function (cp1,cp2)
    			if ( cp2 == transport.constants.event.CONNECTIONCLOSED ) then
    				print("#2 response PROBABLY WILL NOT HAPPEN...")
    				p1:Close()
    				iruleTCPclients[p1]=nil
    				return
    			end
    			--print(cp1)
    			--if cp1 then gir.TriggerEvent("irule_rxdata", "100", 0, cp1) end
    		end)
    		return
    	end
    end
    if ( iruleTCPclients ) then
    	for c,v in pairs(iruleTCPclients ) do
    		c:Close()
    	end
    end
    if ( irulec5 ) then
    	irulec5:Close()
    end
    iruleTCPclients = {}
    iruleLISTENER = transport.New(transport.constants.transport.GIPLISTEN)
    if not iruleLISTENER:Open(nil, 8888) then
    	print("Could not create iRule TCP server.")
    	iruleLISTENER:Close();
    	iruleLISTENER = nil;
    end
    iruleLISTENER:Callback(transport.constants.parser.TERMINATED, '\r\n', 2000, iruleTCPserver)
    print("Starting iRule TCP Server...")
    Would adding those lines commented work?
    Rickd

  3. #23
    Join Date
    May 2001
    Posts
    697

    Default

    THe following works

    Code:
    function iruleTCPserver(p1,p2)
    	if ( p2 == transport.constants.event.CONNECTIONCLOSED ) then
    		print("#1 response PROBABLY WILL NOT HAPPEN...")
    		return
    	end
    	if ( p2 == transport.constants.event.NEWCONNECTION ) then
    		print("New iRule Connection.")
    		iruleTCPclients[p1]=true
    		gir.TriggerEvent("irule_send", "100", 0)
    		p1:Callback(transport.constants.parser.TERMINATED,'\n', 2000, function (cp1,cp2)
    		print(cp1)
    		gir.TriggerEvent("irule_rxdata", "100", 0, cp1)
    			if ( cp2 == transport.constants.event.CONNECTIONCLOSED ) then
    				print("#2 response PROBABLY WILL NOT HAPPEN...")
    				p1:Close()
    				iruleTCPclients[p1]=nil
    				return
    				
    			end
    			if ( cp2 == transport.constants.event.ReceiveData) then
    				print(cp1)
    				gir.TriggerEvent("irule_rxdata", "100", cp1)
    				iruleTCPclients[p1]:Write(cp1 .. '\r\n') --this does not echo terminal
    			return
    			end
    		end)
    		return
    	end
    	
    end
    if ( iruleTCPclients ) then
    	for c,v in pairs(iruleTCPclients ) do
    		c:Close()
    	end
    end
    if ( irulec5 ) then
    	irulec5:Close()
    end
    iruleTCPclients = {}
    iruleLISTENER = transport.New(transport.constants.transport.GIPLISTEN)
    if not iruleLISTENER:Open(nil, 8888) then
    	print("Could not create iRule TCP server.")
    	iruleLISTENER:Close();
    	iruleLISTENER = nil;
    end
    iruleLISTENER:Callback(transport.constants.parser.TERMINATED, '\r\n', 2000, iruleTCPserver)
    print("Starting iRule TCP Server...")
    only issue is it will not echo to terminal but not needed for irule

    any changes you might add would be appreciated

    thanks again Rick
    Rickd

  4. #24
    Join Date
    Oct 2005
    Posts
    307

    Default

    I guess only having one port connected to Girder per device might be interesting (to minimize code you could continue to use the webserver for commands). If you want to do use this port to execute command like the webserver, I would probably have iRule send an 'initialize' to connect and then something like an 'execute,action,device,payload1,payload2' then just parse them out using the first to decide what to do and the remainder as the data necessary:

    if (execute) then gir.TriggerEvent(action, device, payload1,payload2) end

    For the feedback, (if iRule can handle it) I would send one string back with all the states (light on, TV on channel 12, etc...) you are able to get in Girder from your equipment to all devices. Several advantages with this 1) multiple devices know what is going on and 2) if you do have to restart iRule you get all current states of your equipment (not just the ones you change). I actually had a timer in the code given in the previous post, but took it out thinking you wouldn't want it. The timer starts when a client connects and sends a message to all the clients every interval.

    We can add back the echo to terminal if you want, I just didn't see the need for your intended use...

  5. #25
    Join Date
    May 2001
    Posts
    697

    Default

    Thanks on point 2 that is how I do it all status data is send at once as you suggested in one variable constructed in Girder and parsed by iRule for display. All device manger events are driving the same update in the gml.

    On point 1) how do you suggest getting irule to send an initialise? Basically what happens is it connects to the port on startup and triggers the newconnection event and captures the device in table is my understanding. The receive data event enable a trigger back to girder but i could only get it to trigger "data_rx" it would not allow me to use cp1 for some reason.... it would be nice to do what you have suggested...what would i need to add? And why would it not work with cp1 varaible above.

    eg.gir.TriggerEvent(cp1, "100", 0) where cp1 is data entered at terminal or irule

    Also how do I speed the response to data event from irule is that reducing the timeout?
    Rickd

  6. #26
    Join Date
    May 2001
    Posts
    697

    Default

    Code:
    function iruleTCPserver(p1,p2)
    	if ( p2 == transport.constants.event.CONNECTIONCLOSED ) then
    		print("#1 response PROBABLY WILL NOT HAPPEN...")
    		return
    	end
    	if ( p2 == transport.constants.event.NEWCONNECTION ) then
    		print("New iRule Connection.")
    		iruleTCPclients[p1]=true
    		gir.TriggerEvent("irule_send", "100", 0)
    		
    		p1:Callback(transport.constants.parser.TERMINATED,'\n', 1000, function (cp1,cp2)
    		if cp1 then
    			gir.TriggerEvent(cp1, 100, 0)
    			print (cp1) 
    		end
    			if ( cp2 == transport.constants.event.CONNECTIONCLOSED ) then
    				print("#2 response PROBABLY WILL NOT HAPPEN...")
    				p1:Close()
    				iruleTCPclients[p1]=nil
    				return
    				
    			end
    			
    		end)
    		return
    	end
    	
    end
    if ( iruleTCPclients ) then
    	for c,v in pairs(iruleTCPclients ) do
    		c:Close()
    	end
    end
    if ( irulec5 ) then
    	irulec5:Close()
    end
    iruleTCPclients = {}
    iruleLISTENER = transport.New(transport.constants.transport.GIPLISTEN)
    if not iruleLISTENER:Open(nil, 8888) then
    	print("Could not create iRule TCP server.")
    	iruleLISTENER:Close();
    	iruleLISTENER = nil;
    end
    iruleLISTENER:Callback(transport.constants.parser.TERMINATED, '\r\n', 2000, iruleTCPserver)
    print("Starting iRule TCP Server...")
    Scratch that had not reint scripts properly thius does what i want very simply thanks again I think this will work well now injecting the event to girder driectly as you suggest

    will just have to parse cp1 to generate desired event
    Rickd

  7. #27
    Join Date
    Oct 2005
    Posts
    307

    Default

    I read a bunch of questions, but it seems you have answered them yourself. Do you need anything from me?

  8. #28
    Join Date
    May 2001
    Posts
    697

    Default

    THanks I think I have this works well now I assume this will work for multiple clients.?

    Also will reducing timeout on listerner callback speed the input or is it the terminator that makes it more responsive ie act on data received more quickly?
    Rickd

  9. #29
    Join Date
    Oct 2005
    Posts
    307

    Default

    The listener is going to run to timeout unless it receives the proper termination, so you just need to send the proper termination to get immediate response. I would think that after the initial exchange, the updates would be initialized by girder and not the client making the timeout irrelevant. Example: iRule sends a command for girder to execute, girder executes, the equipment responds with the new state, and girder pushes the states to all irule devices...

  10. #30
    Join Date
    May 2001
    Posts
    697

    Default

    Can I use anything as a termination eg <>
    Rickd

Page 3 of 4 FirstFirst 1234 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
  •