Page 1 of 1

trigger json url from PHP script

Posted: Tuesday 26 January 2016 19:25
by henryd
Hello,

I was wondering if it's possible to turn lamp on from a PHP script on an external server.

set lamp on with url works: http://myurl:8080/json.htm?type=command ... itchcmd=On

now on external website in php code:
But this doen'st work:

Code: Select all

<?php 
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://url:8080/json.htm?type=command&param=switchlight&idx=57&switchcmd=On");
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
?>
PS: i have whitelisted the IP adress in my domoticz config of the external PHP server that sends the trigger. So i don't need to autorize.

I also checked fopen; Anybody an idea? or am i looking in the wrong direction?

Re: trigger json url from PHP script

Posted: Tuesday 26 January 2016 22:11
by Egregius
Check the link in my signature ;)
My whole domoticz is controlled by php.

Re: trigger json url from PHP script

Posted: Wednesday 27 January 2016 4:17
by nayr
henryd wrote:PS: i have whitelisted the IP adress in my domoticz config of the external PHP server that sends the trigger. So i don't need to autorize.
Are you using basic-auth? if so that whitelist dont mean diddily and you still need to provide auth credentials..

secondly, why dont you see what curl is erroring on..

Code: Select all

if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}

Re: trigger json url from PHP script

Posted: Wednesday 27 January 2016 6:02
by Egregius
I use file_get_contents:

Code: Select all

file_get_contents($domoticzurl.'json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd='.$cmd.'&level=0&passcode=')
Other examples can be viewed at https://github.com/Egregius/PHP-Custom- ... ctions.php

Re: trigger json url from PHP script

Posted: Wednesday 27 January 2016 11:51
by henryd
I use "Basic Auth" and i also have whitelisted the IP adres of the webserver.

I also added http://username:password@url:8080/json. ... itchcmd=On (username / password)

I tryed file_get_contents( but with no results. page keeps loading. very frustrating when i enter the URL.

Thnx for the CURL error report; it gives: "Curl error: Failed to connect to URL" connection timed out.

Thats a clear message. Probably authenticatie problem.

Could the missing or wrong content-type header cause this error "failed to connect" ?

Addition:
I just tryed a PHP Ping script to ping to my server. That didn't work. Port 80 is succesfull; but port 8080 is not succesfull.

strange; because the url works good in the browser. port 8080 is succesfull forwared. and the light turns on.