PHP code example of techdock / opcua-webapi-client
1. Go to this page and download the library: Download techdock/opcua-webapi-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
techdock / opcua-webapi-client example snippets
TechDock\OpcUaWebApiClient\Api\DefaultApi;
use TechDock\OpcUaWebApiClient\Configuration;
use TechDock\OpcUaWebApiClient\Model\ReadRequest;
use TechDock\OpcUaWebApiClient\Model\ReadValueId;
use TechDock\OpcUaWebApiClient\Model\RequestHeader;
use GuzzleHttp\Client;
// Configure the API endpoint
$config = Configuration::getDefaultConfiguration();
$config->setHost('https://webapi.opcfoundation.org/opcua');
// Create HTTP client
$httpClient = new Client([
'timeout' => 30.0,
'connect_timeout' => 10.0,
]);
// Initialize API
$api = new DefaultApi($httpClient, $config);
// Create a read request
$readRequest = new ReadRequest([
'max_age' => 0,
'nodes_to_read' => [
new ReadValueId([
'node_id' => 'i=2258', // Server.ServerStatus.CurrentTime
'attribute_id' => 13 // Value attribute
])
],
'request_header' => new RequestHeader([
'request_handle' => 1,
'timestamp' => new \DateTime(),
'timeout_hint' => 60000
])
]);
// Execute the read operation
$response = $api->read($readRequest);
// Access the result
$result = $response->getResults()[0];
echo "Server time: " . $result->getValue() . "\n";
use TechDock\OpcUaWebApiClient\Model\ReadRequest;
use TechDock\OpcUaWebApiClient\Model\ReadValueId;
use TechDock\OpcUaWebApiClient\Model\RequestHeader;
$readRequest = new ReadRequest([
'max_age' => 0,
'nodes_to_read' => [
new ReadValueId([
'node_id' => 'i=2258', // Server.ServerStatus.CurrentTime
'attribute_id' => 13 // Value attribute
])
],
'request_header' => new RequestHeader([
'request_handle' => 1,
'timestamp' => new \DateTime(),
'timeout_hint' => 60000
])
]);
$response = $api->read($readRequest);
$value = $response->getResults()[0]->getValue();