Skip to content

Instantly share code, notes, and snippets.

@natcl

natcl/README.md Secret

Created November 2, 2016 14:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natcl/f1b6bc1c2bed0a362a2a7bdfc82221e2 to your computer and use it in GitHub Desktop.
Save natcl/f1b6bc1c2bed0a362a2a7bdfc82221e2 to your computer and use it in GitHub Desktop.
Art-Net sending and receiving

Art-Net encoder/decoder

This sublow is a bi-directional Art-Net encoder/decoder.

Receiving

Connect a udp in object set to port 6454 to the input of the subflow.
The Art-Net data will be output as msg.payload in Buffer form.
The universe is available as msg.topic.

Sending

Send an Array or Buffer to the Art-Net subflow and connect the sublow's output to a udp out object set to port 6454. The universe must be set as msg.topic.

[{"id":"3ba422b0.9c410e","type":"subflow","name":"Artnet","info":"# Art-Net encoder/decoder\n\nThis sublow is a bi-directional Art-Net encoder/decoder.\n\n## Receiving\n\nConnect a `udp in` object set to port *6454* to the input of the subflow. \nThe Art-Net data will be output as `msg.payload` in Buffer form. \nThe universe is available as `msg.topic`.\n\n## Sending\n\nSend an `Array` or `Buffer` to the Art-Net subflow and connect the sublow's output to a `udp out` object set to port *6454*.\nThe universe must be set as `msg.topic`.","in":[{"x":180,"y":140,"wires":[{"id":"54870efc.1f38e8"}]}],"out":[{"x":440,"y":140,"wires":[{"id":"54870efc.1f38e8","port":0}]}]},{"id":"54870efc.1f38e8","type":"function","z":"3ba422b0.9c410e","name":"Artnet","func":"const HEADER_SIZE = 18;\nconst ID = \"Art-Net\\0\";\nconst ArtDmxOpCode = 0x5000;\nconst ProtVer = 14;\ncontext.sequence = context.sequence || 0;\nconst Physical = 0;\n\nvar header = new Buffer(HEADER_SIZE);\nheader.fill(0);\n\nheader.write(ID);\nheader.writeUInt16LE(ArtDmxOpCode, 8);\nheader.writeUInt16BE(ProtVer, 10);\nheader.writeUInt8(Physical, 13);\n\n// Parse incoming Art-Net packets\nif (msg.payload.slice(0, 8).toString() == ID) {\n var Opcode = msg.payload.readUInt16LE(8);\n if (Opcode == ArtDmxOpCode) {\n var Universe = msg.payload.readUInt16LE(14);\n var Length = msg.payload.readUInt16BE(16);\n msg.topic = Universe;\n msg.payload = msg.payload.slice(HEADER_SIZE, Length + HEADER_SIZE);\n node.send(msg);\n }\n// Format incoming buffer or array into Art-Net packet\n} else {\n context.sequence++;\n header.writeUInt8(context.sequence, 12);\n if (context.sequence >= 255)\n context.sequence = 0;\n \n var Universe = msg.topic;\n var Length = msg.payload.length;\n if (Array.isArray(msg.payload)) {\n msg.payload = new Buffer(msg.payload);\n }\n header.writeUInt16LE(Universe, 14);\n header.writeUInt16BE(Length, 16);\n \n msg.payload = Buffer.concat([header, msg.payload]);\n node.send(msg);\n}\n\n\n","outputs":1,"noerr":0,"x":310,"y":140,"wires":[[]]},{"id":"d53116db.4e6448","type":"udp in","z":"52b800eb.285ab8","name":"","iface":"","port":"6454","ipv":"udp4","multicast":"false","group":"","datatype":"buffer","x":140,"y":140,"wires":[["8ae18555.173a08"]]},{"id":"bf51a0e4.9141c8","type":"inject","z":"52b800eb.285ab8","name":"","topic":"1","payload":"[255,255,255,255,255]","payloadType":"json","repeat":"","crontab":"","once":false,"x":190,"y":280,"wires":[["60275d4c.9b60dc"]]},{"id":"ed7aa2c1.abe42","type":"debug","z":"52b800eb.285ab8","name":"","active":true,"console":"false","complete":"false","x":510,"y":140,"wires":[]},{"id":"87528ebd.ee762","type":"comment","z":"52b800eb.285ab8","name":"Receive","info":"","x":130,"y":100,"wires":[]},{"id":"8ae18555.173a08","type":"subflow:3ba422b0.9c410e","z":"52b800eb.285ab8","name":"","x":310,"y":140,"wires":[["ed7aa2c1.abe42"]]},{"id":"27a65618.ee047a","type":"udp out","z":"52b800eb.285ab8","name":"","addr":"localhost","iface":"","port":"6454","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":660,"y":280,"wires":[]},{"id":"60275d4c.9b60dc","type":"subflow:3ba422b0.9c410e","z":"52b800eb.285ab8","name":"","x":430,"y":280,"wires":[["27a65618.ee047a"]]},{"id":"2c150c62.865b04","type":"comment","z":"52b800eb.285ab8","name":"Send","info":"","x":130,"y":240,"wires":[]},{"id":"d3233035.bedfe8","type":"comment","z":"52b800eb.285ab8","name":"Art-Net sending and receiving","info":"","x":200,"y":40,"wires":[]}]
@ctr49
Copy link

ctr49 commented Dec 20, 2016

Could you please describe the values in the flow? It's clear that the topic ("1:") is the universe but what about all those 255's?
[255,255,255,255,255]
I can think of net, subnet, address/channel, value, but thats only 4 and in which order?

Thanks!

@smadds
Copy link

smadds commented Jan 3, 2017

@ctr49 - I was assuming these were the dmx values for each channel, starting at channel 1, but I'm not getting any response from the lights. Can you clarify please, @natcl?

@gobo-ws
Copy link

gobo-ws commented Mar 9, 2020

Hi,
Does anyone (@natcl) have a example flow with Art-Net input converted from the buffer form to something more simple format to use?
Thanks!

@natcl
Copy link
Author

natcl commented Mar 9, 2020

What kind of output are you looking for?

@gobo-ws
Copy link

gobo-ws commented Mar 9, 2020

Thanks for your quick reply.
Don't really know how to explain it but something like an array that contains the universe Id and DMX channel values similar to the Art-Net output.

@natcl
Copy link
Author

natcl commented Mar 9, 2020 via email

@gobo-ws
Copy link

gobo-ws commented Mar 10, 2020

The universe is included in msg.topic and the data is in the payload (as a buffer) which you can manipulate like a normal array so that should be easy to get in a function node.

-- lecaude.com studioimaginaire.com
Le 9 mars 2020 à 22:30, Johan Nilsson @.***> a écrit :  Thanks for your quick reply. Don't really know how to explain it but something like an array that contains the universe Id and DMX channel values similar to the Art-Net output. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Thanks, now I have come further.
I also had some trouble sending Art-Net data from OLA to your flow (needed to enable always broadcast to make it work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment