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:41] – andreh | ezeio2:apiref:subscribe [2021-01-27 19:02] – andreh | ||
---|---|---|---|
Line 15: | Line 15: | ||
The '' | The '' | ||
- | |||
=== Example usage === | === Example usage === | ||
Line 28: | Line 27: | ||
This call will return a JSON object (see example below) with metadata listing the systems that will be accessible through the websocket. | This call will return a JSON object (see example below) with metadata listing the systems that will be accessible through the websocket. | ||
- | // | + | // |
<code javascript> | <code javascript> | ||
Line 96: | Line 95: | ||
The '' | The '' | ||
+ | |||
+ | The '' | ||
**Step 2 : Open websocket and start receiving data** | **Step 2 : Open websocket and start receiving data** | ||
Line 108: | Line 109: | ||
Note that the ezeio normally buffers data before the data is uploaded to the cloud servers, so the data may be delayed with up to 20 minutes | Note that the ezeio normally buffers data before the data is uploaded to the cloud servers, so the data may be delayed with up to 20 minutes | ||
- | **Step 3 : Request immediate | + | The STATUS |
- | Call '' | + | |
- | === Return value === | + | **Step 3 : Request subscription changes** |
- | JSON formatted | + | With an open websocket and while receiving |
+ | To request unbuffered log updates, the call is: | ||
+ | < | ||
+ | The log updates will revert to normal (buffered) mode after 30 minutes. | ||
+ | To request 10s status updates, the call is: | ||
+ | < | ||
+ | The status updates will revert to normal (10 minute) updates after 5 minutes. | ||
+ | To cancel updates, the call is: | ||
+ | < | ||
+ | |||
+ | Multiple requests can be sent 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-> | ||
+ | </ |