NOTE: This interface is in alpha status and some users have reported issues with their hubs when using this. Use at your own risk, and please report any issues in the Community.
Hubitat allows for opening and maintaining a connection to a TCP socket endpoint from the hub. All code needs to be contained in a driver (there is no option to open a socket 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 (socketStatus).
void connect(String ip, int port)void connect(String ip, int port, [options (name/value pairs)])ip - The ip address to connect to.port - The port to connect to.options - Optional parameters to configure the socket connection. Possible values:
timeout - The socket timeout, in milliseconds.secureSocket (since 2.3.0) - possible values: true, false. Use TLS.ignoreSSLIssues (since 2.3.0) - possible values: true, false. Ignores certificate issues for TLS connections.caCertificate (since 2.3.1) - The CA certificate, in PEM format, used to validate the server.certificate (since 2.3.1) - The client certificate, in PEM format, for TLS authentication.privateKey (since 2.3.1) - The private key, in PEM format, paired with the client certificate.tlsVersion (since 2.3.1) - The TLS protocol version to request.termChars (since 2.3.1) - A List of terminating characters.convertReceivedDataToString (since 2.3.0) - possible values: true, false. Controls whether received bytes are converted to a String.bufferSize (since 2.3.0) - The buffer size in bytes, from 1024 through 1048576. Other values use 1024.receiveBufferSize (since 2.5.1) - The receive buffer size in bytes, from 1 through 1048576.keepAlive (since 2.5.1) - possible values: true, false. Enables TCP keepalive.tcpKeepIdle (since 2.5.1) - The keepalive idle time, in seconds (a positive number).tcpKeepInterval (since 2.5.1) - The keepalive probe interval, in seconds (a positive number).tcpKeepCount (since 2.5.1) - The number of keepalive probes (a positive number).inputReader, outputWriter - Optional Closures for custom handling of input or output.// Connect with basic settings
interfaces.rawSocket.connect("192.168.1.15", 8064)
void close()
// Close connection
interfaces.rawSocket.close()
void sendMessage(String message)
message - The message to send. If this connection is a byte interface, then this must be a hex encoded String.
// Send string message
interfaces.rawSocket.sendMessage("My message")
Removes this device's socket interface.
void disconnect()
boolean isConnected()
boolean - true if this device has an active socket connection, false otherwise.
Methods with the following signatures must be provided in your code and will be called as described.
parse(String message) - This method is called with any incoming messages from the socket server. This is a standard method for drivers.socketStatus(String message) - This method is called with any status messages from the socket client connection (disconnections, errors during connect, etc)