wamp-tessel is an open-source implementation of the Web Application Messaging Protocol V2 specifically intended to run on the Tessel microcontroller. This project is a stripped-down version of Autobahn|JS, a subproject of the Autobahn project.
Autobahn|JS is a robust library that can run in multiple environments, including web browsers and in NodeJS, but it can not be used on Tessel because of its large size (by microcontroller standards) and its use of unsupported libraries.
wamp-tessel differs most notably from Autobahn|JS in these ways:
It is licensed under the MIT license.
The following example implements all four roles that Autobahn|JS (and hence wamp-tessel) offers
The code runs as part of your Tessel project in Node.js!
var wamp = require('wamp-tessel');
var connection = new wamp.Connection({url: 'ws://127.0.0.1:9000/', realm: 'realm1'});
connection.onopen = function (session) {
// 1) subscribe to a topic
function onevent(args) {
console.log("Event:", args[0]);
}
session.subscribe('com.myapp.hello', onevent);
// 2) publish an event
session.publish('com.myapp.hello', ['Hello, world!']);
// 3) register a procedure for remoting
function add2(args) {
return args[0] + args[1];
}
session.register('com.myapp.add2', add2);
// 4) call a remote procedure
session.call('com.myapp.add2', [2, 3]).then(
function (res) {
console.log("Result:", res);
}
);
};
connection.open();
wamp-tessel is available via the Node package manager here. To install:
npm install wamp-tessel
For more information, have a look at the Autobahn|JS project documentation. This provides:
wamp-tessel is essentially a stripped-down version of Autobahn|JS, a subproject of the Autobahn project. If you want to learn more about how WAMP (or this library!) works, you should check out that project.