Flexs Q5M

Flexs Q5M Scripting Reference

Flexs Q5 with modular IO cards

Reference by category

Language & Built-in Types

The mJS scripting language, and the methods carried by strings, numbers and arrays.

System & Environment

Script lifecycle, timing, device status and runtime configuration.

Data Logging & Storage

Recording measurements to the data logger, the memory card and non-volatile memory.

Networking

HTTP, UDP and MQTT communication with servers, brokers and other devices.

Industrial Protocols

Modbus, EtherNet/IP, CAN bus and RS-485 serial connectivity to PLCs and instruments.

Binary Data & Encoding

Packing, parsing and converting binary buffers, JSON and strings.

Math & Utilities

Standard math library plus embedded extensions like value scaling and hardware random numbers.

  • Math — Standard JavaScript Math library plus embedded extensions: Math.map() scaling and a hardware random number generator.

Alarms & Events

Alarm condition evaluation, grouping, acknowledgement and structured event logging.

Example scripts

Uptime

Read the device uptime in seconds with now().

System Status

Read supply voltage, device identity, firmware versions and measurement queue level with __status().

Memory Card & Date/Time

Sets the clock UTC offset, appends timestamped lines to a log file on the memory card, and prints the full datetime() object.

JSON Web Client

Reads JSON from external web servers and from another Q5 running the JSON Web Server example — POSTing a payload, checking err/code, and par…

JSON Web Server

Turns the script into a JSON REST server. Access it in a browser at http://<Q5 IP/app/abc.

JSON Send Measurements to Server

Streams JSON measurements to a server by POSTing on an interval, with upload error handling. The server can reply with commands (e.g. relay …

UDP Packet Transmission, SYSLOG

Streams JSON packets to a UDP/syslog target once per second.

MQTT Publish / Subscribe

Publishes telemetry and subscribes to command topics with a callback. Reconnects automatically by calling mqtt.connect() each loop (code 207…

Variable Measurement Interval

Adapts the measurement and upload intervals based on how full the measurement queue is (__status().mqueue), allowing more measurements to be…

AES256 Encryption / Decryption

Derives an AES-256 key from a passphrase with bin.sha256(), encrypts a JSON payload, decrypts it and validates the checksum.

EtherNet/IP Read

Connects to an Allen-Bradley style PLC over EtherNet/IP, reads four floats from file F103, parses them with the binary reader (with unit co…

Modbus TCP Data Table From Logic

Creates a Modbus slave register table backed by a bin buffer that the script updates and remote Modbus TCP clients can read and write. Inclu…

Modbus TCP Multiple Registers READ / WRITE

Connects to a Modbus TCP slave, reads 30 registers from a weather station (parsing mixed U32/S32 values with scaling), and writes multiple r…

Alarm Conditions

Registers a critical fault with a 5-second trigger delay using alm.e(), prints its live value each loop, and shows the group/summary queries…

Binary Packing, Bits & Hex

Round-trips data through the bin conversion functions: packing a bit array to bytes with "RBITS", converting between binary and hex text wit…

Structured Event Logging

The extended five-argument form of log(): title, description, a numeric type for grouping, a priority, and an attached value — particularly …

UDP Server / Listener

Listens for AES-256 encrypted JSON packets on UDP port 9000 with udp.handle() — only a single UDP listener is supported — and merges the rec…

EtherNet/IP Server (PLC Handler)

Answers EtherNet/IP requests from a PLC with eip.handle(): write requests unpack a status word into individual io flags using bit masks, and…

Non-Volatile Setpoint Storage

Persists operator setpoints and a users table in battery-backed memory with nv.get()/nv.set() — merging saved values over code defaults so …

CAN Bus Transmit & Receive

Initialises the CAN bus at 125 kbps, prints every received frame from the can.listen() callback, and transmits a test frame once per second …

Serial Port: Encrypted Device-to-Device

Sends AES-256 encrypted, checksummed measurements between devices over RS-485: objects are serialised with string(), encrypted with bin.enc…

Serial Port: Plain Text

Minimal RS-485 usage: initialise the port, print every carriage-return delimited message that arrives, and transmit a text line once per se…

Serial Modbus (RS-485)

Polls a Modbus RTU slave directly over the RS-485 port: initialise the port with serial.init(), then use modbus.read() with the matching po…

SD Card Configuration File

Demonstrates storing a JSON configuration file with setpoints etc to a sd card.