ajout du fichier modifierAVenV1.php
Signed-off-by: Charles DAVID <charles@cadjou.net>
This commit is contained in:
55
exemples/modifierAVenV1.php
Normal file
55
exemples/modifierAVenV1.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
// Need php with curl extension
|
||||||
|
|
||||||
|
set_time_limit(999);
|
||||||
|
|
||||||
|
// Params for request
|
||||||
|
$username = 'admin';
|
||||||
|
$password = 'Mot De Passe';
|
||||||
|
|
||||||
|
// IP List split by coma ","
|
||||||
|
$ips = '192.168.4.10,192.168.4.11';
|
||||||
|
|
||||||
|
$split = ","; // Split by coma
|
||||||
|
//$split = "\n"; // Split by line
|
||||||
|
|
||||||
|
// Request to change a value
|
||||||
|
$request = 'protocols/bacnet/local/objects/write-property-multiple';
|
||||||
|
|
||||||
|
// Change AnalogValue-2 to 25 as priority 16
|
||||||
|
$jsonData = '{
|
||||||
|
"encode": "text",
|
||||||
|
"propertyReferences": [
|
||||||
|
{
|
||||||
|
"type": "analogValue",
|
||||||
|
"instance": 2,
|
||||||
|
"property": "presentValue",
|
||||||
|
"value": "25",
|
||||||
|
"priority":16
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}';
|
||||||
|
|
||||||
|
// For each IP in the list
|
||||||
|
foreach(explode($split,$ips) as $ip) {
|
||||||
|
if (trim($ip) == '') continue; // If IP is null don't send request
|
||||||
|
|
||||||
|
// Prepare Request
|
||||||
|
$ch = curl_init( 'https://' . trim($ip) . '/api/rest/v1/' . $request );
|
||||||
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, $jsonData );
|
||||||
|
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
||||||
|
curl_setopt( $ch, CURLOPT_USERPWD, $username . ":" . $password);
|
||||||
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
|
||||||
|
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 1 );
|
||||||
|
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
|
||||||
|
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
|
||||||
|
|
||||||
|
// Send request.
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
// Show result
|
||||||
|
echo $ip . "\n";
|
||||||
|
print_r($result);
|
||||||
|
echo "\n";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user