I have a question regarding php and curl to particle functions. I am using curl instead of js to do my post because I am trying to have this done via a cron job. I am pretty new with the particle functions and I am having some trouble getting the result I was expecting. I think that the curl code is working but I am confused why is it not triggering the function to turn the relay on.
Here is the original js code that does work.
var deviceID = "xxxxxxxx";
var accessToken = xxxxxxxxxxxxxxxxxxxxxxx";
function setRelay() {
var id = "2";
var setRelay = "relay" + id; //Set Relay Variable
var statusRelay = "on";
var requestURL = "https://api.spark.io/v1/devices/" + deviceID + "/" + setRelay + "/";
$.post( requestURL, { params: statusRelay, access_token: accessToken });
}
setRelay();
Here is the new curl code that seems to work but my relay does not come on.
$my_device = "XXXXXXXX";
$my_token = "XXXXXXXXXXXXXXXXXXXXXXXx";
$url = "https://api.particle.io/v1/devices/".$my_device."/relay2?access_token=".$my_token;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, array('args' => "on"));
$response = curl_exec( $ch );
curl_close( $ch );
echo $response;
Here is the response
{"id":"xxxxxxxxxxxxxxxxxx","last_app":"","connected":true,"return_value":-1}