UniPi Evok
Node JS wrapper for UniPi EVOK REST and WebSocket API as documented at EVOK Documentation.
Note this only supports EVOK API v2.0
Installation
npm i unipi-evok
Usage
A number of examples can be found within the examples directory.
At it's most basic level we can connect to the UniPi using:
const evok = const unipi = host: 'IP_ADDRESS' restPort: 80 wsPort: 8080 unipi
Properties
host
- DNS hostname or IP addressrestPort
- Port of EVOK REST API - Default is 80wsPort
- Port of EVOK WebSocket API - Default is 8080
Client Methods
Note internal methods are not documented.
connect()
Fetch a list of all devices to be stored under unipi.devices()
then connect to the WebSocket server on the UniPi.
Example
unipi
close()
Example
unipi
restUrl()
Return a string of the base REST URL.
Example
unipi // http://localhost:80
wsUrl()
Return a string of the base WebSocket URL.
Example
unipi // http://localhost:8080
get(url)
Return a promise after performing a GET request.
Arguments
url
- Relative URL on the EVOK API
Example
unipi
post()
TODO
send(message)
Send JSON object via the WebSocket
Arguments
message
- JSON object
Example
unipi
API Methods
This is the default class which extends client.js.
connect()
Extends the client.js connect method by first fetching a list of devices via the REST API.
devices()
Example
unipi // array of objects returned from the API
device(dev, circuit)
Find a device from the list of devices
Arguments
dev
- Device as defined on EVOK API, egao
circuit
- Circuit as defined on EVOK API
Example
let device = unipi
inputs()
Digital inputs filtered from the device list.
Example
unipi
input(circuit)
TODO
relays()
Relays filtered from the device list.
Example
unipi // array of objects
relay(circuit, state)
Either get the current state of the relay or set a new state. Note this will not return the state when setting.
Arguments
circuit
- Circuit as defined on the APIstate
- Optional state of true/false
Examples
Get the state
unipi // true/false
Set the state
unipi
digitalOutputs()
Digital outputs filtered from the device list.
Example
unipi // array of objects
digitalOutput(circuit, state)
Either get the current state of a digital output or set a new state. Note this will not return the state when setting.
Arguments
circuit
- Circuit as defined on the APIstate
- Optional state of true/false
Examples
Get the state
unipi // true/false
Set the state
unipi
leds()
LEDs filtered from the device list.
Example
unipi // array of objects
led(circuit, state)
Either get the current state of a LED or set a new state. Note this will not return the state when setting.
Arguments
circuit
- Circuit as defined on the APIstate
- Optional state of true/false
Examples
Get the state
unipi // true/false
Set the state
unipi
analogueInputs()
Analogue inputs filtered from the device list.
Example
unipi // array of objects
analogueInput()
TODO
analogueOutputs()
Analogue outputs filtered from the device list.
Example
unipi // array of objects
analogueOutput(circuit, state)
Either get the current state of an analogue output or set a new state. Note this will not return the state when setting.
Arguments
circuit
- Circuit as defined on the APIstate
- Optional value between 0-10 (no validation on this)
Examples
Get the state
unipi // true/false
Set the output to 5v
unipi
owDevices
TODO
set(dev, circuit, state)
Shorthand method for setting values on the WebSocket API.
Arguments
dev
- Dev as defined on the APIcircuit
- Circuit as defined on the APIvalue
- Boolean or float
Example
Set a relay on
unipi
Events
Module events
Created by this module.
connect
Emitted on connect of the WebSocket.
connectFailed
Emitted when we failed to connect to the WebSocket
message
When any message is received via the WebSocket.
Example
unipi
error
Emitted when theres an error.
close
Emitted when the WebSocket connection is closed.
EVOK Events
By default we emit events based on the type of device which has made a change.
Arguments
device
- Latest data emitted from EVOK APIdevice
- Last stored data fromdevices()
prior to event, note this may be null in some cases
Note these do not necessarily mean the value changed, nor should they be considered 100% reliable as race conditions may occur.
Example
unipi
input
When a digital input message is received.
relay
When a relay message is received.
digitalOutput
When a digital output message is received.
ai
When analogue input message is received.
ao
When analogue output message is received.
led
When LED message is received.
wd
When a watchdog message is received
neuron
uart
wifi
Notes
This is currently a work in progress.