Home AMX User Forum NetLinx Studio

Help with Telnet Login

Greetings,

I am trying to connect to an IP device via telnet from Netlinx. My connection is opened as follows:
<code>
DEFINE_START
WAIT 200 IP_CLIENT_OPEN (nPort,cIP,23,1)
</code>
nPort is my Netlinx port which is 7
cIP is the IP address of the device I would like to talk to.
I am seeing the login prompt come in. After the login prompt is seen...
<code>
SEND_STRING dv,"login,$0D"
</code>
Login is a char array containing the login name. After the string is sent, I do not get any response from the device. It just keeps sending the login prompt every minute or so. Using a Windows Telnet connection it works as expected, asking me for a password.

Any idea what I could be doing wrong?

Thanks.

Comments

  • viningvining Posts: 4,368
    There could be some reall goofy telnet crap during the intial telnet handshake:
    http://www.amxforums.com/showthread.php?6856-TELNET-commands&highlight=telnet+commands

    What are you trying to talk to?

    Most things like Lutron which also uses port 23 is pretty much a straight forward back and forth procedure. Catch what it sends when you open the client connection and respond accordingly based on the devices api. But if that's what you're doing, first verify the login response the device expects is formatted the way the api specifies.

    Post what the device is and maybe someone will have working code they'd like to share or at least a word of advice. If you have the api post that too, especially if it's an oddball device.
  • TurnipTruckTurnipTruck Posts: 1,485
    It is a Lutron device. As soon as I see the 'login: ' I am sending the login name.
  • viningvining Posts: 4,368
    Here's the pertinent section of my code:
    	 }
    		    ACTIVE(find_string(cHWI_Str,"'closing connection...LOGIN:'",1) == 1):
    			 {
    			 fnHWI_Q_QCmd("HWI_USER_NAME,',',HWI_PASSWORD") ;
    			 fnHWI_DeBug("'RCVD- "',cHWI_Str,'", & SENT USER-:',HWI_USER_NAME,' & SENT PASS-: ',HWI_PASSWORD,' :DEBUG<',ITOA(__LINE__),'>'") ;
    			 REMOVE_STRING(cHWI_Str,"': '",1) ;
    			 }
    		    ACTIVE(find_string(cHWI_Str,"'LOGIN: '",1) == 1 || find_string(cHWI_Str,"'login: '",1) == 1):
    			 {
    			 fnHWI_Q_QCmd("HWI_USER_NAME,',',HWI_PASSWORD") ;
    			 fnHWI_DeBug("'RCVD- "',cHWI_Str,'", & SENT USER-:',HWI_USER_NAME,' & SENT PASS-: ',HWI_PASSWORD,' :DEBUG<',ITOA(__LINE__),'>'") ;
    			 REMOVE_STRING(cHWI_Str,"': '",1) ;
    			 }
    		    ACTIVE(find_string(cHWI_Str,"'LOGIN: '",1) || find_string(cHWI_Str,"'login: '",1)): //catch any login rx anywhwere and respond
    			 {
    			 fnHWI_Q_QCmd("HWI_USER_NAME,',',HWI_PASSWORD") ;
    			 fnHWI_DeBug("'RCVD- "',cHWI_Str,'", & SENT USER-:',HWI_USER_NAME,' & SENT PASS-: ',HWI_PASSWORD,' :DEBUG<',ITOA(__LINE__),'>'") ;
    			 REMOVE_STRING(cHWI_Str,"': '",1) ;
    			 }
    		    ACTIVE(find_string(cHWI_Str,"'login incorrect'",1)):
    			 {
    
    Note I duplicated the ACTIVE since it should always appear at the beginning of the string being parsed but just in case it isn't the second will catch it. So why not just remove the first active you say, well cusz that's the one that's supposed to work and I'm stubborn.

    edit:

    Just in case you're working with RA2 or HomeWorks QS you can try this code:
     else if(find_string(cRA2_Str,'login: ',1) || find_string(cRA2_Str,'password: ',1))
    	  {
    	  SELECT
    	       {
    	       ACTIVE(find_string(cRA2_Str,"'login: '",1)): //catch any login rx anywhwere and respond
    		    {
    		    fnRA2_Clear_ToSend() ;
    		    fnRA2_Q_QCmd("RA2_USER_NAME") ;
    		    fnRA2_DeBug("'RX: "',cRA2_Str,'", & SENT USER-: ',RA2_USER_NAME,' :DEBUG<',ITOA(__LINE__),'>'") ;
    		    REMOVE_STRING(cRA2_Str,"': '",1) ;
    		    }
    	       ACTIVE(find_string(cRA2_Str,"'password: '",1)):
    		    {
    		    fnRA2_Clear_ToSend() ;
    		    fnRA2_Q_QCmd("RA2_PASSWORD") ;
    		    fnRA2_DeBug("'RX: "',cRA2_Str,'", & SENT PASS-: ',RA2_PASSWORD,' :DEBUG<',ITOA(__LINE__),'>'") ;
    		    REMOVE_STRING(cRA2_Str,"': '",1) ;
    		    }
    		ACTIVE(1)://PRINT ANYTHING RCV'D WE AREN'T LOOKING FOR
    		    {
    		    fnRA2_Clear_ToSend() ;
    		    fnRA2_DeBug("'RX:(Not Logged in) UNKOWN STRING: "',cRA2_Str,'" :DEBUG<',ITOA(__LINE__),'>'") ;
    		    cRA2_Str = '' ;
    		    }
    	       }
    
  • Joe HebertJoe Hebert Posts: 2,159
    CRLF
    It is a Lutron device. As soon as I see the 'login: ' I am sending the login name.

    After I get the login prompt I send the username a comma the password and a carriage return line feed:
    SEND_STRING dvLutron,"cUser,',',cPassword,CRLF"
    
    <code>
    SEND_STRING dv,"login,$0D"
    </code>
    Login is a char array containing the login name. After the string is sent, I do not get any response from the device. It just keeps sending the login prompt every minute or so. Using a Windows Telnet connection it works as expected, asking me for a password.
    Windows is probably sending a carriage return line feed and you are just sending a carriage return.
    Also you can send the user name and password with one string if you want.
  • viningvining Posts: 4,368
    I think the earlier versions of HomeWorks required just the "13", maybe interactive? Or maybe it was serial comms required "13" while IP comms required "13,10". I don't remember exactly when or what but there was a shift at some point. Both the current illuminations, RA2 and QS use the "13,10" as Joe indicated but RA2 & QS have seperate responses for user and password and a completely different command/response architecture.
  • TurnipTruckTurnipTruck Posts: 1,485
    Thanks guys! Will have another look at it soon.
Sign In or Register to comment.