WebSocket Client - Version 2.2.0#

Module Summary#

Communicates with a HTTP/TCP server over a WebSocket.

Module Status#

This IO Module is stable and has been tested internally.

Release Notes#

Version 2.2#

  •  Fully rewritten WebSocket client library for increased performance and compatibility.

  •  Added ability to disable keep-alive pings.

Version 2.1.1#

  •  Allow the use of HTTP Bearer Authentication Tokens.

Version 2.1#

  •  Prevent message from being concatenated during high traffic situations.

Version 2.0#

  •  Initial release.

Minor point releases (eg. 1.1.x) will be for small fixes and may not be listed here.

Operation#

Instance Properties#

Configure Hostname, Path, Protocol and Port to that of the WebSocket server. The protocol prefex ie. wss:// should not be entered here.

For testing the module, a free online WebSocket tool can be found on the Pie Socket website. To use this, enter demo.piesocket.com in to the Hostname field and once connected, enter the API path in to the Path property. Set the Protocol to WSS and leave the Port as Default (0).

If Send keep alive? is enabled, a ping will be sent a regular intervals to keep the connection open. Certain WebSocket servers don’t support pings and the connection may be aborted, in these instances Send keep alive? should be disabled.

If Auto-Reconnect is enabled, when the WebSocket and/or the TCP connection is closed, a re-connect attempt will be made. If enabled and there is a fatal connection error, this may cause the controller to continuously attempt re-connection.

Checking the Extended Logging checkbox will provide more detailed log messages. This is intended for diagnostics and problem solving and should ideally be disabled during normal operation.

Checking the Log Comms checkbox will provide more very detailed log messages for TCP frames. This is intended for diagnostics and problem solving and should ideally be disabled during normal operation.

Status Variables#

The IO Modules tab of the web interface provides status variables to shows information about the module and monitor its state.

Connection Status    Status of TCP and WebSocket session with a timestamp of the last change.
Last Sent    Last Message sent using the Send Message Action with a timestamp.
Last Received    Last message received with a timestamp.

Triggers#

Connected#

Fires when a TCP connection is established with the WebSocket server.

WebSocket Established#

Fires once a WebSocket session has been established, after TCP has connected. After this point, messages can be exchanged.

Disconnected#

Fires when a WebSocket and/or the TCP connection has been closed for any reason. Either the Auto-Reconnect instance option or a Connect Action can be used to re-establish a connection. It is not advised to associate a Connect Action with a Disconnected and use Auto-Reconnect.

Messages Received#

Fires when a WebSocket message is received from the server and the received message contains the Match String, or Match String is left blank. Note that Match String does not support wildcards.

Trigger variables:

  •  Variable 1: Message received (string).

Actions#

Connect#

Establishes a TCP connection and then established a WebSocket session.
If a HTTP Bearer Authentication (RFC 6750) token is required this can be added here.

Disconnect#

Closes both the TCP socket and the WebSocket session.

Send Message#

Sends the Message over the WebSocket if it is established. If the WebSocket is not established, an error will be printed in the log.

Support#

If you encounter any issues with this module, please contact our support team.