Http commands with username and password
George Krietsepis
Posts: 284
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
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
0
Comments
"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
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 ?
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.
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)
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.
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