UNPKG

5.6 kBMarkdownView Raw
1# sACN receiver & sender in node.js
2
3[![Build Status](https://github.com/k-yle/sACN/workflows/Build%20and%20Test/badge.svg)](https://github.com/k-yle/sACN/actions)
4[![Coverage Status](https://coveralls.io/repos/github/k-yle/sACN/badge.svg?branch=master)](https://coveralls.io/github/k-yle/sACN?branch=master)
5[![npm version](https://badge.fury.io/js/sacn.svg)](https://badge.fury.io/js/sacn)
6[![npm](https://img.shields.io/npm/dt/sacn.svg)](https://www.npmjs.com/package/sacn)
7
8💡 This module can receive [DMX](https://en.wikipedia.org/wiki/DMX512) data sent via [sACN](https://en.wikipedia.org/wiki/E1.31) from professional lighting consoles (e.g. [ETC](https://www.etcconnect.com/), [Onyx](https://obsidiancontrol.com/)).
9
10🎭 It can also send data to DMX fixtures that support sACN, e.g. LED lights, smoke machines, etc.
11
12## Install
13
14```bash
15npm install sacn
16```
17
18## Usage - Receiver
19
20🔦 Sending [RDM](<https://en.wikipedia.org/wiki/RDM_(lighting)>) data to fixtures is not implemented yet, see [issue #1](https://github.com/k-yle/sACN/issues/1).
21
22```js
23const { Receiver } = require('sacn');
24
25const sACN = new Receiver({
26 universes: [1, 2],
27 // see table 1 below for all options
28});
29
30sACN.on('packet', (packet) => {
31 console.log('got dmx data:', packet.payload);
32 // see table 2 below for all packet properties
33});
34
35sACN.on('PacketCorruption', (err) => {
36 // trigged if a corrupted packet is received
37});
38
39sACN.on('PacketOutOfOrder', (err) => {
40 // trigged if a packet is recieved out of order
41});
42
43/* advanced usage below */
44
45sACN.on('error', (err) => {
46 // trigged if there is an internal error (e.g. the supplied `iface` does not exist)
47});
48
49// start listening to a new universe (universe 3 in this example)
50sACN.addUniverse(3);
51
52// stop listening to a universe 1
53sACN.removeUniverse(1);
54
55// close all connections; terminate the receiver
56sACN.close();
57
58sACN.universes; // is a list of the universes being listened to
59```
60
61### Table 1 - Options for Receiver
62
63| Name | Type | Purpose | Default |
64| ----------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
65| `universes` | `number[]` | Required. List of universes to listen to. Must be within 1-63999 | `[]` |
66| `port` | `number` | Optional. The multicast port to use. All professional consoles broadcast to the default port. | `5568` |
67| `iface` | `string` | Optional. If the computer is connected to multiple networks, specify which network adaptor to use by using this computer's local IP address | `null` |
68| `reuseAddr` | `boolean` | Optional. Allow multiple programs on your computer to listen to the same sACN universe. | `false` |
69
70### Table 2 - Packet properties
71
72```js
73{
74 "sourceName": "Onyx", // controller that sent the packet
75 "sourceAddress": "192.168.1.69", // ip address of the controller
76 "universe": 1, // DMX universe
77 "sequence": 172, // packets are numbered 0-255 to keep them in order
78 "priority": 100, // 0-200. used if multiple controllers send to the same universe
79 "payload": { // an object with the percentage values of DMX channels 1-512
80 1: 100,
81 2: 50,
82 3: 0
83 },
84
85 /* there are more low-level properties which most
86 users won't need, see the ./src/packet.ts file */
87}
88```
89
90## Usage - Sender (beta)
91
92```js
93const { Sender } = require('sacn');
94
95const sACNServer = new Sender({
96 universe: 1,
97 // see table 3 below for all options
98});
99
100async function main() {
101 await sACNServer.send({
102 payload: { // required. object with the percentages for each DMX channel
103 1: 100,
104 2: 50,
105 3: 0,
106 }
107 sourceName: "My NodeJS app" // optional. LED lights will use this as the name of the source lighting console.
108 priority: 100, // optional. value between 0-200, in case there are other consoles broadcasting to the same universe
109 });
110
111 sACNServer.close(); // terminate the server when your app is about to exit.
112}
113
114main(); // wrapped in a main() function so that we can `await` the promise
115
116```
117
118### Table 3 - Options for sender
119
120| Name | Type | Purpose | Default |
121| ----------- | --------- | --------------------------------------------------------------------------------------------- | ------- |
122| `universe` | `number` | Required. The universes to listen to. Must be within 1-63999 | `[]` |
123| `port` | `number` | Optional. The multicast port to use. All professional consoles broadcast to the default port. | `5568` |
124| `reuseAddr` | `boolean` | Optional. Allow multiple programs on your computer to listen to the same sACN universe. |
125
126# Contribute
127
128```bash
129npm run build # compile typescript
130npm test # run tests
131```
132
133# Network Requirements
134
135- [x] Multicast must be enabled. sACN uses port `5568` on `239.255.x.x`
136- [x] Network infrastructure that supports at least 100Mbps (100BaseT)
137
138# Protocol Docs
139
140The Architecture for Control Networks (ACN) and derived protocols are created by the Entertainment Services and Technology Association.
141
142- sACN is defined in [ANSI E1.31](./docs/E1.31-2018.pdf)
143- RDMNet is defined in [ANSI E1.33](./docs/E1.33-2019.pdf)