jinsmemesdk-node-noble-xdeprecated

JINS MEME SDK for Node.js using noble-derivatives

Usage no npm install needed!

<script type="module">
  import jinsmemesdkNodeNobleX from 'https://cdn.skypack.dev/jinsmemesdk-node-noble-x';
</script>

README

jinsmemesdk-node-noble-x

JINS MEME SDK for Node.js using noble BLE library. If you need japanese information, read README_ja.md

Features

  • It can be implemented in electron.js main process as sdk supports event handler
  • Supports multiple JINS MEME connections

License

Subject to JINS MEME SDK terms of use

Prerequisites

  • Any noble(BLE for Node.js) derivatives
    • noble-winrt
      • Windows(Windows 10 build 10.0.15063 or later)
      • MIT License
      • ^0.0.3
      • install github repository directory as npm installs different modules ;(.
    • noble-mac
      • Mac(macOS 10.7 or later)
      • MIT License
      • ^0.0.4
    • noble
      • Mac/Linux
      • MIT License
      • ^1.9.1
  • node-rest-client
    • needs for SDK authentication
    • MIT License
    • ^3.1.0

Samples

JinsMemeSDK-Samples-NodeJS

Sequences

The following is the minimum sequence of execution.

  • Specifies the type of noble to import (module.exports.noble_type = 'noble-winrt';)
  • require to load jinsmesdk-node-noble-x
  • Performs app authentication with setAppClientID
  • Create memeDevice instance
  • scan searches MEME
  • Connecting to MEME with connect
  • start/stop receiving data with startDataReport/stopDataReport
  • Disconnecting from MEME with disconnect

ScanAndConnect can handle the latter half automatically.

Methods

memeDevice

Create an instance. If you want to use multiple instances, you need to assign them indivisually.

let memeDevice = new memeDevice();

setAppClientID

Use the authentication information obtained from the JINS MEME DEVELOPERS to perform application authentication. To use the JINS MEME SDK for NodeJS, you must first run the API once. If it is an invalid code, you cannot connect to the JINS MEME in the subsequent process. If you are using multiple MEMEs, you only need to run it once in any instance.

memeDevice.setAppClientID(appClientId, clientSecret, successCallback, errorCallback);

  • appClientId: client_id obtained with JINS MEME DEVELOPERS
  • clientSecret: client_secret obtained with JINS MEME DEVELOPERS
  • successCallback: Handling authentication success
  • errorCallback: Handling authentication failure

scan

Starts a BLE scan of the device and starts a MEME search. Scan stops automatically in 20 seconds. The found devices information sends via the device-discovered event listener.

memeDevice.scan();

connect

Specify the MAC address of the MEME to which you want to connect.

memeDevice.connect(mac_address_without_coron [, mode]);

  • mac_address_without_coron: Sets the MAC Address string to a lowercase MAC Address string that does not contain a colon.
  • mode: Set connection options
    • mode = 0: do nothing on error(default)
    • mode = 1: retry connect once

scanAndConnect

If the MEME to which you want to connect is determined, start scan with the MAC address, and connect if an appropriate device is found.

memeDevice.scanAndConnect(mac_address_without_coron);

  • mac_address_without_coron: Sets the MAC Address string to a lowercase MAC Address string that does not contain a colon.

startDataReport

Starts data transmission when connected.

memeDevice.startDataReport(callback);

  • callback: Sets the callback function for real-time mode

The callback passes the following data as a object.

data = {
      blinkSpeed: /*blink speed*/,
      blinkStrength: /*blink strength*/,
      roll: /*oyler R*/,
      pitch: /*oyler P*/,
      yaw: /*oyler Y*/,
      accX: /*acceleration X*/,
      accY: /*acceleration Y*/,
      accZ: /*acceleration Z*/,
      fitError: /*wearing flag(Not recommended for use)*/,
      walking: /*step flag*/,
      noiseStatus: /*noise status*/,
      powerLeft: /*battery level 0:in charge 1:low-5:high*/,
      eyeMoveUp: /*eye movement up*/,
      eyeMoveDown: /*eye movement down*/,
      eyeMoveLeft: /*eye movement left*/,
      eyeMoveRight: /*eye movement right*/,
      sequenceNumber: /*index number, 0-255*/
    };

setRtCallback

This is called when you want to change the callback function for real-time mode.

memeDevice.setRtCallback(callback);

stopDataReport

Terminates data transmission when connected.

memeDevice.stopDataReport();

disconnect

Disconnects from the connected MEME.

memeDevice.disconnect();

setAutoReconnect

If you disconnect because of weak signal or moving away from the device, it will automatically try scanAndConnect() to the last connected device.

  • If you call disconnect(), it will be set to false to prevent automatic reconnection, so please set it again if necessary.
  • If not specified, automatic reconnection will not occur.

memeDevice.setAutoReconnect(bool = false);

  • bool: option
    • true: reconnect automatically
    • false: don't reconnect automatically

getHWVersion

shows hardware version

const obj = memeDevice.getHWVersion();
//obj -> { model_main: 1, model_sub: 1, version: 1 }

getFWVersion

shows firmware version

const obj = memeDevice.getFWVersion();
//obj -> { str: '1.1.1', major: 1, minor: 1, revision: 1 }

getSDKVersion

shows SDK(this library) version

const obj = memeDevice.getSDKVersion();
//obj -> { str: '1.0.3', major: 1, minor: 0, revision: 3 }

Event listener

device-discovered

Notify the event listener, sequential id, mac address, etc. of device information when a device is found during a scan. In the case of electron, this information can be sent to the renderer to place the logic on the main side.

memeDevice.on('device-discovered', (device) => {
  //Process device information
})

device has the following object structure:.

device = {
      idx: /*sequential id*/,
      peripheral: /*peripheral info*/,
      mac_addr: /*mac_addr*/,
      name: /*localName*/,
      rssi: /*rssi*/
    };

device-status

Notifies you when the connection/disconnection status changes.

memeDevice1.on('device-status', (status) => {
  //
});
  • status: 0: disconnect
  • status: 1: connected
  • status: 2: scan-connecting

Tips

Start sending data immediately after connection

If you want to start sending data automatically after connected, run startDataReport when device-status==1 is received.

memeDevice.on('device-status', (status) => {
  if(status == 1){
    memeDevice.startDataReport(callback);
  }
});