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 payload in real-time, allowing the conversion of a value to the desired unit. For example, if your data contains a temperature in F, you can use the parser to convert it into C before inserting the data into the Device.
You can learn about the differences between Payload Parser and Analysis.
TagoIO can run up to two parsers: one that is defined by the Connector (added during the creation of the device) and your own parser (optional).
The parsers are executed in sequence. First the one from the Connector, then your parser.
The connector type is defined based on your selection from the list of devices (Add Device step). It contains the script necessary to work with that device.
The script contained inside the parser from the Connector is not visible.
The payload parser is automatically triggered every time the device sends data to TagoIO (no need to setup anything). Your payload parser is the first step that gets triggered before saving data in the Device's data storage, so if your code has an error it will be returned directly to the device HTTP post response.
There are some concepts about global variables and context that you may want to learn.
For this example, let's connect a toaster to Tago.
A toaster could send data to TagoIO when your bread is toasted in the following format:
The value above could represent XX YYY ZZ. Where:
Values | Representation |
---|---|
XX | 00 - Interrupted, 01 - Successful |
YYY | Temperature in Fahrenheit |
ZZ | Error code or 00 - No error |
That value is good enough for machines or engineers, but for humans, it doesn't mean anything and also it's not optimized for the Tago Dashboard. Therefore, we need to parse this payload.
Let's code the Payload Parser to transform that payload into real variables. First, click on your Device and go to the Payload Parser tab.
On the Payload Parser tab you will see the code editor. Then, you can write the following code:
Save, and you are ready. Now, every time the toaster sends those variables, the parser will transform it in real variables, and you can use them to build Dashboard, Analysis, or Action.
Learn more about Building your own parser function.