Page 1 of 1

API login

Posted: 16 Feb 2018 21:41
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

Re: API login

Posted: 17 Feb 2018 09:38
by Provo
Add your username and password separated with a colon into your url, like this:

http://username:password@192.168.1.69:8083/

Re: API login

Posted: 17 Feb 2018 17:17
by cbnidk
it was tried but this is not working
if I tried it in a brower I get not logged in

Re: API login

Posted: 19 Feb 2018 08:31
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');

Re: API login

Posted: 27 Feb 2018 21:04
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

Re: API login

Posted: 27 Feb 2018 22:38
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