npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tosolve/datacodec

v0.18.2

Published

Library with useful functions for our clients

Readme

2Solve Datacodec

A lightweight data decoding library designed to interpret and convert raw transmission payloads from 2Solve devices. It provides utilities to transform encoded data (such as hexadecimal payloads) into structured and readable formats like JSON, simplifying integration and data processing.


Installation

npm install @tosolve/datacodec

Quick Start

const { packetDecode } = require('@tosolve/datacodec');

const rawData = '000441da6666';
const result = packetDecode(rawData);

console.log(result);
// { temp: '27.3000' }

API

packetDecode(rawdata, offset?)

Decodes a raw payload into a structured JSON object.

| Parameter | Type | Default | Description | |-----------|--------|---------|----------------------------------------------------| | rawdata | String | — | Hexadecimal string or Base64-encoded JSON payload | | offset | Number | 0 | Byte offset to start reading from |

Returns: An object where each key is a sensor name and its value is the decoded reading.

const { packetDecode } = require('@tosolve/datacodec');

// Hex string
packetDecode('000441da6666');
// { temp: '27.3000' }

// With offset
packetDecode('0033c1a237ac', 0);
// { GPS_Lat: '-20.2772' }

mapping

An object containing all supported sensor definitions. Each entry follows the structure:

{ sensorName: [id, byteLength, value, dataType] }
const { mapping } = require('@tosolve/datacodec');

console.log(mapping.temp);
// [4, 4, null, 'float']

mappingKeys

An array of all supported sensor names.

const { mappingKeys } = require('@tosolve/datacodec');

console.log(mappingKeys);
// ['temp', 'hum', 'GPS_Lat', 'GPS_Lng', ...]

Supported Input Formats

packetDecode accepts the following input formats:

  • Raw hexadecimal string — "000441da6666"
  • Base64-encoded JSON with one of the following payload fields:
{ "payload": "..." }
{ "uplink_message": { "frm_payload": "..." } }
{ "data": { "uplink_message": { "frm_payload": "..." } } }
{ "params": { "payload": "..." } }

This makes the library compatible with common LoRaWAN network server formats out of the box.


Supported Data Types

| Type | Description | |-----------|------------------------------------| | uint | Unsigned integer | | int16 | 16-bit signed integer | | int32 | 32-bit signed integer | | float | IEEE 754 single-precision float | | uintHex | Unsigned integer as hex string |


Supported Sensors

The library includes 180+ predefined sensor mappings across the following categories:

| Category | Examples | |-------------------|---------------------------------------------------| | Temperature | temp, hum, thermocouple channels | | Battery | BatteryMon, BatteryMon_IC | | Analog Inputs | AI1AI5, EAI1EAI5 (float variants) | | GPS | GPS_Lat, GPS_Lng, altitude, speed, satellites | | Pressure | DPS1DPS4, water pressure | | Water Quality | pH, turbidity, conductivity (+ standard deviation)| | RFID | RC522_UID, PN532_UID, PN532_NAME | | Digital I/O | DI1DI10, DO1DO14 | | Vibration | Peak frequency, RMS and peak acceleration X/Y/Z | | Modbus Registers | 16-bit and 32-bit, signed/unsigned/float | | Pulse / Relay | Pulse inputs, relay and drain manager states |


Advanced Example

const { packetDecode } = require('@tosolve/datacodec');

const rawData =
  '801E40E66666801F42366666802044454666802441BB3333' +
  '80253F40000080263F800000802741200000';

const result = packetDecode(rawData);

// Optionally convert string values to numbers
for (const key in result) {
  result[key] = Number(result[key]);
}

console.log(result);

Error Handling

packetDecode throws descriptive errors for invalid inputs:

packetDecode('xyz');          // Error: invalid hex format
packetDecode('aabbcc', -1);   // Error: offset must be a non-negative integer
packetDecode('aabbcc', 100);  // Error: offset out of bounds

Running Tests

npm test

Tests are written with Jest and located in __tests__/packetDecode.spec.js.


Migrating from 2stools-daq

This package replaces the legacy 2stools-daq package. The API is fully compatible — only the package name changed.

1. Uninstall the old package and install the new one:

npm uninstall 2stools-daq
npm install @tosolve/datacodec

2. Update your imports:

// Before
const { packetDecode } = require('2stools-daq');

// After
const { packetDecode } = require('@tosolve/datacodec');

No other changes are required.


License

ISC © 2Solve Engenharia e Tecnologia