Introduction

MTS or Movement Tracking System is an android SDK written in Java & Kotlin. It can be integrated into any native android or react native application (android only). MTS SDK can be used for user/vehicle tracking.

To learn more about the MTS service, refer to the documentation.

📘

Currently, supports 21=<SDK<=29.

Features of MTS SDK

MTS SDK provides the following features:

  • Provides real-time location updates.
  • Sync location updates to server in real-time.
  • Works in the background even if the app is killed.
  • This library can be used in react native as well as in native android.
  • Sync Location Trace both through REST API & MQTT (MQ Telemetry Transport) Protocol.

Installation

npm install @os1-platform/mts-mobile

Usage

import * as MtsLib from '@os1-platform/mts-mobile';
// Add token expiry sync task in root index file (index.ts)
import { registerSyncTask } from '@os1-platform/mts-mobile';
registerSyncTask();

MTS Default Config

export class MTSDefaults {
  locationFrequency: number = 10000; // in milli seconds (no. of seconds after which location updates will happen)
  distanceAccuracyLimit: number = 250; // in metres
  speedLimit: number = 28; // in m/s
  mode: MTSMode = MTSMode.HYBRID;
  environment: MTSEnv = MTSEnv.DEV;
  batchSize: number = 25;
  isMqttCleanSession: boolean = true;
  mqttKeepAliveInterval: number = 15 * 60; //in seconds
  maxLocationAge: number = 15000; // in milliseconds
  maxTraceSession: number = 24 * 3600 * 100; //in milliseconds
  isOdometerEnabled: boolean = true;
  retriesBeforeFallback: number = 1;
  httpFailureLimit: number = 5;
  dataSendDelay: number = 30000; // in milli seconds
  alarmTime: number = 60000; // in milli seconds
  missingSeqCheckDuration: number = 5 * 60 * 1000; // in milli seconds
  odometerPushFrequency: number = 5 * 60 * 1000; // in milli seconds
  qosLevel: number = 1; // values can be 0 ,1
}

Check For Mandatory MTS Permissions

let granted = await MtsLib.requestPermissionsForMTS();
// if granted = true : all permissions granted
// granted = false : one or more permissions denied

Init MTS

import type { MTSInitRequest } from '@os1-platform/mts-mobile';

let mtsDefaults = new MtsLib.MTSDefaults();
mtsDefaults.speedLimit = 5000;
mtsDefaults.locationFrequency = 10000;
mtsDefaults.environment = MtsLib.MTSEnv.PRE_PROD;
mtsDefaults.isOdometerEnabled = false;

//Change MTS default values as per your use case

// ...Use this for Initiating MTS
let mtsInitReq: MTSInitRequest = {
  appName: 'app_name',
  appVersion: '1',
  mtsDeviceID: 'deviceId', // Use a unique device ID here
  configData: mtsDefaults,
  baseURL: 'https://{tenant}.example.io/{mtsEndpoint}',
  accessToken: 'token',
  tenantID: 'TENANTID',
};
MtsLib.initMTS(mtsInitReq, async () => {
  // fetch latest token and return the lastest access token
  return 'newToken';
});

See Error Codes for Possible error types.

Start MTS

let startReq: MTSStartRequest = {
  accessToken: 'token', // update access token
  resetSequence: false,
  dispatchID: '12345', // pass dispatch ID here
  expiryTime: Date.now() + 24 * 2600 * 1000, // expiry time after which MTS will stop automatically
};
await MtsLib.startMTS(startReq);

Publish Event

await MtsLib.publishEvent('TESTEVENT', { battery: 56, network: 100 });

Stop MTS

await MtsLib.stopMTS();

Error Codes

PERMISSIONS_ERROR[2500] = "Mandatory Android Permissions not provided"
    MTS_INIT_ERROR[2501] ="MTS INIT Not called! MTS Device ID is Empty"
    PARAM_MISSING[2502] = "Mandatory Paramater is missing in request"