Skip to content

Commit c81a3fa

Browse files
committed
[DOC] Events
1 parent 0457b82 commit c81a3fa

3 files changed

Lines changed: 364 additions & 22 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,37 @@ Event::listen(DataChangeReceived::class, function (DataChangeReceived $e) {
198198
php artisan opcua:session # connects, subscribes, publishes — all automatic
199199
```
200200

201+
### React to events
202+
203+
47 PSR-14 events are dispatched automatically — connections, reads, writes, alarms, subscriptions, cache, retries. Just register listeners:
204+
205+
```php
206+
use Illuminate\Support\Facades\Event;
207+
use PhpOpcua\Client\Event\ClientConnected;
208+
use PhpOpcua\Client\Event\NodeValueWriteFailed;
209+
use PhpOpcua\Client\Event\AlarmActivated;
210+
211+
// Log connections
212+
Event::listen(ClientConnected::class, function ($e) {
213+
logger()->info("Connected to {$e->endpointUrl}");
214+
});
215+
216+
// Track write failures
217+
Event::listen(NodeValueWriteFailed::class, function ($e) {
218+
logger()->warning("Write failed on {$e->nodeId}: 0x" . dechex($e->statusCode));
219+
});
220+
221+
// Alert operators on alarms
222+
Event::listen(AlarmActivated::class, function ($e) {
223+
Notification::send(
224+
User::role('operator')->get(),
225+
new AlarmTriggered($e->sourceName, $e->severity, $e->message),
226+
);
227+
});
228+
```
229+
230+
See [Events documentation](doc/11-events.md) for the full reference of all 47 events.
231+
201232
### Switch connections
202233

203234
```php
@@ -276,6 +307,7 @@ echo $mock->callCount('read'); // 1
276307
| 08 | [Testing](doc/08-testing.md) | MockClient, DataValue factories, unit and integration tests |
277308
| 09 | [Examples](doc/09-examples.md) | Complete code examples for all features |
278309
| 10 | [Auto-Publish & Monitoring](doc/10-auto-publish.md) | Auto-publish, auto-connect, event listeners, real-world use case |
310+
| 11 | [Events](doc/11-events.md) | All 47 PSR-14 events, Laravel listeners, queued handlers, practical examples |
279311

280312
## Testing
281313

doc/10-auto-publish.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ Auto-publish eliminates the need for manual `publish()` loops when using OPC UA
88

99
```
1010
┌──────────────────────────────────────────────────────────────────────────┐
11-
│ Laravel Application │
11+
│ Laravel Application
1212
│ │
13-
│ EventServiceProvider │
14-
│ Event::listen(DataChangeReceived::class, ...) │
15-
│ Event::listen(AlarmActivated::class, ...) │
13+
│ EventServiceProvider
14+
│ Event::listen(DataChangeReceived::class, ...)
15+
│ Event::listen(AlarmActivated::class, ...)
1616
│ │
17-
│ config/opcua.php │
18-
│ auto_publish: true │
17+
│ config/opcua.php
18+
│ auto_publish: true
1919
│ connections: │
20-
│ plc-1: { auto_connect: true, subscriptions: [...] } │
21-
│ historian: { } ← on-demand only │
20+
│ plc-1: { auto_connect: true, subscriptions: [...] }
21+
│ historian: { } ← on-demand only
2222
│ │
2323
├──────────────────────────────────────────────────────────────────────────┤
24-
│ php artisan opcua:session │
24+
│ php artisan opcua:session
2525
│ │
26-
│ Daemon (ReactPHP event loop) │
27-
│ ├── Auto-connect: plc-1 → TCP → OPC UA Server │
28-
│ ├── Create subscriptions + monitored items │
29-
│ ├── AutoPublisher: │
30-
│ │ ├── Timer → publish() → events dispatched │
31-
│ │ ├── Acknowledgements tracked │
32-
│ │ └── Recovery on connection errors │
33-
│ └── IPC socket for runtime requests │
26+
│ Daemon (ReactPHP event loop)
27+
│ ├── Auto-connect: plc-1 → TCP → OPC UA Server
28+
│ ├── Create subscriptions + monitored items
29+
│ ├── AutoPublisher:
30+
│ │ ├── Timer → publish() → events dispatched
31+
│ │ ├── Acknowledgements tracked
32+
│ │ └── Recovery on connection errors
33+
│ └── IPC socket for runtime requests
3434
│ │
35-
│ Events dispatched: │
36-
│ DataChangeReceived → Laravel listener → DB / notification / etc. │
37-
│ AlarmActivated → Laravel listener → alert operators │
38-
│ SubscriptionKeepAlive → (optional logging) │
35+
│ Events dispatched:
36+
│ DataChangeReceived → Laravel listener → DB / notification / etc.
37+
│ AlarmActivated → Laravel listener → alert operators
38+
│ SubscriptionKeepAlive → (optional logging)
3939
└──────────────────────────────────────────────────────────────────────────┘
4040
```
4141

@@ -555,7 +555,7 @@ Starting OPC UA Session Manager...
555555
+---------------------+----------------------------------------------+
556556
| Setting | Value |
557557
+---------------------+----------------------------------------------+
558-
| Socket | storage/app/opcua-session-manager.sock |
558+
| Socket | storage/app/opcua-session-manager.sock |
559559
| Timeout | 600s |
560560
| Auth Token | configured |
561561
| Auto-publish | enabled |

0 commit comments

Comments
 (0)