2018-03-18 14:28:40 +01:00
|
|
|
<?php
|
2018-03-24 10:46:42 +01:00
|
|
|
/**
|
|
|
|
* PHP API usage example
|
|
|
|
*
|
|
|
|
* contributed by: @4oo4
|
2021-01-21 10:59:27 +01:00
|
|
|
* description: example script to upgrade device firmware (can be scheduled with systemd/cron)
|
|
|
|
* to the most current version
|
2018-03-24 10:46:42 +01:00
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
require_once 'vendor/autoload.php';
|
|
|
|
require_once 'config.php';
|
2018-03-18 14:28:40 +01:00
|
|
|
|
2018-03-24 10:46:42 +01:00
|
|
|
/**
|
|
|
|
* site id of the AP to update
|
2019-04-29 17:35:09 +02:00
|
|
|
* https://github.com/Art-of-WiFi/UniFi-API-client#important-notes
|
2018-03-24 10:46:42 +01:00
|
|
|
*/
|
|
|
|
$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)
|
|
|
|
*/
|
2023-12-18 11:11:27 +01:00
|
|
|
$unifi_connection = new UniFi_API\Client(
|
|
|
|
$controlleruser,
|
|
|
|
$controllerpassword,
|
|
|
|
$controllerurl,
|
|
|
|
$site_id,
|
|
|
|
$controllerversion
|
|
|
|
);
|
|
|
|
|
|
|
|
$login = $unifi_connection->login();
|
2018-03-18 14:28:40 +01:00
|
|
|
|
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);
|