A script in Protolinker is a small piece of custom logic that allows you to process or transform data before it is passed along.
While tags hold raw values and links move them between protocols, scripts give you the flexibility to adapt those values to your specific needs.
In short, scripts let you add intelligence to how data is handled inside Protolinker.
Why Scripts Are Useful #
Not all devices and systems use data in the same way. Sometimes you need to:
- Convert units (e.g., Celsius → Fahrenheit).
- Scale values (e.g., raw sensor 253 → 25.3 °C).
- Apply thresholds or limits (e.g., cap a value at 100).
- Filter or clean up noisy data.
- Implement simple logic (e.g., turn a 0/1 input into “OFF/ON”).
Scripts provide the flexibility to do all this without modifying the devices or protocols themselves.
How Scripts Work in Protolinker #
Currently, it is possible to use any scripting language or binaries as a script as long it is supported to your host operating systems and all dependencies are installed, then you just need to select your script file (could be python, bash, JavaScript or even a binary), specify the command your system needs to run it, for example python for python files or sh for bash and so on.
Scripts with Tags #
A script can be attached to a tag so that:
- When the tag receives a value from its protocol, the script transforms that value before storing/applying it.
- When the tag sends data out, the script will have adjusted the value before it leaves, so all links gets the new value.
Example:
Raw Modbus register 40001 = 253 → Script divides by 10 → Tag value = 25.3 °C.
Scripts with Links #
A script can also be applied on a link so that:
- The source tag value is modified while being transmitted to the destination tag.
- This is useful if you want the tag to remain in raw form, but still adapt the data before it reaches another protocol. This means that the other links of this tag will receive the original data and only the specified link will have an adapted data.
Example:
Source tag temperature = 25.3 °C → Link script converts to Fahrenheit → Destination tag sensor/temperature_f = 77.5 °F.
Example Scenarios #
- Unit Conversion: pressure_kpa (from sensor) → script converts to pressure_psi.
- Status Mapping: Tag value 0 → script outputs “STOP”; value 1 → “RUN”.
- Data Filtering: Script smooths rapid fluctuations before sending to MQTT.
