Skip to content

Read Data Logging

Your Tap Device can be configured to continously store bundle values at a fixed rate (we call it data logging).

This guide will show you how to retrieve the data log with your application.

Prerequisities

What you need

  • Tap Device
  • IoTize Studio
  • Target Application that handles serial communication
  • Mobile Device with RF capabilities

You have iotized your target application variables

See steps to iotize your target application

You have enabled data logging

To enable data logging, edit IoTize Studio configuration: IoTize Explorer / Bundles / <Your bundle> / DataLog Period (the period is in seconds).

Make sure value is not 0 (meaning data logging is disabled).

import { Tap } from '@iotize/device-client.js/device';

let tap: Tap; // ... init your tap device
let bundleId: number = 1;

// Read data logging period
let dataLogPeriodMinutes = (
  await tap.service.bundle.getDataLogPeriod(bundleId)
).body();

if (dataLogPeriodMinutes == 0) {
  console.warn(`Data log is disabled for bundle with id=${bundleId}`);
} else {
  console.log(
    `Bundle with id=${bundleId} has a data log period of ${dataLogPeriodMinutes} milliseconds`
  );
}

Get data log

import { Tap } from '@iotize/device-client.js/device';

let tap: Tap; // ... init your tap device

// Get the number of data log packets stored on the tap
let packetCount = (await tap.service.datalog.getPacketCount()).body();

let packets = [];

// For example let's read all packets from the tap
for (let i = 0; i < packetCount; i++) {
  packets.push((await tap.service.datalog.dequeueOnePacket()).body());
}
console.log(`Number of packets: ${packetCount}`);

let newPacketCount = (await tap.service.datalog.getPacketCount()).body();
console.log(`New packet count: ${newPacketCount}`); // Will be 0 but it may be >= 1 if a new packet was created by the tap in the meantime

// Not yet documented
// Not yet documented

Manage data log state

You can also control data log acquisitionn (start/stop/clear)

import { Tap } from '@iotize/device-client.js/device';
let tap: Tap; // ... init your tap device

let isDatalogRunning = (await tap.service.datalog.isRunning()).body()!;

// Stopping data log acquisition
if (isDatalogRunning) {
  (await tap.service.datalog.stop()).successful();
}

// Restarting data log acquisition
(await tap.service.datalog.run()).successful();

// Remove packets (you will loose all data)
(await tap.service.datalog.flush()).successful();

// Not yet documented
// Not yet documented

IMPROVED: