Home AMX User Forum AMX General Discussion

Http commands with username and password

Dear All,
I need to control a system ( ZWave) through IP and http commands. I have already managed to make the command structure ( see below ) but the problem is that I have to get through a username and password for the command to be applied.

send_string dvZWave, "'POST /api/devices/15/action/turnOff HTTP/1.1',13,10"
send_string dvZWave, "'Host: 192.168.10.120',13,10"
send_string dvZWave, "'Connection: keep-alive',13,10"
send_string dvZWave, "13,10"

When sending these commands, a reply says ( on NS diagnostics ) that an unauthorized user is trying to log in.

Below you can see an http fox snap shot while log in the system with u/p admin/admin.
How can I send the username and password with a send_string command before sending the above commands ?






George

Comments

  • sling100sling100 Junior Member Posts: 115
    You need to add an 'authorization' header:

    "Authorization: Basic root:root',13,10"

    The user/password bit needs to be encoded using base 64. There is a function to do it - do a forum search and I'm sure it'll pop up.

    Simon
  • George KrietsepisGeorge Krietsepis Member Posts: 251
    I added the authorization header and the command worked, BUT with a delay of about 2 minutes !!! I really don't know why this happens.
    Once the command is executed - after such a delay - I'm getting the below string:
    SendString 0:0:0 too long 297 truncated to 274
    I have tried many different syntax's with no success.
    Any ideas of why an http command may have such a delay ?

  • viningvining X Member Posts: 4,368
    How is the connection being handled? I would push a button to issue a command that would send a command string to Q which calls IP socket to open. The online event would trigger and that would trigger my code to send my Q'd string to device. With http I don't try to maintain the socket and I don't use any waits or wait untils in my code since everything is event triggered, intially by the button push and then the online event. Sounds to me the delay is in your code, maybe the socket is hanging open and it has to time out before opening again to send..
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    Once the command is executed - after such a delay - I'm getting the below string:
    SendString 0:0:0 too long 297 truncated to 274
    I have tried many different syntax's with no success.

    The SendString message is just a limitation of Netlinx Studio Diagnostic printouts.
    It's no indication that your code is good or bad.
    It just means it can't print that much with 1 SendString 0.
  • ericmedleyericmedley Senior Member - 4000+ posts Posts: 4,177
    I added the authorization header and the command worked, BUT with a delay of about 2 minutes !!! I really don't know why this happens.
    Once the command is executed - after such a delay - I'm getting the below string:
    SendString 0:0:0 too long 297 truncated to 274
    I have tried many different syntax's with no success.
    Any ideas of why an http command may have such a delay ?



    I don't know if the text quoted is accurate or not... But, you don't want to make your IP device 0:0:0. That may just be a typo or whatever. the first two ports (0:1:0 and 0:2:0) are reserved for use by the Netlinx master's internal clockwork. (Technically, I think the published statement is actually just port 0:1:0 - but I've noticed over the years that there seems to be some use of port 2 on occasion. I've never confirmed it with AMX. But I just tend to start at port 3 out of habit)
  • jbeamjbeam Junior Member Posts: 14

    The attached code does HTTP authentication(Which requires Base64 encoding the username and password) for a HTTP Post request to a streaming server I needed to talk to. It controls channel changes on the receiver boxes. I got the 'CHANGE_DISPLAY_CHANNEL' call working but didn't implement much else like HTTP response parsing which is commented out.

  • Duncan EllisDuncan Ellis Code Junkie Posts: 118

    @George Krietsepis said:
    Dear All,
    I need to control a system ( ZWave) through IP and http commands. I have already managed to make the command structure ( see below ) but the problem is that I have to get through a username and password for the command to be applied.

    send_string dvZWave, "'POST /api/devices/15/action/turnOff HTTP/1.1',13,10"
    send_string dvZWave, "'Host: 192.168.10.120',13,10"
    send_string dvZWave, "'Connection: keep-alive',13,10"
    send_string dvZWave, "13,10"

    When sending these commands, a reply says ( on NS diagnostics ) that an unauthorized user is trying to log in.

    Below you can see an http fox snap shot while log in the system with u/p admin/admin.
    How can I send the username and password with a send_string command before sending the above commands ?

    George

    Youre brave dealing with Fibaro. I had to use the original Homecentre on one project....

    this is the header that I built

    sURI = "'/api/scenes/',itoa(nSceneID),'/action/start'"
    s64 = fnEncodeBase10toBase64str("sFibaroUser,':',sFibaroPass")

    sHTTPheader= "'POST ',sURI,' HTTP/1.1',$0D,$0A,
    'Host: ',sFibaroIP,$0D,$0A,
    'Authorization: Basic ',s64,$0D,$0A"

    I found that if you put more information in it than the above, it either fails or rejects the command. For Home centre, thats all you need. Open the port and send the command on the ONLINE event.
    We just hd to trigger scenes set up by the brain surgeon who chose fibaro in the first place. Worst lighting system I've ever dealt with.
    Hope that helps

Sign In or Register to comment.