Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
ezeio2:apiref:subscribe [2021-01-26 22:51] – andreh | ezeio2:apiref:subscribe [2021-01-27 22:22] – andreh | ||
---|---|---|---|
Line 1: | Line 1: | ||
==== subscribe ==== | ==== subscribe ==== | ||
- | Request a websocket data stream, and commands to manage the data stream | + | Request a websocket data stream, and commands to manage the data stream. |
=== Description === | === Description === | ||
Line 95: | Line 95: | ||
The '' | The '' | ||
+ | |||
+ | The '' | ||
**Step 2 : Open websocket and start receiving data** | **Step 2 : Open websocket and start receiving data** | ||
Line 113: | Line 115: | ||
With an open websocket and while receiving data from the ezeio system, you can call the subscribe API to request immediate updates or to cancel updates from a certain ezeio. | With an open websocket and while receiving data from the ezeio system, you can call the subscribe API to request immediate updates or to cancel updates from a certain ezeio. | ||
- | To request | + | To request |
- | < | + | < |
+ | The log updates will revert to normal (buffered) mode after 30 minutes. | ||
To cancel updates, the call is: | To cancel updates, the call is: | ||
Line 120: | Line 123: | ||
Multiple requests can be sent in the same command: | Multiple requests can be sent in the same command: | ||
- | < | + | < |
+ | Up to 50 devices can be included in the same command | ||
+ | === Example code (PHP) === | ||
+ | <code php> | ||
+ | <?php | ||
+ | define(" | ||
+ | | ||
+ | // API keyID and key needs to be set up in eze.io under Groups-> | ||
+ | define(" | ||
+ | define(" | ||
+ | // Using the textalk/ | ||
+ | // https:// | ||
+ | require(' | ||
+ | use WebSocket\Client; | ||
+ | // Request a websocket key and metadata using cURL | ||
+ | $ch = curl_init(); | ||
+ | curl_setopt($ch, | ||
+ | | ||
+ | // All API calls use Digest AUTH | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | | ||
+ | // Set a 5s timeout, and return any received data | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | | ||
+ | // Execute the cURL request | ||
+ | $response = curl_exec($ch); | ||
+ | curl_close($ch); | ||
+ | |||
+ | // Decode the json reply into an associative array | ||
+ | $json = json_decode( $response, TRUE ); | ||
+ | | ||
+ | // Status should be ' | ||
+ | if($json[" | ||
+ | die(" | ||
+ | |||
+ | // Open the websocket | ||
+ | $wsclient = new WebSocket\Client( $json[" | ||
+ | | ||
+ | // Loop forever (until websocket disconnects) | ||
+ | while ( true ) { | ||
+ | try { | ||
+ | $message = $wsclient-> | ||
+ | |||
+ | // Process the data - here we just print it for testing | ||
+ | print_r( json_decode( $message, TRUE ) ); | ||
+ | } | ||
+ | catch (\WebSocket\ConnectionException $e) { | ||
+ | // If the websocket was disconnected, | ||
+ | if( !$wsclient-> | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | $wsclient-> | ||
+ | </ |