Skip to content

Commit

Permalink
Explain how the UDPX pixels protocol is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
martinberlin committed Oct 3, 2019
1 parent 6b11009 commit 918285d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
Remora is a simple pseudo animation language that works as a companion to Orca receiving UDP short instructions and sending animations to addressable LED stripes.
This animations run entirely in the ESP32 controller and are initially aimed to be short so they can be triggered by [Orca sequencer](https://github.com/hundredrabbits/Orca) bangs

## Branches

- **develop** main branch ahead of others where latest updates are merged
- **master** stable branch
- **m5/*** to be compiled on M5StickC devices

## Communications protocol

UDP will be hearing in a configurable port so you can send short instructions from Orca or any other program you desire.
UDP will be hearing in port 49161 so you can send short instructions from Orca or any other program you desire.
This project is mainly headed to receive short UDP commands from ORCΛ but on develop branch also UDPX [Pixel library}(https://github.com/IoTPanic/pixels/) coded by IoTPanic is included. So if the UDP payload is major than 9 pixels it will trigger the binary protocol.
To test it there is an online tool called [UDPX](http://api.slosarek.eu/udpx/). As a prerequisite you need to start from this repository a script to act as a middleware:

nodejs middleware.js

For security reasons it's not allowed to send UDP directly from the browser, so this acts as a proxy doing TCP->UDP.
Fill your ESP32 IP address and UDP port with 49161. Provided the middleware is running you should be able to send binary animations directly from the UDPX tester.
The test is though as a learning tool. Please read the documentation of the [UDPX Repository](https://github.com/martinberlin/udpx) to understand more about the communications protocol.

### Requirements and discovering the ESP32 IP Address

Expand Down
49 changes: 49 additions & 0 deletions extras/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Middleware will just receive a POST with :
* data - Json data (Method: POST)
* ip - Destination ip (GET)
* port - Optional defaults to 1234 (GET)
*
* And will send that data depending on the compressed flag as an UDP package to destination ip
*
* Turn DEBUG false to disable console output
*/
var DEBUG = true;
var PORT = 1234; // Default port
var HOST = '127.0.0.1';

// Requires
var dgram = require('dgram');
const http = require('http');
var url = require('url');
var client = dgram.createSocket('udp4');

http.createServer((request, response) => {
let body = [];
request.on('data', (chunk) => {
body.push(chunk);

}).on('end', () => {

var url_parts = url.parse(request.url, true);
var query = url_parts.query;
var outBuff = Buffer.concat(body);
if (DEBUG) console.log(body);
sendBuffer(outBuff, query.ip, query.port);

response.end();
})
.on('error', (err) => {
console.error(err);
});
}).listen(1234);

function sendBuffer(inBuffer, outHost, port) {
udpPort = (port) ? port : PORT;
client.send(inBuffer, 0, inBuffer.length, udpPort, outHost, function(err, bytes) {
if (err) throw err;

if (DEBUG) console.log('Sent to ' + outHost +':'+ udpPort);
});
}

0 comments on commit 918285d

Please sign in to comment.