Skip to content

hoiast/marvelmind.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

marvelmind.js

Javascript Library for Marvelmind GPS

Marlvelmind.js includes two small Javascript classes for receiving and parsing data from Marvelmind mobile beacon by USB/serial port.

This code contains a CLIENT and a SERVER utility classes. Both classes read data using bufferpack and Marvelmind Instructions (v7.00). They apply a similar approach to read incoming data, but differ significantly on how data is received and parsed.

The client class is built upon WebUSB API, an experimental technology which, up to this date, is only supported by Chromium Based Browsers (Google Chrome, Edge, Opera, ...). On client, parsing incoming data chunks into readable message is performed by a custom parser.

The server class of this code uses a serial port library, serialport, to acquire data stream. On server, parsing is conviniently done with parser-delimiter.

Events are emitted using EventEmitter and native Node.js Events API for client and server classes, respectively.

How to Test

Please, ensure that all deploying instructions by Marvelmind have been thoroughly followed. Remember to update all SW Firmware, setup Beacon positioning, turn them ON, adjust Maps and Submaps and connect the USB Modem on your computer. It's mandatory to install the STM32 Driver to get modem data via USB.

Note: Don't forget to ensure Marvelmind Dashboard is closed when testing this code - only one program (a Node.js server, a web browser or the Marvelmind Dashboard) is allowed to receive data stream from the USB Modem at a specific port and time.

Note 2: Some data stream are disabled by default. For example, quality and telemetry streams require that options “Quality and extended location data” and “Telemetry stream” are enabled, respectively. Visit the Dashboard, select a device and go under Interfaces to see more.

Client version

  • Open /client/test.html
  • Click on Connect GPS Modem
  • Select the Marvelmind Modem.
  • Incoming data will be logged on console. Enjoy!

Server version

  • Verify the USB Serial port address used in your OS. This address may vary significantly on Windows, Linux and MacOS devices. Update it on the portAddress argument. For example, if your USB port address is COM3:
let marvelmind = new Marvelmind({portAddress:'COM3'})
  • On the /server/ folder, run:
npm install
npm run test
  • Incoming data will be logged on console. Enjoy!

How to Use

Events:

Both classes emit Events to transfer incoming data. Here follows a comprehensive list:

Event String Content Marvelmind Code Version
rawDistances Beacon Distances (mm) 0x0004 (4) Both
telemetry Battery (mV) and RSSI (Dbm) 0x0006 (6) Both
quality Quality Parameter (%) and Geofencing Zone Index 0x0007 (7) Both
hedgehogMilimeter Hedgehog Coordinates (mm) 0x0011 (17) Both
beaconsMilimeter Beacons Coordinates (mm) 0x0012 (18) Both
connected None ----------- Client Only
disconnected None ----------- Client Only

Client version

    <script src="assets/js/bufferpack.js"></script>
    <script src="assets/js/EventEmitter.js"></script>
    <script src="marvelmind.js"></script>
    <script>
        let marvelmind = new Marvelmind();
        marvelmind.on('hedgehogMilimeter', (hedgehogAddress, hedgehogCoordinates) => {
            console.log(hedgehogAddress, hedgehogCoordinates);
        });
        marvelmind.toggleConnection(); //Requires user interaction first!
    </script>

Attributes:

baudRate - baudrate. Should match baudrate of hedgehog-beacon.

Default value: 9600

debug - debug flag. Activates console output.

Default value: False

Methods:

toggleConnection( ) - Toggle serial port connection.

Note: Modern browser policy requires that users interact with the site before allowing a WebUSB connection. For example, on /client/test.html, a click event is used to ensure user interaction.

Server version

const { Marvelmind } = require('./marvelmind');
const marvelmind = new Marvelmind();
marvelmind.on('hedgehogMilimeter', (hedgehogAddress, hedgehogCoordinates) => {
  console.log(hedgehogAddress, hedgehogCoordinates);
});

Attributes:

portAddress - serial port device name (physical or USB/virtual). Default value: 'COM3'

  • '/dev/ttyACM0' - typical for Linux
  • '/dev/tty.usbmodem1451' - typical for Mac OS X
  • 'COM3' to 'COM6' - typical for Windows

baudRate - baudrate. Should match baudrate of hedgehog-beacon.

Default value: 9600

debug - debug flag. Activates console output.

Default value: False

paused - pause flag. If true, instance will not read messages parsed from serial data when created. To start data reading, use toggleReading.

Default value: False

Methods:

toggleReading( ) - Toggle data reading.

Acknowledgements

This repository is inspired by a former repository of Joshua J. Damanik which implemented Marvelmind data processing on Node.js. Additionally, some opinionated choices have been inspired by marvelmind.py for consistency.

Contact

Please reach murilohoias@gmail.com