API login

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
cbnidk
Posts: 41
Joined: 14 May 2015 11:25

API login

Post by cbnidk »

Hi

is there a how to do it I have a php script where I can see the temparatur from the Zwave me by API
but after a new install it is not working any more
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,'http://192.168.1.69:8083/ZWaveAPI/Run/d ... .val.value');
echo "Stue = ";
$number = curl_exec($ch);
$number = sprintf('%.2f', $number);
echo $number;
echo "&nbsp;&#8451;";
?>
I have to login in now I have tryed everthing that I can fandt but nothing is working

the php page is on a other server, not the Raspberry pi

Claus
Provo
Posts: 112
Joined: 19 Oct 2016 19:54

Re: API login

Post by Provo »

Add your username and password separated with a colon into your url, like this:

http://username:password@192.168.1.69:8083/
cbnidk
Posts: 41
Joined: 14 May 2015 11:25

Re: API login

Post by cbnidk »

it was tried but this is not working
if I tried it in a brower I get not logged in
Provo
Posts: 112
Joined: 19 Oct 2016 19:54

Re: API login

Post by Provo »

Ok, if you are sure your credentials exist and are correct (you might want to double check this – easy to forget when reinstalling), then I suppose php curl doesn't support that kind of basic auth syntax. Try adding this instead, grouped with your other curl_setopt() calls:

curl_setopt($ch, CURLOPT_USERPWD, 'yourusername:yourpassword');
cbnidk
Posts: 41
Joined: 14 May 2015 11:25

Re: API login

Post by cbnidk »

Hi

can some one tell me how to put this code
curl_setopt($ch, CURLOPT_USERPWD, 'yourusername:yourpassword');
in my code, maybe there have to be more code, I cant get it to work
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,'http://192.168.1.69:8083/ZWaveAPI/Run/d ... .val.value');
echo "Stue = ";
$number = curl_exec($ch);
$number = sprintf('%.2f', $number);
echo $number;
echo "&nbsp;&#8451;";
?>



Claus
cbnidk
Posts: 41
Joined: 14 May 2015 11:25

Re: API login

Post by cbnidk »

hi
I have now get it to work with this code

<?php
$login = 'admin';
$password = 'password';
$url = 'http://192.168.20.250:8083/ZWaveAPI/Run ... .val.value';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$number = curl_exec($ch);
curl_close($ch);
echo "Stue = ";
$number = sprintf('%.2f', $number);
echo $number;
echo "&nbsp;&#8451;";
?>
claus
Post Reply