Homeassistant sensor, Bash-script with curl and json

jonrub11

n3wb
Joined
Dec 13, 2018
Messages
18
Reaction score
0
Location
Sweden
Hi,

I am trying to create a sensor for Homeassistant so I can see which BlueIris profile is active for the moment.

I have created a bash-script for the json commands but I am stuck, it wont log me in.

# Ask about sessionkey and add it to $sessionkey
sessionkey=$(curl --header "Content-Type: application/json" --request POST --data '{"cmd":"login"}' http://192.168.1.205:81/json | jq -r '.session')
# create responsekey
responsekey=$(echo -n username:$sessionkey:password | md5sum)
# Log in via json
curl --header "Content-Type: application/json" --request POST --data '{"cmd":"login","session":'"$sessionkey"',"response":'"$responsekey"'}' http://192.168.1.205:81/json

Any ideas?

Thanks in advance!
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,673
Reaction score
14,017
Location
USA
Does the response key look like a simple hex string? It might not matter but I know UI3's login code produces lower-case abcdef characters.

Are you able to capture the network traffic being sent and received?
 

jonrub11

n3wb
Joined
Dec 13, 2018
Messages
18
Reaction score
0
Location
Sweden
Sorry for late reply.

Yes, I have tested with wireshark and the result is in the attached image. I think the spaces is just how Wireshark displays it but what could be the problem is the dash (-) at the end.
What do you think? I have no idea how to remove it.

Thanks!
 

Attachments

jonrub11

n3wb
Joined
Dec 13, 2018
Messages
18
Reaction score
0
Location
Sweden
And when I solved that problem I got a new one. :)

Now it works as I want when I run each line one by one. When I put them in a bash-script, everything after a pipe (|) prints on a new line.
 
Joined
Aug 3, 2015
Messages
3,820
Reaction score
12,272
Location
Charlotte
And when I solved that problem I got a new one. :)

Now it works as I want when I run each line one by one. When I put them in a bash-script, everything after a pipe (|) prints on a new line.
Share/post/attach the relevant portion of your BASH script (as a .txt text file) and I'll try to help.
 

jonrub11

n3wb
Joined
Dec 13, 2018
Messages
18
Reaction score
0
Location
Sweden
Thank you for your willingness to help. I actually solved the problem by running all commands on the same line separeted with ; .
 

joydashy

n3wb
Joined
Mar 27, 2018
Messages
2
Reaction score
2
Thank you for your willingness to help. I actually solved the problem by running all commands on the same line separeted with ; .
Could you post your working script, I am trying to do this also, without luck so far.
 
Top