sgparse
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

SGPARSE

Run tests

Biblioteca para converter payloads da Sigfox de hexadecimal para dados legiveis, baseado em um FRAME e um TEMPLATE.

Exemplo de um template

 const templateRef = [{
    label: 'temperature',
    bytes: [5, 6, 7, 8, 9, 10, 11],
    bits: { offset: 0, length: 11 },
    type: 'temperature',
  },
  {
    label: 'resetType',
    bytes: [1],
    bits: { offset: 0, length: 8 },
    type: 'int',
  }];

Convertendo um payload em um objeto

import { Sigmeter } from 'sgparse';
const sigmeter = new Sigmeter();
const event = sigmeter.decode('0137006DDB003354FA0004B5');
console.log(event);

/*
{
  frame: 2,
  config: false,
    data: {
      reset: false,
      lastLog: false,
        count1: 7143479,
        count2: 3342555,
        timeCount1: 348064,
        timeCount2: 1205,
     },
}
*/

Convertendo um objeto em um payload

import { BSHM } from 'sgparse';
const bshm = new BSHM();
const config = [
  timestampSyncPeriod: {
    value: 6,
    unit: 'HOURS',
  },
  downlinkPeriod: {
    value: 1,
    unit: 'DAYS',
  }]

const payload = bshm.encode(config,12,true); 
// 12 é o tamanho do payload em bytes e true é para indicar que deve ser gerado CRC e adicionado ao ultimo byte.

console.log(payload);

/* 0086C1000000000000000058 */

Readme

Keywords

none

Package Sidebar

Install

npm i sgparse

Weekly Downloads

0

Version

1.1.1

License

none

Unpacked Size

329 kB

Total Files

114

Last publish

Collaborators

  • sigmaisiot