sensit-payload
v0.7.2
Published
Sensit Payload
Downloads
2
Readme
sensit-payload
Sensit payload parser and serializer
Installation
npm install sensit-payload
API
const sensitPayload = require('sensit-payload');
sensitPayload.parse(payload)
Parse a Sensit payload and returning an object representing the values contained in the payload. The payload
argument is a 8 hexadecimals string or a 24 hexadecimals string if the config of the Sensit is sent.
The object representing the values contained in the payload will always containe the following properties:
error
{Number} -0
if no error something else otherwise check sensitPayload.*_ERROR_CODE constantstype
{Number} -2
for Sensit v2 payload,3
for Sensit v3 payloadbutton
{Boolean} -true
when the button was pressed,false
otherwiseconfig
{Object} -null
if the payload does not contain the configmode
{String} - string representing the current mode, see exposed constantsmodeCode
{Number} - number representing the current mode, see exposed constantsbatteryLevel
{Number} - number of mV of the batterybattery
{Number} - percentage of the battery energy still left
The next properties are present depending on the current mode, in case of a v2 payload when the button is pressed the record corresponding to the mode is not sent except for the temperature in the temperature mode.
temperature
{Number} - temperature in celsius degreeshumidity
{Number} - humidity in percentlight
{Number} - brightness in luxmagnet
{Boolean} -true
when magnet detected,false
otherwisevibration
{Boolean} -true
when vibration is ongoing,false
otherwisedoor
{Number} - a number representing door state, see exposed constantseventCounter
{Number} - number of times the event was catched
const data = sensitPayload.parse("f6100065")
// { error: 0, type: 3, brightness: 1.05, button: false, modeCode: 2, mode: 'light', config: null }
sensitPayload.parseConfig(config, payloadType)
The config is different depending on the current verion:
V3 specific fields
isStandByPeriodic
{Boolean} - true if StandBy is in periodic modeisTemperaturePeriodic
{Boolean} - true if Temperature is in periodic modeisDoorPeriodic
{Boolean} - true if Door is in periodic modeisMagnetPeriodic
{Boolean} - true if Magnet is in periodic modeisVibrationPeriodic
{Boolean} - true if Vibration is in periodic modeisLightPeriodic
{Boolean} - true if Light is in periodic modelightThreshold
{Number} - the brightness threshold
V2 specifig fields
lightUpper
{Number} - upper brightness thresholdlightLower
{Number} - lower brightness threshold
Shared fields
temperatureLower
{Number} - lower temperature thresholdtemperatureUpper
{Number} - upper temperature thresholdhumidityLower
{Number} - lower humidity thresholdhumidityUpper
{Number} - upper humidity thresholdlightLower
{Number} - lower light thresholdlightUpper
{Number} - upper light thresholdvibrationSensitivity
{Number} - code that indicates how sensitive is the vibration sensordoor
{Number} - code that indicates how sensitive is the door detectionperiod
{Number}limited
{Boolean}
Example
const data = sensitPayload.parse("895d205d00ff008f04027390")
data should contain:
{
error: 0,
type: 2,
button: false,
batteryLevel: 4150,
battery: 95,
modeCode: 1,
mode: 'temperature',
temperature: 19,
humidity: 46.5,
config: {
temperatureLower: -20,
temperatureUpper: 107,
humidityLower: 0,
humidityUpper: 0,
lightUpper: 10,
lightLower: 0,
vibrationSensitivity: 2,
door: 0,
period: 1,
limited: true
}
}
sensitPayload.serializeConfig(config, payloadType)
Serialize an object representating (config
argument above) Sensit config into a 16 hexadecimals string.
The payloadType
argument is either sensitPayload.PAYLOAD_TYPE_V2
or sensitPayload.PAYLOAD_TYPE_V3
, other value will throw an error.
Example
const config = {
isStandByPeriodic: 0,
isTemperaturePeriodic: 0,
isLightPeriodic: 0,
isDoorPeriodic: 0,
isVibrationPeriodic: 0,
isMagnetPeriodic: 0,
temperatureLower: -20,
temperatureUpper: 107,
humidityLower: 0,
humidityUpper: 0,
lightThreshold: 0,
lightUpper: 10,
lightLower: 0,
vibrationSensitivity: 2,
vibrationClearTime: 0,
door: 0,
period: 1,
limited: 1
};
const payload = sensitPayload.serializeConfig(config, sensitPayload.PAYLOAD_TYPE_V3);
payload should be equal to 00ff008f04027390
Test
Run test suite with:
npm install
npm test
Development
Requirements
- Install node.js, we recommand nvm to handle multiple version of node on your machine
- Install node-gyp with
npm install node-gyp -g
Build
node-gyp rebuild
Run
node sample.js
Sensit payload specification
v2
v3
Extra
For more checkout https://build.sigfox.com/sensit-for-developers.
Licence
MIT