|
@@ -0,0 +1,37 @@
|
|
|
+<?php
|
|
|
+namespace App\Services\Project;
|
|
|
+use Illuminate\Support\Facades\Http;
|
|
|
+
|
|
|
+class ProjectBACnetService {
|
|
|
+ protected string $baseProxyUrl;
|
|
|
+ protected string $siteId = '10100';
|
|
|
+ protected array $queryParams = [
|
|
|
+ 'skip' => 0,
|
|
|
+ 'max-results' => 15,
|
|
|
+ 'alt' => 'json'
|
|
|
+ ];
|
|
|
+ protected string $username;
|
|
|
+ protected string $password;
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->baseProxyUrl = config('bacnet.base_proxy_url');
|
|
|
+ $this->siteId = config('bacnet.site_id');
|
|
|
+ $this->username = config('bacnet.auth.username');
|
|
|
+ $this->password = config('bacnet.auth.password');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fetchDeviceObjects($params = [])
|
|
|
+ {
|
|
|
+ $url = "{$this->baseProxyUrl}/{$this->siteId}/{$params['deviceId']}";
|
|
|
+ $response = Http::withBasicAuth($this->username, $this->password)
|
|
|
+ ->timeout(30)
|
|
|
+ ->get($url, $this->queryParams);
|
|
|
+
|
|
|
+ if ($response->successful()) {
|
|
|
+ return $response->json();
|
|
|
+ } else {
|
|
|
+ throw new \Exception('API request failed: ' . $response->body());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|