2018-03-18 14:28:40 +01:00
|
|
|
<?php
|
2018-03-24 10:46:42 +01:00
|
|
|
/**
|
|
|
|
* PHP API usage example
|
|
|
|
*
|
|
|
|
* contributed by: @4oo4
|
|
|
|
* description: example script to check and upgrade device firmware (can be scheduled with systemd/cron)
|
|
|
|
* to the most current version
|
|
|
|
*/
|
2018-03-18 14:28:40 +01:00
|
|
|
require_once('vendor/autoload.php');
|
|
|
|
require_once('config.php');
|
|
|
|
|
2018-03-24 10:46:42 +01:00
|
|
|
/**
|
|
|
|
* site id of the AP to update
|
|
|
|
*/
|
|
|
|
$site_id = '<enter your site id here>';
|
2018-03-18 14:28:40 +01:00
|
|
|
|
|
|
|
/**
|
2018-03-24 10:46:42 +01:00
|
|
|
* device MAC address formatted with colons, e.g. 'de:ad:be:ef:01:23'
|
2018-03-18 14:28:40 +01:00
|
|
|
*/
|
2018-03-24 10:46:42 +01:00
|
|
|
$device_mac = '<enter MAC address of device to update>';
|
2018-03-18 14:28:40 +01:00
|
|
|
|
2018-03-24 10:46:42 +01:00
|
|
|
/**
|
|
|
|
* initialize the UniFi API connection class, log in to the controller
|
|
|
|
* (this example assumes you have already assigned the correct values in config.php to the variables used)
|
|
|
|
*/
|
2018-03-18 14:28:40 +01:00
|
|
|
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, false);
|
|
|
|
$login = $unifi_connection->login();
|
|
|
|
|
2018-03-24 10:46:42 +01:00
|
|
|
/**
|
|
|
|
* Run the actual upgrade
|
|
|
|
*/
|
2018-03-18 14:28:40 +01:00
|
|
|
$results = $unifi_connection->upgrade_device($device_mac);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* provide feedback in json format from $response given by upgrade_device();
|
|
|
|
*/
|
2018-03-24 10:46:42 +01:00
|
|
|
echo json_encode($results, JSON_PRETTY_PRINT);
|