Example - creating data mapping scripts
This chapter provides details on how to write a codec script for an example device, B-Meters LoRaWAN pulse meter that operates with PDUs encoded in Hexa decimal format.
Reference: For more information on LoRa Pulse Meter, refer to https://www.bmeters.com/wp-content/uploads/2020/06/Manual_LORA_PULSE_1.1.pdf
Before writing the script, it is essential to understand the protocols used between the device and the application server. In this example, the PDU structure of the uplink and downlink command messages are as follows:
Command type | Command index | Command data |
---|---|---|
1 Byte | 1 Byte | 0....N Bytes |
Types:
- 0x01 - Set command (to set/write some parameter on device)
- 0x02 - Query command (to query/read some parameter on device)
- 0x03 - Action command (to ask the device to execute/perform some action)
Reference: For a complete list of command index, see page 6 of https://www.bmeters.com/wp-content/uploads/2020/06/Manual_LORA_PULSE_1.1.pdf
Data
The data type and size depends on the command index. For details, refer to page 6 of https://www.bmeters.com/wp-content/uploads/2020/06/Manual_LORA_PULSE_1.1.pdf.
For the codec script, the uplink message from the device requires decoding as per the device protocol. Similarly, messages towards the device must be encoded as per the protocol.
- encode( )
- decode( )
The following is an example of a codec ( ) script:
function LoraPulseCodec() {
this.encode = function (impactRequest) {
// encode the message to be sent to the device
}
this.decode = function (decodeCtx) {
// decode the message received from device
}
}
var codec = new LoraPulseCodec();
(codec);