trigger json url from PHP script

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
henryd
Posts: 7
Joined: Wednesday 23 December 2015 22:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Zeewolde
Contact:

trigger json url from PHP script

Post 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?
Raspberry Pi / Arduino / Youless / Aeon z-stick gen5 / RFXCom / Fibaro sensor / Qubino flush 2 relays / MySensors.org
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: trigger json url from PHP script

Post by Egregius »

Check the link in my signature ;)
My whole domoticz is controlled by php.
User avatar
nayr
Posts: 354
Joined: Tuesday 11 November 2014 18:42
Target OS: Linux
Domoticz version: github
Location: Denver, CO - USA
Contact:

Re: trigger json url from PHP script

Post 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);
}
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: trigger json url from PHP script

Post 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
henryd
Posts: 7
Joined: Wednesday 23 December 2015 22:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Zeewolde
Contact:

Re: trigger json url from PHP script

Post 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.
Raspberry Pi / Arduino / Youless / Aeon z-stick gen5 / RFXCom / Fibaro sensor / Qubino flush 2 relays / MySensors.org
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest