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. |
device | Device information containing configuration parameters, tags and device ID, etc. |
raw_payload | Payload 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.