mirror of
https://github.com/Art-of-WiFi/UniFi-API-client.git
synced 2024-11-22 02:00:21 +01:00
added example to change AC-IW port config
renamed update_wlan_settings_5.5.X.php to update_device_wlan_settings_5.5.X.php
This commit is contained in:
parent
14f4d58b02
commit
ad21ebaad8
@ -3,7 +3,9 @@
|
||||
* PHP API usage example
|
||||
*
|
||||
* contributed by: Art of WiFi
|
||||
* description: example basic PHP script to auth a guest device and attach a note to it
|
||||
* description: example basic PHP script to auth a guest device and attach a note to it,
|
||||
* this requires the device to be connected to the WLAN/LAN at moment of
|
||||
* authorization
|
||||
*/
|
||||
|
||||
/**
|
||||
|
78
examples/update_ac-iw_ports.php
Executable file
78
examples/update_ac-iw_ports.php
Executable file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP API usage example
|
||||
*
|
||||
* contributed by: Art of WiFi
|
||||
* description: example basic PHP script to update the port settings of an AC-IW device when using a controller
|
||||
* FYI: the AC-IW device has three ports, one for the wired uplink and two with external connectors
|
||||
* note: requires version 5.5.X or higher (to be verified)
|
||||
*/
|
||||
|
||||
/**
|
||||
* using the composer autoloader
|
||||
*/
|
||||
require_once('vendor/autoload.php');
|
||||
|
||||
/**
|
||||
* include the config file (place your credentials etc. there if not already present)
|
||||
* see the config.template.php file for an example
|
||||
*/
|
||||
require_once('config.php');
|
||||
|
||||
/**
|
||||
* 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 AC-IW device to modify
|
||||
*/
|
||||
$device_mac = '<enter MAC address>';
|
||||
|
||||
/**
|
||||
* port configuration to apply to port #1 of the AC-IW device
|
||||
* NOTE: available port configurations are available through list_portconf()
|
||||
*/
|
||||
$port_conf_id_port_1 = '<_id of port configuration to apply to port #1>';
|
||||
|
||||
/**
|
||||
* port configuration to apply to port #2 of the AC-IW device
|
||||
* NOTE: available port configurations are available through list_portconf()
|
||||
*/
|
||||
$port_conf_id_port_2 = '<_id of port configuration to apply to port #2>';
|
||||
|
||||
/**
|
||||
* prepare the payload to pass on to the API endpoint
|
||||
*/
|
||||
$new_ports_config = [
|
||||
'port_overrides' => [
|
||||
[
|
||||
'port_idx' => 1,
|
||||
'portconf_id' => $port_conf_id_port_1
|
||||
],
|
||||
[
|
||||
'port_idx' => 2,
|
||||
'portconf_id' => $port_conf_id_port_2
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* initialize the UniFi API connection class and log in to the controller and do our thing
|
||||
*/
|
||||
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, false);
|
||||
$set_debug_mode = $unifi_connection->set_debug(false);
|
||||
$loginresults = $unifi_connection->login();
|
||||
$data = $unifi_connection->list_devices($device_mac);
|
||||
$device_id = $data[0]->device_id;
|
||||
$update_device = $unifi_connection->set_device_settings_base($device_id, $new_ports_config);
|
||||
|
||||
if(!$update_device){
|
||||
$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);
|
@ -3,7 +3,7 @@
|
||||
* PHP API usage example
|
||||
*
|
||||
* contributed by: Art of WiFi
|
||||
* description: example basic PHP script to update WLAN settings when using a controller version 5.5.X or higher
|
||||
* 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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user