stream-based implementation of the openpixelcontrol-protocol. Provides a protocol-parser and a client-implementation.
npm install openpixelcontrol-stream
This will run an openpixelcontrol server on the default port (7890) and send
received data to the rpi-ws281x-native module for output to a strip of
ws2812-leds.
varParseStream=require('openpixelcontrol-stream').OpcParseStream,net=require('net'),ws281x=require('rpi-ws281x-native');varserver=net.createServer(function(conn){varparser=newParseStream({channel: 1,dataFormat: ParseStream.DataFormat.UINT32_ARRAY});parser.on('setpixelcolors',function(data){ws281x.render(data);});conn.pipe(parser);});ws281x.init(100);server.listen(7890);A basic client connecting to an openpixelcontrol-server and running an animation there.
varClientStream=require('openpixelcontrol-stream').OpcClientStream,net=require('net');varNUM_LEDS=100,OPC_CHANNEL=0;varclient=newClientStream();// connect to openpixelcontrol-server at `192.168.1.42:7890`varsocket=net.createConnection(7890,'192.168.1.42',function(){client.pipe(socket);run();});functionrun(){// create a typed-array for color-datavardata=newUint32Array(NUM_LEDS);// setup an animation-loop at 10FPSsetInterval(function(){// ... update colors in `data` ...client.setPixelColors(OPC_CHANNEL,data);},100);}