unifi-php-api/examples/ap_upgrade_firmware.php
malle-pietje 09db47affd API client class v1.1.41
changed create_wlan function/method to not include passphrase in payload when security = "open" and passphrase = null
fixed indentations in several places
added custom_api_request() function/method which allows a programmer to issue custom API requests that may not yet be supported by this client (to be used with care!)
added example to demonstrate use of custom_api_request()
removed repetitive code and optimized exec_curl() when creating the final payload, resulting in 10-20% performance increase and slightly lower memory consumption by PHP
2019-04-29 17:35:09 +02:00

38 lines
1.1 KiB
PHP
Executable File

<?php
/**
* 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
*/
require_once('vendor/autoload.php');
require_once('config.php');
/**
* site id of the AP to update
* https://github.com/Art-of-WiFi/UniFi-API-client#important-notes
*/
$site_id = '<enter your site id here>';
/**
* device MAC address formatted with colons, e.g. 'de:ad:be:ef:01:23'
*/
$device_mac = '<enter MAC address of device to update>';
/**
* 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)
*/
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, false);
$login = $unifi_connection->login();
/**
* Run the actual upgrade
*/
$results = $unifi_connection->upgrade_device($device_mac);
/**
* provide feedback in json format from $response given by upgrade_device();
*/
echo json_encode($results, JSON_PRETTY_PRINT);