How to script custom parsing logic for message payload?

Using plugins with PVM code to instruct how to parse payload in the device messages.

The "msg-pvm-code" plugin type is used to transform message parameters with custom logic using PVM code. Comparing to msg-expression plugin type pvm code is much more powerful and in general within a single code block it is possible to combine functionality of multiple plugin types. With pvm code it is possible to perform any kind of modification of message before it is registered in the device storage:

  • Conditionally convert parameter values using custom multipliers.
  • Parse custom textual or hexadecimal binary data into meaningful set of new parameters.
  • Delete some parameters.
  • Add to the message values from the device telemetry fields.
  • Add to the message values from current device settings cache.
  • Add to the message values from device metadata.

It is possible to use conditional logic, variables, loops in pvm code. Basically it is a piece of custom script that is run on flespi side during reception of device message where you can implement any kind of message parameters conversion. We suggest to read PVM basics guide to get acquainted with the structure and capabilities of PVM script. To develop and test PVM code we usually use PVM plugin sandbox.

If you will encounter difficulties writing the code for your plugin do not hesitate to contact our team in the chat and we will help you with it. Also you may use our AI services to write the code for you either directly asking AI assistant in the chat or by using special PVM generating tool. You can find PVM generating tool in the top-right corner of your account, under Tools section.

How to create pvm-code plugin

Click on the "+" button in the Telematics Hub -> Plugins section to create a new plugin:

flespi panel telematics hub plugins

Let's define a new device plugin that will remove the position parameters (as GDPR regulations require) if the private.mode parameter is set to true (boolean value). private.mode parameter can be defined by another plugin if needed, for example using the "item-fields" plugin. In that case just set higher priority to parameter setting plugin to ensure the private.mode parameter is already in place before our "msg-pvm-code" applies.

add plugin with pvm code

Translation: if the message contains private.mode parameter and it is set to true, delete the following position.* parameters.

Then we need to assign this plugin to the right devices. Go to the Plugins tab for the required device and click the "+" button:

assign plugin with pvm code

And then you should be able to see that position.* parameters are no longer present in the new device messages when the private.mode is true. Go to the Logs & Messages tab for the given device to check:

check that plugin with pvm code applied

Done.

Examples

Sandbox

You are welcome to use this open source pvm plugin sandbox to experiment with plugin code.

Change log

Subscribe to the PVM code plugin change log to stay in sync with any updates.

More plugin types

Find a comprehensive list of available plugins types here.


See also
Using a plugin to convert value with a stepwise linear function