2018-02-01 16:56:17 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHP API usage example
|
|
|
|
*
|
|
|
|
* contributed by: Art of WiFi
|
2021-01-21 10:59:27 +01:00
|
|
|
* description: example basic PHP script to update WLAN settings of a device when using a controller version 5.5.X or higher
|
|
|
|
* where set_ap_radiosettings() throws an error
|
2018-02-01 16:56:17 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* using the composer autoloader
|
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
require_once 'vendor/autoload.php';
|
2018-02-01 16:56:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* include the config file (place your credentials etc. there if not already present)
|
|
|
|
* see the config.template.php file for an example
|
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
require_once 'config.php';
|
2018-02-01 16:56:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the site to use to log in to the controller
|
|
|
|
*/
|
|
|
|
$site_id = '<short site name of a site the credentials used have access to>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the MAC address of the access point to modify
|
|
|
|
*/
|
|
|
|
$ap_mac = '<enter MAC address>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* power level for 2.4GHz
|
|
|
|
*/
|
|
|
|
$ng_tx_power_mode = 'low';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* channel for 2.4GHz
|
|
|
|
*/
|
|
|
|
$ng_channel = 6;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* power level for 5GHz
|
|
|
|
*/
|
|
|
|
$na_tx_power_mode = 'medium';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* channel for 5GHz
|
|
|
|
*/
|
|
|
|
$na_channel = 44;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* initialize the UniFi API connection class and log in to the controller and do our thing
|
|
|
|
*/
|
2023-12-18 11:11:27 +01:00
|
|
|
$unifi_connection = new UniFi_API\Client(
|
|
|
|
$controlleruser,
|
|
|
|
$controllerpassword,
|
|
|
|
$controllerurl,
|
|
|
|
$site_id,
|
|
|
|
$controllerversion
|
|
|
|
);
|
|
|
|
|
|
|
|
$set_debug_mode = $unifi_connection->set_debug(false);
|
|
|
|
$loginresults = $unifi_connection->login();
|
|
|
|
$data = $unifi_connection->list_devices($ap_mac);
|
|
|
|
$radio_table = $data[0]->radio_table;
|
|
|
|
$device_id = $data[0]->device_id;
|
2018-02-01 16:56:17 +01:00
|
|
|
|
2018-10-02 13:16:48 +02:00
|
|
|
foreach ($radio_table as $radio) {
|
|
|
|
if ($radio->radio === 'ng') {
|
2018-02-01 16:56:17 +01:00
|
|
|
$radio->tx_power_mode = $ng_tx_power_mode;
|
2023-12-18 11:11:27 +01:00
|
|
|
$radio->channel = $ng_channel;
|
2018-02-01 16:56:17 +01:00
|
|
|
}
|
|
|
|
|
2018-10-02 13:16:48 +02:00
|
|
|
if ($radio->radio === 'na') {
|
2018-02-01 16:56:17 +01:00
|
|
|
$radio->tx_power_mode = $na_tx_power_mode;
|
2023-12-18 11:11:27 +01:00
|
|
|
$radio->channel = $na_channel;
|
2018-02-01 16:56:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$update_device = $unifi_connection->set_device_settings_base($device_id, ['radio_table' => $radio_table]);
|
|
|
|
|
2018-10-02 13:16:48 +02:00
|
|
|
if (!$update_device) {
|
2018-02-01 16:56:17 +01:00
|
|
|
$error = $unifi_connection->get_last_results_raw();
|
|
|
|
echo json_encode($error, JSON_PRETTY_PRINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* provide feedback in json format
|
|
|
|
*/
|
|
|
|
echo json_encode($update_device, JSON_PRETTY_PRINT);
|