# cp.websocket.serial

A partial implementation of the websocket API communicating via serial port rather than HTTP.

It implements the same basic methods as hs.websocket, so can be dropped in as a replacement without change, other than the initial construction.

Note that it does not support any websocket extensions.


# API Overview

Functions - API calls offered directly by the extension

  • new

Methods - API calls which can only be made on an object returned by a constructor

  • close
  • isOpen
  • open
  • send
  • status

# API Documentation

# Functions

# new

Signature cp.websocket.serial.new(deviceName, baudRate, dataBits, stopBits, callback) -> object
Type Function
Description Creates a new websocket connection via a serial connection.
Parameters
  • deviceName - The name of the USB Device
  • baudRate - The connection baud rate
  • dataBits - The data bits.
  • stopBits - The stop bits.
  • callback - A function that's triggered by websocket actions.
Returns
  • The cp.websocket object
Notes
  • The callback should accept two parameters.
  • The first parameter is a cp.websocket.event value.
  • The second parameter is a string with the received message or an error message.
Examples None
Source src/extensions/cp/websocket/serial.lua line 178

# Methods

# close

Signature cp.websocket.serial:close() -> object
Type Method
Description Closes a websocket connection.
Parameters
  • None
Returns
  • The cp.websocket.serial object
Notes
  • The status may be either closing or closed after calling this method.
  • To be notified the close has completed, listen for the cp.websocket.event.closed event in the callback.
Examples None
Source src/extensions/cp/websocket/serial.lua line 382

# isOpen

Signature cp.websocket.serial:isOpen() -> boolean
Type Method
Description Gets whether or not the serial websocket is fully open.
Parameters
  • None
Returns
  • true if open, otherwise false.
Notes None
Examples None
Source src/extensions/cp/websocket/serial.lua line 337

# open

Signature cp.websocket.serial:open() -> cp.websocket.status
Type Method
Description Attempts to open a websocket connection with the configured serial connection.
Parameters
  • None
Returns
  • The cp.websocket.status after attempting to open.
Notes None
Examples None
Source src/extensions/cp/websocket/serial.lua line 300

# send

Signature cp.websocket.serial:send(message[, isData]) -> object
Type Method
Description Sends a message to the websocket client.
Parameters
  • message - A string containing the message to send.
  • isData - An optional boolean that sends the message as binary data (defaults to true).
Returns
  • The cp.websocket.serial object
Notes
  • Forcing a text representation by setting isData to false may alter the data if it
  • contains invalid UTF8 character sequences (the default string behavior is to make
  • sure everything is "printable" by converting invalid sequences into the Unicode
  • Invalid Character sequence).
Examples None
Source src/extensions/cp/websocket/serial.lua line 414

# status

Signature cp.websocket.serial:status() -> cp.websocket.status
Type Method
Description Returns the current connection status.
Parameters
  • None
Returns
  • The current cp.websocket.status.
Notes None
Examples None
Source src/extensions/cp/websocket/serial.lua line 214