MATRIX Ecosystem protocol buffers for NodeJS
Package contains a static build of MATRIX protocol buffers via protobufjs 6.x.
Installation
$ npm install matrix-protos
Features
- Removes the need of passing proto paths inside applications
- Improved message API thanks to protobufjs 6.x
IMPORTANT
Please keep in mind that NodeJS protobufjs interface uses camelCase
instead of snake_case
. This is important if you are using the proto messages as a reference, because fields like rect_detection
or delay_between_updates
become rectDetection
and delayBetweenUpdates
respectively.
Docs & Community
- MATRIX documentation / Quickstart
- Community
- Github repo
- Examples
- MOS - A NodeJS framework for MATRIX Creator
- MATRIX-CLI - MOS Command line
Quick Start
NodeJS proto message usage is provided via protobufjs 6.x library, so make sure you check out the documentation.
You can find the code of the following examples in the MATRIX MALOS repo
MATRIX MALOS protocol is an abstraction layer built on top of ZeroMQ that uses protocol buffers as the data exchange format. In a nutshell, MALOS exposes 4 ports for every service: base or driver port, error port, keep alive port and data update port. In the following examples, we will show how to send a config to the driver port and how to obtain data updates on the data update port.
Please refer to the examples for a complete implementation.
Importing ZMQ and matrix-proto modules
var zmq = // Import MATRIX Proto messagesvar matrix_io = matrix_io
Getting data about the available drivers and ports
Go to the full code
var requestSocket = zmq var creator_ip = processenvCREATOR_IP || '127.0.0.1';var creator_info_base_port = 20012 requestSocket; requestSocketrequestSocket;
The output should more or less look like this:
$ node test_driver_info.jsMalosDriverInfo
You can then use the basePort
in the examples below.
Configuring and reading the pressure sensor
Go to the full code
# Configure the socketvar configSocket = zmqconfigSocket // Now prepare valid configuration and send it.var config = matrix_iomalosv1driverDriverConfig configSocket # Configure the data update port socketvar updateSocket = zmqupdateSocketupdateSocket updateSocket;
Configuring and reading the humidity sensor
Go to the full code
# Configure the socketvar configSocket = zmqconfigSocket // Now prepare valid configuration and send it.var config = matrix_iomalosv1driverDriverConfig configSocket # Configure the data update port socketvar updateSocket = zmqupdateSocketupdateSocket updateSocket;
Configuring and reading the IMU (Inertial Measurement Unit)
Go to the full code
# Configure the socketvar configSocket = zmqconfigSocket // Now prepare a valid configuration message and send it. The extra args in this// example: // * delayBetweenUpdates: different delay between data updates// * timeoutAfterLastPing: Stop sending data updates after 6 secs of the last pingvar config = matrix_iomalosv1driverDriverConfig configSocket # Configure the data update port socketvar updateSocket = zmqupdateSocketupdateSocket updateSocket;
Setting the Everloop LED intensity
Go to the full code
# Configure the socketvar configSocket = zmqconfigSocket var max_intensity = 50var intensity_value = max_intensity { var image = matrix_iomalosv1ioEverloopImage for var j = 0; j < 35; ++j var ledValue = matrix_iomalosv1ioLedValue; imageled var config = matrix_iomalosv1driverDriverConfig configSocket;} ;
Using the GPIO
Go to the full code
# Configure the socketvar configSocket = zmqconfigSocket // Set GPIO 0 to output modevar gpio_cfg_cmd = matrix_iomalosv1ioGpioParams // For demo: toggle function for output valueprocess;consoleif toggle gpio_cfg_cmdvalue = 1;else gpio_cfg_cmdvalue = 0; // build and sending protovar config = matrix_iomalosv1driverDriverConfigconfigSocket // Set GPIO 1 to input modevar config = matrix_iomalosv1driverDriverConfigconfigSocket # Configure the data update port socketvar updateSocket = zmqupdateSocketupdateSocket updateSocket;