Home AMX User Forum NetLinx Studio

GET method control HTTP VLC

I want to share an example with VLC via HTTP
I propose here to share management capabilities VLC.
Here is an example of the GET method with VLC.
VLC player, perform management through the management interface to the HTTP server example
Host server: 10.0.7.18 port 8081
PROGRAM_NAME='Main Program'
(***********************************************************)
(***********************************************************)
(*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)
(*
    $History: $
*)
(***********************************************************)
(*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_DEVICE
dvIPDeviceVLC 		= 0:5:0
dvTP			= 32000:1:0
(***********************************************************)
(*               CONSTANT DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_CONSTANT

CHAR cDevTelnetVLC[15] = '10.0.7.18'  		//IP Address VLC server

INTEGER nIPPORT		=	8081		/// IP PORT VLC server
INTEGER nProtocol	=	1

LONG tlOnline	=	1

(***********************************************************)
(*              DATA TYPE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_TYPE

(***********************************************************)
(*               VARIABLE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_VARIABLE

integer nOnline
integer nOffline
integer nError
integer nData
integer btnCtr[]	=
			{
			    1,
			    2,
			    3,
			    4,
			    5,
			    6,
			    7,
			    8,
			    9
			}

DEFINE_FUNCTION CHAR[100] SMTPGetIpError (LONG nNUM)
{
     SWITCH (nNUM)
     {
	  //// ERROR REPORTING
	  CASE 2:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): General Failure (IP_CLIENT_OPEN/IP_SERVER_OPEN)'"
	  CASE 4:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Unknown host (IP_CLIENT_OPEN)'"
	  CASE 6:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Connection refused (IP_CLIENT_OPEN)'"
	  CASE 7:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Connection timed out (IP_CLIENT_OPEN)'"
	  CASE 8:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Unknown connection error (IP_CLIENT_OPEN)'"
	  CASE 9:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Already closed (IP_CLIENT_CLOSE/IP_SERVER_CLOSE)'"
	  CASE 14:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Local port already used (IP_CLIENT_OPEN/IP_SERVER_OPEN)'"
	  CASE 16:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Too many open sockets (IP_CLIENT_OPEN/IP_SERVER_OPEN)'"
	  CASE 17:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Local Port Not Open (IP_SERVER_OPEN)'"
	  DEFAULT:
	       RETURN "'IP ERROR (',ITOA(nNUM),'): Unknown'"
     }
}
(***********************************************************)
(*               LATCHING DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_LATCHING

(***********************************************************)
(*       MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW           *)
(***********************************************************)
DEFINE_MUTUALLY_EXCLUSIVE

(***********************************************************)
(*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)

(***********************************************************)
(*                STARTUP CODE GOES BELOW                  *)
(***********************************************************)
DEFINE_START

IP_CLIENT_OPEN(dvIPDeviceVLC.PORT,cDevTelnetVLC,nIPPort,IP_TCP) /// OPEN IP CONNECTION
(***********************************************************)
(*                THE EVENTS GO BELOW                      *)
(***********************************************************)
DEFINE_EVENT

DATA_EVENT[dvIPDeviceVLC]
{
     ONLINE:
     {
	  nOnline = 100
	  SEND_STRING 5001:0:0,"'dv1-DEVICE ONLINE- PORT ',ITOA(data.device.port)"/// TELL ME ABOUT IT
     }
     OFFLINE:
     {
	  nOffline = 100
	  IP_CLIENT_OPEN(dvIPDeviceVLC.PORT,cDevTelnetVLC,nIPPort,IP_TCP) /// OPEN IP CONNECTION
	  SEND_STRING 5001:0:0,"'dv1-DEVICE OFFLINE- PORT ',ITOA(data.device.port)" /// TELL ME ABOUT IT
     }
     ONERROR:
     {
	  nError = 100
	  // Print error
	  SEND_STRING 5001:0:0,"'dv1-REPORT- PORT ',ITOA(data.device.port),'-',SMTPGetIpError(Data.Number)" /// TELL ME ABOUT THE ERROR
	  /// Act Accordingly
	  SWITCH(data.number)
	       {
	       CASE 14:
		    
	       CASE 17:
		    IP_CLIENT_OPEN(dvIPDeviceVLC.PORT,cDevTelnetVLC,nIPPort,IP_TCP) /// OPEN IP CONNECTION
	       }
     }
     STRING:
     {
	  nData = 100
	  SEND_STRING 5001:0:0, data.text
     }
}

BUTTON_EVENT [dvTP, btnCtr]
{
    PUSH:
    {
	SWITCH (button.input.channel)
	{
	    case 1: //pause
	    {
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_pause HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	    case 2: //play
	    {
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_play HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	    case 3: //stop
	    {
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_stop HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	    case 4: //next
	    {
		
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_next HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	    case 5: //previous
	    {
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_previous HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	    case 6: //pl_delete 
	    {
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_delete HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	    case 7: //pl_loop  
	    {
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_loop HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	    case 8: //pl_repeat   
	    {
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_repeat HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	    case 9: //fullscreen    
	    {
		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=fullscreen HTTP/1.0',$0D,$0A,$0D,$0A"
	    }
	}
    }
}

(***********************************************************)
(*            THE ACTUAL PROGRAM GOES BELOW                *)
(***********************************************************)
DEFINE_PROGRAM

(***********************************************************)
(*                     END OF PROGRAM                      *)
(*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
(***********************************************************)


Comments

  • vincenvincen Posts: 526
    Thanks for the share ;)
  • not for that,
    I would appreciate if anyone share the parser (feedback) to process the HTML code.
  • continue,
    feedback example:
    PROGRAM_NAME='Main Program'
    (***********************************************************)
    (***********************************************************)
    (*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
    (***********************************************************)
    (* System Type : NetLinx                                   *)
    (***********************************************************)
    (* REV HISTORY:                                            *)
    (***********************************************************)
    (*
        $History: $
    *)
    (***********************************************************)
    (*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_DEVICE
    dvIPDeviceVLC 		= 0:5:0
    dvTP			= 34001:1:0  //test virtual device
    (***********************************************************)
    (*               CONSTANT DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_CONSTANT
    
    CHAR cDevTelnetVLC[15] = '10.0.7.18'  		//IP Address VLC server
    
    INTEGER nIPPORT		=	8081		/// IP PORT VLC server
    INTEGER nProtocol	=	1
    
    LONG tlOnline	=	1
    		
    (***********************************************************)
    (*              DATA TYPE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_TYPE
    
    STRUCTURE t_StatusVLCPayer
    {
        char pVOLUME[100]
        char pLENGHT[100]
        char pTIME[100]
        char pSTATE[100]
        char pPOSITION[100]
        char pFULLSCREEN[100]
        char pRANDOM[100]
        char pLOOP[100]
        char pREPEAT[100]
        char pTITLE[100]
        char pARTIST[100]
        char pREADBYTES[100] 
    }
    
    (***********************************************************)
    (*               VARIABLE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_VARIABLE
    
    t_StatusVLCPayer StatusVLCPayer
    char bufferVLC[5000]
    
    integer nOnline
    integer nOffline
    integer nError
    integer nData
    integer btnCtr[]	=
    			{
    			    1,
    			    2,
    			    3,
    			    4,
    			    5,
    			    6,
    			    7,
    			    8,
    			    9,
    			    10
    			}
    integer POS, POS2, inc
    integer posSt
    integer posEnd
    integer lengthPos
    char u[20],r[20]
    
    DEFINE_FUNCTION CHAR[100] SMTPGetIpError (LONG nNUM)
    {
         SWITCH (nNUM)
         {
    	  //// ERROR REPORTING
    	  CASE 2:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): General Failure (IP_CLIENT_OPEN/IP_SERVER_OPEN)'"
    	  CASE 4:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Unknown host (IP_CLIENT_OPEN)'"
    	  CASE 6:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Connection refused (IP_CLIENT_OPEN)'"
    	  CASE 7:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Connection timed out (IP_CLIENT_OPEN)'"
    	  CASE 8:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Unknown connection error (IP_CLIENT_OPEN)'"
    	  CASE 9:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Already closed (IP_CLIENT_CLOSE/IP_SERVER_CLOSE)'"
    	  CASE 14:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Local port already used (IP_CLIENT_OPEN/IP_SERVER_OPEN)'"
    	  CASE 16:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Too many open sockets (IP_CLIENT_OPEN/IP_SERVER_OPEN)'"
    	  CASE 17:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Local Port Not Open (IP_SERVER_OPEN)'"
    	  DEFAULT:
    	       RETURN "'IP ERROR (',ITOA(nNUM),'): Unknown'"
         }
    }
    DEFINE_FUNCTION char[100] fnParserState (char txtHTML[5000], char txtState[20])
    {
        IF ((FIND_STRING(txtHTML,"'</',txtState,'>'",1)) && (FIND_STRING(txtHTML,"'<',txtState,'>'",1)))
        {
    	u = txtState
    	r = "'<',txtState,'>'" //l=8
    	lengthPos = length_string(r)//("'<',txtState,'>'")		// <volume> l=12
    	posSt = FIND_STRING(txtHTML,"'<',txtState,'>'",1) + lengthPos	// + length_string("'<',txtState,'>'")
    
    	posEnd = FIND_STRING(txtHTML,"'</',txtState,'>'",1)
    	
    	RETURN mid_string(txtHTML, (posSt), (posEnd-posSt))
        }
        ELSE
        {
    	RETURN 'Error'
        }
    }
    
    
    (***********************************************************)
    (*               LATCHING DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_LATCHING
    
    (***********************************************************)
    (*       MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW           *)
    (***********************************************************)
    DEFINE_MUTUALLY_EXCLUSIVE
    
    (***********************************************************)
    (*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
    (***********************************************************)
    (* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
    (* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
    
    (***********************************************************)
    (*                STARTUP CODE GOES BELOW                  *)
    (***********************************************************)
    DEFINE_START
    
    IP_CLIENT_OPEN(dvIPDeviceVLC.PORT,cDevTelnetVLC,nIPPort,IP_TCP) /// OPEN IP CONNECTION
    create_buffer dvIPDeviceVLC, bufferVLC
    (***********************************************************)
    (*                THE EVENTS GO BELOW                      *)
    (***********************************************************)
    DEFINE_EVENT
    
    DATA_EVENT[dvIPDeviceVLC]
    {
         ONLINE:
         {
    	  nOnline = 100
    	  SEND_STRING 5001:0:0,"'DEVICE ONLINE- PORT ',ITOA(data.device.port)"/// TELL ME ABOUT IT
         }
         OFFLINE:
         {
    	  nOffline = 100
    	  IP_CLIENT_OPEN(dvIPDeviceVLC.PORT,cDevTelnetVLC,nIPPort,IP_TCP) /// OPEN IP CONNECTION
    	  SEND_STRING 5001:0:0,"'DEVICE OFFLINE- PORT ',ITOA(data.device.port)" /// TELL ME ABOUT IT
         }
         ONERROR:
         {
    	  nError = 100
    	  // Print error
    	  SEND_STRING 5001:0:0,"'REPORT- PORT ',ITOA(data.device.port),'-',SMTPGetIpError(Data.Number)" /// TELL ME ABOUT THE ERROR
    	  /// Act Accordingly
    	  SWITCH(data.number)
    	       {
    	       CASE 14:
    		    
    	       CASE 17:
    		    IP_CLIENT_OPEN(dvIPDeviceVLC.PORT,cDevTelnetVLC,nIPPort,IP_TCP) /// OPEN IP CONNECTION
    	       }
         }
         STRING:
         {
    	stack_var char param[20]
    	inc++
    	  nData = 100
    	  SEND_STRING 5001:0:0, data.text
    
    //	  param = 'volume'
    	 StatusVLCPayer.pVOLUME = fnParserState (bufferVLC, 'volume')
    	  StatusVLCPayer.pLENGHT = fnParserState (bufferVLC, 'length')
    	  StatusVLCPayer.pTIME = fnParserState (bufferVLC, 'time')
    	  StatusVLCPayer.pSTATE = fnParserState (bufferVLC, 'state') //playing or stopping negative
    	  StatusVLCPayer.pPOSITION = fnParserState (bufferVLC, 'position')
    	  StatusVLCPayer.pFULLSCREEN = fnParserState (bufferVLC, 'fullscreen')
    	  StatusVLCPayer.pRANDOM = fnParserState (bufferVLC, 'random')
    	  StatusVLCPayer.pLOOP = fnParserState (bufferVLC, 'loop')
    	  StatusVLCPayer.pREPEAT = fnParserState (bufferVLC, 'repeat')
    	  StatusVLCPayer.pTITLE = fnParserState (bufferVLC, 'title')
    	  StatusVLCPayer.pARTIST = fnParserState (bufferVLC, 'artist')
         }
    }
    
    BUTTON_EVENT [dvTP, btnCtr]
    {
        PUSH:
        {
    	bufferVLC = ''
    	SWITCH (button.input.channel)
    	{
    	    case 1: //pause
    	    {
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_pause HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 2: //play
    	    {
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_play HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 3: //stop
    	    {
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_stop HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 4: //next
    	    {
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_next HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 5: //previous
    	    {
    	    
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_previous HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 6: //pl_delete 
    	    {
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_delete HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 7: //pl_loop  
    	    {
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_loop HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 8: //pl_repeat   
    	    {
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=pl_repeat HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 9: //fullscreen    
    	    {
    		send_string dvIPDeviceVLC, "'GET /requests/status.xml?command=fullscreen HTTP/1.0',$0D,$0A,$0D,$0A"
    	    }
    	    case 10: //test 
    	    {
    		POS2 = 500
    		
    	    }
    	}
        }
    }
    
    (***********************************************************)
    (*            THE ACTUAL PROGRAM GOES BELOW                *)
    (***********************************************************)
    DEFINE_PROGRAM
    
    (***********************************************************)
    (*                     END OF PROGRAM                      *)
    (*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
    (***********************************************************)
    
    
    
  • ericmedleyericmedley Posts: 4,177
    I'm curious why you are sending strings to device 5001:0:0.
  • jimmywjimmyw Posts: 112
    its funny, I thought it was odd too, but, its seems like its actually the "netlinx" way to do it instead of the "axlink" way.
    but I would assume it would be 0:0:0 not 5001:0:0
  • ericmedleyericmedley Posts: 4,177
    jimmyw wrote: »
    its funny, I thought it was odd too, but, its seems like its actually the "netlinx" way to do it instead of the "axlink" way.
    but I would assume it would be 0:0:0 not 5001:0:0

    While what you say is true it hits wide of my question. I'm not the best communicator. :) The thrust of my question was to ask for what reason he was sending notifications to the NI device and not the master. My guess is that he was assuming he WAS sending notifications to the master and not the device portion of the box.

    I've seen a lot of programmers not quite get the concept of the integrated master. It's seems that some people have a hard time getting their head around the idea that the box actually contains several little boxes (conceptually) integrated on the same PC board.

    Also, I was curious if there was some new exciting thing I didn't know about that sending to port zero on the NI device facilitated or something.
    e
  • ericmedley wrote: »
    I'm curious why you are sending strings to device 5001:0:0.

    I have been an example to work with VLC player.
    Send to a device 5001:0:0, I was comfortable watching message in the notification window. You can also look in the Diagnostic window, sending send_string 0, "'xxx'", including Diagnostics -> Enabe Netlinx Internal Diagnostics Messages
  • tell me please,
    How to send a message Invite device - 0:5:0 (local port) through the window "Control a Device .."
    I try to send a Control a Device .. (Device - 0, Port - 5, System - an, Message (s) to Send check String Expressions - "'GET / requests / status.xml? Command = pl_pause HTTP/1.0', $ 0D, $ 0A, $ 0D, $ 0A "), but the VLC server does not understand this command.
    , Although a one button command "'GET / requests / status.xml? Command = pl_pause HTTP/1.0', $ 0D, $ 0A, $ 0D, $ 0A") perfectly understood
  • viningvining Posts: 4,368
    zaharov wrote: »
    tell me please,
    How to send a message Invite device - 0:5:0 (local port) through the window "Control a Device .."
    I try to send a Control a Device .. (Device - 0, Port - 5, System - an, Message (s) to Send check String Expressions - "'GET / requests / status.xml? Command = pl_pause HTTP/1.0', $ 0D, $ 0A, $ 0D, $ 0A "), but the VLC server does not understand this command.
    , Although a one button command "'GET / requests / status.xml? Command = pl_pause HTTP/1.0', $ 0D, $ 0A, $ 0D, $ 0A") perfectly understood

    Control device doesn't work with IP devices.
  • Thanks Vining

    Сan somebody share his ideas to work with VLC?
    I want to write a complete unit of work with this player. I want to implement a control with the touch panel to control not less than the HTML page.
  • ericmedleyericmedley Posts: 4,177
    zaharov wrote: »
    I have been an example to work with VLC player.
    Send to a device 5001:0:0, I was comfortable watching message in the notification window. You can also look in the Diagnostic window, sending send_string 0, "'xxx'", including Diagnostics -> Enabe Netlinx Internal Diagnostics Messages

    I guess that's my point. But never mind. :/ If you getting the results you need then who am I to argue? :)

    You can kinda accomplish sending something to an IP port by routing it through a virtual device temporarily.

    Sonething like
    define_device
    
    dv_IP_port = 0:4:0
    
    vdv_testing = 34001:1:0
    
    Define_event
    
    Data_event[vdv_testing]
    {
    String: 
      {
      send_string dv_IP_port, data.text
      }
    Command:
      {
      send_command dv_IP_port, data.text
      }
    }
    

    Then send stuff to the virtual dev in control device.
  • Thank you, Ericmedley

    I'll try,
    Answer, and how to connect virtual device (vdv_testing) with a local port (dv_IP_port)
  • ericmedleyericmedley Posts: 4,177
    zaharov wrote: »
    Thank you, Ericmedley

    I'll try,
    Answer, and how to connect virtual device (vdv_testing) with a local port (dv_IP_port)

    There is no need to connect the two devices. (Combine..) By sending a command to the testing device the code will send it on to the port for you. You still have to open the IP port, connect it to something out there and so forth. It's just a work-around for being able to send strings to an IP port.
Sign In or Register to comment.