filament-sdk v2.0.13
sdk
Filament specific SDK middlewares for node/electron/cordova
The Big idea
npm install filament-sdk
import {Mesh, SerialHost, BleCentral, BaseUtil, ParserMiddleware, OPCServer} from 'filament-sdk';
var app = new Mesh(() => {
console.log("THC has been initialized");
});
app.use(new SerialHost({ baudrate : 9600 }));
app.use(new BaseUtil());
app.use(new ParserMiddleware());
app.use(new OPCServer({port : 9876}));
app.on('discover', (event) => {
// you are aware of, but not yet connected, to a device
console.log(event.id) // short hashname
console.log(event.handle) // the transport specific connection metadata
console.log(event.type) // BLECentral / SerialHost
app.connect(event)
.catch(e => console.log(e));
})
app.on('link', (link) => {
// the link has been extended by the methods in base utils
link.eval({
script : "led.green()",
environment : "tap"
memSafe : true
}, function onProgress({stage, details, percent}){
console.log(`got progress event, ${percent}% completed`);
})
.then(() => {
console.log("the LED is green!");
})
.catch(e => {
console.log("there was an error!", e);
})
})
//start things up
app.start(true);
Plugin types
- Transports - physical layer transport plugins (BLE for node/electron/cordova, Serial for node/electron)
- Integrations - Statsd, OPC, file, stdout, fusion, dweet, etc.
Utils - Method extensions (dfu, eval, sendFile, reboot...)
Transports and Integrations are pretty much set and forget, as seen above. Utils export a list of methods that get attached to all new links. It is likely that you will need to use several of them to complete more intricate app specific flows.
All util methods MUST conform to the following signature
var promise = link.method(options, onProgress);
assert(promise instanceOf Promise);
// example
link.dfu({
firmware_file : "patchos",
firmware_dir : process.cwd()
}, ({percent, stage, details}) => {
console.log(`DFU ${percent}%`);
}).then(() => {
console.log("DFU COMPLETE")
// return link.someOtherMethod....
}).catch(() => {
console.log("DFU ERROR")
})
API Details
Note
some of the options available (compass, more specifically) are options available for parent classes of the plugin, it is safe to ignore them; just make note of the ones that are pertinant to what you're trying to accomplish.
Cordova Plugins
Some cordova plugins are necessary to... do anything. ble-central, device, network information...
cordova plugin add cordova-plugin-ble-central
cordova plugin add cordova-plugin-device
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago