Difference between revisions of "Websocket Interface"
(Created page with "=Overview= Hubitat allows for opening and maintaining a connection to a websocket endpoint from the hub. All code needs to be contained in a driver, there is no option to ope...") |
|||
Line 15: | Line 15: | ||
:: url - The url to connect to. | :: url - The url to connect to. | ||
:: options - Optional parameters to configure the web socket connection. Possible values: | :: options - Optional parameters to configure the web socket connection. Possible values: | ||
− | :::''byteInterface'' | + | :::''byteInterface'' - defaults to 'false'. If set to true, messages are handled as byte arrays and will be hex string encoded. |
− | :::''pingInterval'' | + | :::''pingInterval'' - The number of seconds to send a ping message. Defaults to 30. |
− | :::''headers'' | + | :::''headers'' - A Map of key/value pairs to send as header values when connecting to the web socket server. |
===<code>webSocketClose</code>=== | ===<code>webSocketClose</code>=== |
Revision as of 16:55, 17 June 2019
Contents
Overview
Hubitat allows for opening and maintaining a connection to a websocket endpoint from the hub. All code needs to be contained in a driver, there is no option to open a websocket connection from an app. Hubitat provides methods to connect and disconnect to the endpoint, in addition it is required to create a method in the driver that accepts incoming messages (parse) and another method that will be called with any status updates for the endpoint (webSocketStatus).
Methods
Hubitat Provided Methods
webSocketConnect
- Signature
void hubitat.helper.InterfaceUtils.webSocketConnect(Map options = [:], DeviceWrapper device, String url)
- Parameters
- device - The current device that is calling the method.
- url - The url to connect to.
- options - Optional parameters to configure the web socket connection. Possible values:
- byteInterface - defaults to 'false'. If set to true, messages are handled as byte arrays and will be hex string encoded.
- pingInterval - The number of seconds to send a ping message. Defaults to 30.
- headers - A Map of key/value pairs to send as header values when connecting to the web socket server.
webSocketClose
- Signature
void webSocketClose(DeviceWrapper device)
- Parameters
- device - The current device that is calling the method.
sendWebSocketMessage
- Signature
void sendWebSocketMessage(DeviceWrapper device, String message)
- Parameters
- device - The current device that is calling the method.
- message - The message to send. If this connection is a byte interface, then this must be a hex encoded String.
User defined methods
parse(String message)
- This method is called with any incoming messages from the web socket server. This is a standard method for drivers.
webSocketStatus(String message)
- This method is called with any status messages from the web socket client connection (disconnections, errors during connect, etc)