Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleJavaScript code example

The first example is for cases when the payload type is string (Nwave HTTP Calls for example):

Code Block
languagejs
payload = "E91F345678"

// cut out 1st byte and convert to integer
first_byte = parseInt(payload.slice(0,2), 16)

// the sensor is occupied if 1st bit is 1
occupied = Boolean(first_byte & 0x01 === 1)

console.log("Occupied: ", occupied);

The second example is for cases when the payload type is array of integers (TTN, TTI for example):

Code Block
languagejs
payload = [0xE9, 0x1F, 0x34, 0x56, 0x78]

// the sensor is occupied if 1st bit of the first byte is 1
occupied = Boolean(payload[0] & 0x01 === 1)

console.log("Occupied: ", occupied);

The last example shows how to get occupancy status from base64 encoded binary message:

Code Block
languagejs
msg_base64 = 'AQ=='

// decode base64
msg_bytes = atob(msg_base64)

// get the first byte of decoded message
first_byte = msg_bytes[0].charCodeAt()

// the sensor is occupied if 1st bit of the first byte is 1
occupied = Boolean(first_byte & 0x01 === 1)

console.log('Occupied: ' + occupied)
Info

You can also refer to our Java Script payload decoder shared on the Github.

Examples of decoded messages are available on the TTN device page.

...


The parking status message uses port 1 and is confirmed by default. It may be configured as unconfirmed with or without repetitions (see downlink messages).

Byte

Bits

Name

0

0

Parking status

0: Free parking space

1: Occupied parking space

7..1

Compressed duration of the previous status

Compressed duration of the previous status may be used to restore (with some limitation) the time of the previous status change(the same as the time of the last Parking Status message, may differ from the time of actual parking event if the Parking Status message was delayed due to some limitations ) if the previous parking status message was lost. It makes historic data more consistent if connectivity is not 100% (for example, if parking status messages are configured as unconfirmed).

The following table demonstrates how to calculate the previous status duration using the compressed value.

Compressed duration

Calculated duration(full minutes)

Maximum compression error(minutes)**

compressed_duration < 90

compressed_duration

0

90 ≤ compressed_duration <120

90 + (compressed_duration - 90)*5

4

120 ≤ compressed_duration <127

240 + (compressed_duration - 120)*60

59

127

>= 660

undefined

** Total error of previous status duration consists of:

...


The heartbeat message uses port 2 and it is always confirmed. The heartbeat message contains parking status and information necessary for sensor health monitoring and it is sent every 24 hours (by default).

Byte

Bits

Name

0

0

Parking status

0: Free parking space

1: Occupied parking space

7..1

Error Mask

1

7..0

Battery voltage. To convert to actual voltage:

Vbat = (2500 + X*4)mV, where X is the value of the byte as unsigned integer

This parameter can be used as a source for Low Battery Alert:

  • >= 3000 - normal

  • <3000 - low

  • <2900 - critical

2

7..0

Temperature at which battery voltage was obtained *

3

7..0

Minimum temperature during last 24 hours *

4

7..0

Maximum temperature during last 24 hours *

5

7..6

Nwave debug data. Ignore these bytes.

5..0

Average current consumption estimation for the last 24 hours. Only power consumption of embedded sensors is used in the estimation(LoRaWAN messages transmission/reception consumption is not used in the estimation).

To convert this value (unsigned integer) to current consumption:

Current consumption = (X + 10)uA.

Current consumption should be less than 50uA. Please contact Nwave support if you get higher numbers (X>40).

Heartbeat messages allow the device’s health monitoring using Error Mask, where all zeros mean that no hardware issues were detected.

...


The startup message uses port 3 and it is always confirmed. It will be sent after every startup/reboot /(re-)join event:

Byte

Name

0

Major part of version number

1

Minor part of version number

2

Micro part of version number

3

Reset cause

0x00 No reset ( Startup message after re-joining LoRaWAN network)

0x01: Watchdog reset

0x02: Power On Reset

0x03: User Request Reset

0x06 - Brownout Reset

0x07 - Others

4

Bit 0 - parking status

0: Free parking space
1: Occupied parking space

Bits 7..1 - reserved

4.2.4 SDI tag registration message

...

Bluetooth tag setup and principles of work

Byte

Name

0

This byte value depends on when Registration message is being sent:

  • if it is being sent after Parking Status message indicating this occupancy session was sent the value will be 0

  • if it is being sent before parking status change message for this Occupancy session was sent the first byte will be equal to such in Parking Status message and Parking Status change message won’t be sent(so in this case SDI tag registration message combines registration data and Parking Status message in one message to decrease delay in getting Registration message)

1

SDI tag serial address, bits 31..24

2

SDI tag serial address, bits 23..16

3

SDI tag serial address, bits 15..8

4

SDI tag serial address, bits 7..0

4.2.5 Debug messages


The Debug messages use port 6 and they are always unconfirmed. By default, these messages are enabled and have no repetitions, but they may be disabled or increased by the number of repetitions used (see downlink messages). These messages do not have a fixed length as their payload depends on the type of debug message.

The first 2 bytes of the payload represent the debug code in Big Endian format, and the rest of the payload(if any) contains additional parameters which meaning depend on the exact debug code.

Debug code

Meaning

Additional parameters

404 (0x194)

Calibration has been competed. The calibration could have been an initial calibration after activation or requested by user calibration. Automatic calibration (adjustment to changing environment) does not cause this message to be sent.

1 byte

899 (0x383)

Invalid user request. The downlink command has not been recognised or provided configuration cannot be used.

None

805 (0x325)

No change in configuration. Provided configuration parameters are equal to the current parameters in use

None

4.2.6 Configuration feedback message

...


DataRate configuration uses port 52. There are different configurations for data rate when the sensor assumes that it is occupied and when it assumes that it is vacant. The default value is DR2 (0x02) for the occupied state and DR3 (0x03) for the vacant state. The selected configuration is persistent unless overwritten in the join procedure. Higher DataRates increases the battery lifetime of the sensor but may reduce the reliability of the reception of messages by the Gateway. This is especially the case for unconfirmed messages. The data rate for “vacant” state must be not less than for “occupied” state.

Byte

Bits

Name

Default value

0

2..0

DataRate configuration for “vacant” state

3 (DR3)

3

Reserved

6..4

DataRate configuration for “occupied” state. This data rate is also used during first 2 attempts in Join cycly sequence.

2 (DR2)

7

Reserved

DataRate configuration value

DataRate(Spreading Factor) EU868

0

DR0 (SF12BW125)

1

DR1 (SF11BW125)

2

DR2 (SF10BW125)

3

DR3 (SF9BW125)

4

DR4 (SF8BW125)

5

DR5 (SF7BW125)

DataRate configuration value

DataRate(Spreading Factor) US915

0

DR0 (SF10BW125)

1

DR1 (SF9BW125)

2

DR2 (SF8BW125)

3

DR3 (SF7BW125)

4

DR4 (SF8BW500)

4.3.3 Heartbeat frequency


Heartbeat frequency uses port 53. The default value is 23 what is equal to 24 hours. The configuration selected is persistent.

Byte

Name

0

Heartbeat interval configuration

Interval = (value+1)hours

4.3.4 Debug configuration

...


Heartbeat NACK limit configuration uses port 72 and is used to specify how many heartbeat messages may be unacknowledged without initiating re-join procedure. The selected configuration is persistent. The default value is 3. 15 (0xF) and it is a special value that disables re-join functionality completely.

Byte

Bits

Name

Default value

0

3..0

Heartbeat NACK limit

3

7..4

Reserved

0


4.3.6 Short stay filtration configuration


Short stay filtration can be used to optimize battery power consumption and decrease airtime (to decrease gateway utilization and to enable more sensors to be served by each gateway). It uses port 73 and the selected configuration is persistent.

Byte

Bits

Name

Default value

0

7..0

Expected maximum count of sessions per day. Value 0 is special and means that adaptive filtration is disabled.

35

1

7..0

Minimal occupation duration. The value of delay between occupation detection and Parking Status message transmission is DELAY = value * 10s. The delay before transmission can be different due to LoRaWAN duty cycle restrictions.

0

4.3.7 Full configuration

The full configuration uses port 70 and is used to configure all parameters in one message.

Byte

Bits

Name

Default value

0

2..0

Parking status confirmable configuration (4.3.1 )

0

3

Reserved

0

6..4

Debug configuration (4.3.4)

1

7

Reserved

0

1

2..0

DataRate configuration for “vacant” state (4.3.2)

3 (DR3)

3

Reserved

0

6..4

DataRate configuration for “occupied” state (4.3.2)

2 (DR2)

7

Reserved

0

2

3..0

Heartbeat NACK limit (4.5.2)

3

7..4

Reserved

0

3

7..0

Heartbeat frequency (4.3.3)

23 (0x17)

4

7..0

Short stay filtration - expected maximum count of sessions per day (4.3.6)

35 (0x23)

5

7..0

Short stay filtration - minimal occupation duration(4.3.6)

0

If you append 1 more byte equal to AA to this message, you will also be sent a Configuration feedback message as a way to acknowledge if the configuration was accepted.

...