* @project phpSpark * @file examples/listDevices.php * @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // List all the devices on your account $spark->debug("Spark Devices"); if ($spark->listDevices() == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @project phpSpark * @file examples/setDeviceName.php * @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // Rename your Spark Core $spark->debug("Spark Set Device Name"); if ($spark->renameDevice($deviceID, uniqid('phpSpark_')) == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @project phpSpark * @file examples/uploadFirmware.php * @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // Upload firmware to your Spark Core $spark->debug("Spark Firmware Upload"); if ($spark->uploadFirmware($deviceID, "tinker.bin", "tinker.bin", false) == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // create spark webhook $spark->debug("Create Spark Web Hook"); $extras = array(); $extras['mydevices'] = true; $extras['deviceid'] = $deviceID; $extras['requestType'] = "POST"; //$extras['headers'] = array("X-Device-ID"=>"test"); //$extras["form"] = json_encode(array("form_name"=>"form_value")); // Not implemented server side yet //$extras['json'] = array("json_key"=>"json_value"); $extras['query'] = array("p1" => "v1"); $extras['auth'] = array("username" => "test", "password" => "test_password"); // headers & auth are mutually exclusive (can't have both at the same time or the call will fail on the cloud side) // json and query are mutually exclusive $fields = array_merge(array('event' => $event, 'url' => $url, 'deviceid' => $deviceID), $extras); print_r($fields); if ($spark->newWebhook('test', 'http://google.com/', $extras) == true) { $spark->debug_r($spark->getResult());
/* * @project phpSpark * @file examples/listTokens.php * @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // List of Spark core tokens $spark->debug("Spark Tokens"); $spark->setAuth($username, $password); if ($spark->listAccessTokens() == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @project phpSpark * @file examples/newAccessToken.php * @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Delete a specific token $token = "EXAMPLE_TOKEN"; $spark->debug("Delete Token " . $token); $spark->setAuth($username, $password); if ($spark->deleteToken($token) == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
/* * @project phpSpark * @file examples/newAccessToken.php * @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // List of Spark core tokens $spark->debug("New Access Token"); $spark->setAuth($username, $password); if ($spark->newAccessToken() == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. Flash the code in phpSpark.firmware.cpp to your Spark Core and try these functions out */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set the timeout to be pretty short (in case your core is offline) $spark->setTimeout("5"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // Turn on the D7 LED (requires Tinker to be on your Spark Core) $spark->debug("Spark Function"); if ($spark->callFunction($deviceID, "digitalwrite", "D7,HIGH") == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @project phpSpark * @file examples/getVariable.php * @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. Flash the code in phpSpark.firmware.cpp to your Spark Core and try these functions out */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // Grab the current uptime of your core (requires a modified version of tinker on your Spark Core) $spark->debug("Spark Variable"); if ($spark->getVariable($deviceID, "uptime") == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @project phpSpark * @file examples/signalDevice.php * @authors Devin Pearson (devin@blackhat.co.za) * @date March 19, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // Signals the spark with a rainbow display using the rgb led $spark->debug("signal Spark Device"); if ($spark->signalDevice($deviceID, 1) == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
/* * @project phpSpark * @file examples/getToken.php * @authors Devin Pearson (devin@blackhat.co.za) * @date March 18, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Create Spark core token $spark->debug("generate Token"); $spark->setAuth($username, $password); if ($spark->createAccessToken() == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @project phpSpark * @file examples/deleteDevice.php * @authors Devin Pearson (devin@blackhat.co.za) * @date March 18, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // Remove the device from your account $spark->debug("Remove Device"); if ($spark->deleteDevice($deviceID) == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @project phpSpark * @file examples/claimDevice.php * @authors Devin Pearson (devin@blackhat.co.za) * @date March 18, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // claim a device on your account $spark->debug("Claim Device"); if ($spark->claimDevice($deviceID) == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }
* @project phpSpark * @file examples/listWebhooks.php * @authors Harrison Jones (harrison@hhj.me) * @date March 16, 2015 * @brief Examples file. */ // For testing purposes we want to be as strict as possible error_reporting(E_STRICT); // Include the required files. You will need to rename phpSpark.config.sample.php to phpSpark.config.php and then set the values within to use this example if (@(include '../phpSpark.class.php') === false) { die("Unable to load phpSpark class"); } if (@(include '../phpSpark.config.php') === false) { die("Unable to load phpSpark configuration file"); } // Grab a new instance of our phpSpark object $spark = new phpSpark(); // Set the internal debug to true. Note, calls made to $spark->debug(...) by you ignore this line and display always $spark->setDebug(true); // Set the debug calls to display pretty HTML format. Other option is "TEXT". Note, calls made to $spark->debug(...) display as set here $spark->setDebugType("HTML"); // Set our access token (set in the phpConfig.config.php file) $spark->setAccessToken($accessToken); // List of Spark core tokens $spark->debug("Spark Web Hooks"); if ($spark->listWebhooks() == true) { $spark->debug_r($spark->getResult()); } else { $spark->debug("Error: " . $spark->getError()); $spark->debug("Error Source" . $spark->getErrorSource()); }