Scripting

Senquip devices have the ability to run user written scripts, allowing extra flexibility. The scripting language is called mJS and is essentially a restricted JavaScript engine. Typical uses include:

Scripting on Senquip devices allows:

  • Decoding and parsing of messages from serial and CAN-bus devices

  • Mathematical manipulation of measured data

  • Controlling connected devices

  • Creating complex alerts that may be dependent on more than one variable

  • Customisation of data payloads to be compatible with third party dashboards

Scripts can be executed in response to a measurement cycle completing, a trigger button being pressed, or based on a recurring timer function.

For more information about writing JavaScript for a Senquip device, please see the Senquip Scripting Guide.

Risks

Warning

The scripting environment is a powerful tool. If incorrectly used the scripting functions may cause the device to malfunction, or even permanently brick the device.

  • The mJS scripting environment provides low level access to the device’s memory and CPU. Running a script on the device is not without risk, some of which include:

  • Permanent filesystem damage rendering the device unable to boot.

  • Malfunction of other functions, such as regular reporting of data to the portal.

  • Memory corruption, causing incorrect reporting of data.

  • Memory leaks, which may present intermittently or after a period of time.

  • Loss of remote control over the device, if your Portal account is compromised.

A good understanding of the environment, language and best practices will help avoid or mitigate these risks.

Access

Scripts can be written and securely downloaded to the device from the Senquip Portal. There are several requirements for access scripting on your device:

  • You must have ADMIN status on the Portal for the device.

  • Your Portal account must be granted SCRIPTING permissions. This can be granted by making a request to support@senquip.com

Once the requirements are met, you can access the scripting page at: https://portal.senquip.com/script/DEVICEID or by pressing the scripting icon on the device dashboard.

Writing and deploying a script

The scripting page on the Senquip Portal allows scripts to be written and downloaded, and custom variables, custom settings, and triggers to be created.

Scripting window on the Senquip Portal

Senquip scripting page

Once written, the user can deploy the script to a remote device by pressing the download button and then the reboot button. To enable error reporting, enable the Send Errors option. If the script terminates unexpectedly, a message will be sent with a description of the reason that the script failed to complete execution.

Enabling error reporting

Feedback on unsuccessful script

Scripts can be saved to a file using the Save button on the scripting page. It is recommended that all scripts are backed up to a secondary storage medium.

Note

Remember to backup your scripts.