Monokot Server 1.x
  • What is Monokot Server?
  • Quickstart
  • 🐸Basics
    • Supported OS and Hardware
    • Installation
    • Licensing
    • OPC UA
      • UA TCP Endpoint
      • UA Settings
      • Client Certificates
      • Aliases
      • Access to Object Settings
      • Troubleshooting
    • Security Certififcate
    • Users & Roles
    • Administrator GUI
      • Event Log
      • Users in Monokot Server Administrator
      • Roles in Monokot Server Administrator
    • Startup Parameters
  • 🦊Tags & Devices
    • Devices
      • Diagnostics
      • Devices in the Monokot Server Administrator
    • Tags
      • Parameters
      • Change Trigger
      • Tags in Monokot Server Administrator
        • Go Online
        • Group Action
        • Import & Export
    • Modbus Connectivity
      • Parameters
      • Addressing
      • Diagnostics
    • Siemens Connectivity
      • Parameters
      • Addressing
      • Access to DBs area in S7-1200/S7-1500
    • IEC 60870-5-104 Connectivity
      • Parameters
      • Addressing
      • Time Conversion
      • Diagnostics and Commands
    • OPC UA Connectivity
      • Parameters
      • Addressing
      • Diagnostics
      • How to: Importing OPC UA items
      • How to: Pulling Security Certificate
    • InfluxDB Connectivity (Connector)
      • Parameters
      • Addressing
      • Query Result and Data Mapping
      • Diagnostics
      • How to: Configure for InfluxDB 2.x
    • SNMP Connectivity
      • Parameters
      • Addressing
      • UDP Considerations
  • 🐺Time Series & Stores
    • Stores
      • Backlog
      • Diagnostics
      • Stores in Monokot Server Administrator
    • Time Series
      • Parameters
      • Deadband
      • Sampling
      • Last Sample Repeat
      • Time Series in Monokot Server Administrator
        • Group Action
        • Import & Export
    • InfluxDB Connectivity (Store)
      • Parameters
      • Addressing
      • Data Structure
      • About Metadata
      • Diagnostics
      • How to: Configure for InfluxDB 2.x
    • PostgreSQL Connectivity
      • Parameters
      • Addressing
      • Database Design
      • Data Compression
    • REST Connectivity
      • Parameters
      • Addressing
      • Message Script
      • RestRequestMessage
      • DataContext
      • TimeSeries
  • 🐻Scripts
    • Overview
    • Expression
      • Parameters
      • Import & Export
      • Go Online
    • Programming Examples
      • How to: Calculate Arithmetic Mean
      • How to: DoNothing
      • How to: Writing to Tag
      • How to: Inverting Bits
      • How to: Execute SQL
      • How to: Run Ping
      • How to: Do Simulation
      • How to: String Formatting
      • How to: OPC UA Method
      • How to: Initialize Device Settings from File
    • API
      • Bundle
      • BundlePair
      • Context
      • DataMap
      • DataMapPair
      • DataTriggerInfo
      • Expression
      • MosCrypto
      • MosDirectories
      • MosFiles
      • MosOdbc
      • MosOdbcReader
      • MosProcess
      • MosProcessExecuteResult
      • MosText
      • MosUtils
      • ValueState
Powered by GitBook
On this page
  1. Time Series & Stores
  2. REST Connectivity

Message Script

PreviousAddressingNextRestRequestMessage

Last updated 2 years ago

The message script allows to dynamically generate an HTTP request for sending time series to the target URL. The script uses JavaScript with the support for all built-in objects and functions of ECMAScript 5 specification (read more about it ). As a result, the script should return a RestRequestMessage object. The object is a prototype of the generated HTTP request and should contain all necessary message headers and body. Detailed description of the object can be found .

In order to access the time series data ready to be sent, the dataContext object is used. It provides access to an array of time series data. The object provides access to the secret string, and objects. A detailed description of dataContext can be found .

The following example shows a script used for inserting data into InfluxDB, which marks the data with an additional ts_type tag during generation.

var message = new RestRequestMessage();
var body = '';
var firstLine = true;
var ts_type = 'misc'; // Declare a variable for the ts_type tag

// Process the ready-to-publish time series
for (var i = 0; i < dataContext.series.length; i++)
{
	var ts = dataContext.series[i];

	// Determine the value of the ts_type tag
	// based on the path of the time series
	if (ts.path.includes('Power'))
		ts_type = 'power';
	else if (ts.path.includes('Alarms'))
		ts_type = 'alarm';
	else if (ts.path.includes('Fuel'))
		ts_type = 'fuel';

	// Process the samples of the i-th time series
	for (var j = 0; j < ts.samples.length; j++)
	{
		var sample = ts.samples[j];        
		
		if (!firstLine)
			body += '\n'; // If at least one line was added, insert a line break
           
		// Generate a string like this:
		// rest_measures,ts_path=Plant.Generator1.Power full.kWh value=280.87124,status=0,ts_type='power' 1591172295193
		body += 'rest_measures,ts_path=' + ts.path
            + ' value=' + sample.value.toFixed(5)
            + ',status=' + sample.status
            + ', ts_type=' + ts_type
            + ' ' + sample.time.getTime();

            firstLine = false;
	}
}

// Specifying the final string as the HTTP request body
message.body = body;
return message;

When publishing data to various cloud services, cryptographic and text functions may be useful. Access to them is provided by and objects.

🐺
here
here
TimeSeries
ValueState
here
MosCrypto
MosText