A module for connecting to an Elk M1 security system over a TCP connection.
Install with NPM or Yarn
npm install elk-client
// or
yarn add elk-client
import { ElkClient } from 'elk-client';
// Parse a message
const client = new ElkClient({
connection: {
host: 'elkm1.example.net',
secure: true,
},
username: 'myelkm1username',
password: 'supersecret!',
});
client
.connect()
.then(() => client.getArmingStatus())
.then((armingStatus) => {
const area1 = armingStatus.getAreaStatus(1);
console.log('Area 1 status:', ArmingLevel[area1.armingLevel])
})
.then(() => client.disconnect())
.then(() => {
console.log('Done!');
})
.catch((err) => {
console.error(err);
});
Devices can be discovered using UDP broadcast messages. Only M1XEP and C1M1 devices can be discovered. This is not documented by Elk Products, but this is how the ElkRP2 software does it's discovery.
import { ElkDiscoveryClient } from 'elk-client';
const discoveryClient = new ElkDiscoveryClient();
discoveryClient
.start()
.then((devices) => {
console.log(`Found `${devices.length}` devices!);
})
.catch((err) => {
console.error(err);
});
You can optionally limit the device types requested and adjust the timeout, broadcast address, and port used:
import { ElkDiscoveryClient, ElkDeviceType } from 'elk-client';
const discoveryClient = new ElkDiscoveryClient({
// Only look for M1XEP devices
deviceTypes: [ElkDeviceType.M1XEP],
// Use port 9000 instead
// NOTE: This probably won't ever work if you change the port!
port: 9000,
// Wait 10 seconds instead of the 5 second default
timeout: 10000,
// Use a different broadcast address (default is 255.255.255.255)
broadcastAddress: "192.168.1.255",
});
discoveryClient
.start()
.then((devices) => {
console.log(`Found `${devices.length}` devices!);
})
.catch((err) => {
console.error(err);
});
Emitted when authentication has begun. This is typically triggered when the Elk M1 requests a username, after the "connected" event.
Emitted when a connection was successfully established. The client may still need to authenticate before it becomes "ready".
Emitted whenever the underlying connection disconnects. An error will be included if it caused the disconnect.
Emitted whenever an error occurs. The underlying connection will be disconnected after this, if it hasn't already.
Emitted whenever a message is recevied from the Elk M1.
Emitted when the client receives an "OK" response the panel. This is not a typical panel "message", but a special type of response the panel sends in very specific cases.
Emitted when the client is ready to send/receive events. It means we have successfully connected and authenticated (if a username and password was supplied). If no username was supplied, but the panel requires authentication, this event may still be emitted, followed by an "error" event indicating that authentication failed.
The default connect timeout value when not specified.
The default host name to use when one is not specified.
192.168.0.251 is the default IP address that the Elk M1 assigns to itself when it is not given one by a DHCP server or when it is expicitly reset.
The default port to connect to when using an insecure connection.
The default timeout for command responses when not specified.
The default port to connect to when using a secure connection.
The control panel sends this when logging in fails.
The control panel sends this when logging in is susccessful
The control panel sends this when prompting for a password.
The control panel sends this when prompting for a username.
Methods that send a command and wait for a response based solely on the response class type.
Methods that only send a command and don't wait for a reply.
Decodes an ElkDevice
configuration from a UDP discovery response.
The UDP response data.
Extracts an IP address from 4 bytes of a data buffer
The data buffer
The index within the buffer where the IP address is specified.
Extracts a MAC address from 6 bytes of a data buffer
The data buffer
The index within the buffer where the MAC address is specified.
Extracts a port number from 2 bytes of a data buffer
The data buffer
The index within the buffer where the port is specified.
Wraps a promise in a new promise that will reject if the promise is not resolved or rejected within the timeout provided.
The default connection options to use if secure
=== false
The default connection options to use if secure
=== true
A map of connection states to the name of the event that they emit when the connection is changed to that state.
Generated using TypeDoc
Emitted when authentication has completed succesfully. This should be followed by a "ready" event.
ElkClientEvents