Payload Parser - Context & global variables

Payload Parser - Context & global variables

If you are going to create your own parser, you need to understand how context works.

When you start writing your own Payload Parser, you can use certain globals variables in your code. Think of these global variables as variables that you can access anywhere without actually creating them, like the module keyword or the process keyword in Node.js. 

These global variables can vary from simple objects to complex functions or arrays. To see a list of the global variables available, you can always check the Payload Parser tab in the device details. 

Payload parser context
Description
payload*Content of the message that was sent. It usually is an Array of data or string.

At the end of the parser, the payload content is added to your device.
deviceDevice information containing configuration parameters, tags and device ID, etc.
raw_payloadPayload sent in the original request, without changes of any parser. Useful when you want to access the data before it has been changed by a Network parser.
dayjs**Day.js library
loraPacket**
Lora Packet library
console.log**Show a info message in the Live Inspector.
console.debug**Show a debug message in the Live Inspector.
console.error**Show an error message in the Live Inspector.


* This variable must be an Array of TagoIO data when the code ends.
** These are functions available to be used in the Payload Parser.

The most important variable is the payload variable. This variable is always available anywhere on the code. It is an array with objects in the TagoIO format and with it you can edit, remove or even add more variables as you wish.

The content of the payload variable will be sent to your device at the end of the parser.

Learn how to build your own parser function.


    • Related Articles

    • Payload Parser Troubleshooting

      When using the Payload Parser on TagoIO, you might run into some common problems that stop the parser from decoding your device data correctly. This means the data won't be saved on TagoIO. These problems are usually related to mistakes in how the ...
    • Payload Parser

      The Payload Parser handles the raw payload sent by the devices in order to extract the measured variables. For example, it can be used to transform an HEX payload sent by a device into temperature and battery levels. You can also use it to handle the ...
    • Filtering Out Variables with Parser Code

      When your device sends data from a sensor to TagoIO, a parser code may be added to your device (located in the 'Payload Parser' tab) to extract and create the variables in the Device's data storage using TagoIO format. If you want to save space in ...
    • Parser vs. Analysis Comparison

      The Payload Parser was created to handle raw payload sent by the devices in order to extract the measured variables or execute simple operations. Analysis is much more powerful, including access to Devices and external services. Also, there is a cost ...
    • Building your own parser

      In this tutorial, you will learn how to convert (parse) a raw payload sent by a device into actual measurable variables.  Data flow structure You can create parses for devices that weren't found in our list of Devices, so that you had to use a ...