13.4.2. Receive Format

A receive format consists of 4 parts:

  1. A sample input message: a complete JSON message payload typical of the messages that the device will produce. If a device can produce different amounts of content in its messages, this sample should contain the maximum message content that the device will produce. This is used to test the parser script, and to generate the message schema if necessary.

  2. A JSON message schema: the JSON schema that described the messages that the device will produce. If the device manufacturer provides a schema, enter it here. If not, you can enter a sample message and press the “Generate Schema” button to create a reasonable schema that describes that message. You may need to edit the schema after generation to add missing fields or to determine which fields are required vs. optional.

  3. An initialization script: a script that is run once when the first message using this schema is received for any topic. That is, it is run once, not once per topic. This provides an opportunity to create functions that will be used in the parser script, or to create a function that will run once per topic. If the device is generating data at high speed, place as much of your code here as possible to minimize the CPU load when parsing subsequent messages from the device. The initialization script can be empty.

  4. A parser script: a script that is run for every message that matches the schema that is received from any MQTT topic. Use this script to extract data from the message and to write data point values to the DataHub data engine. Once this information is in a data point it can be used by any other connected client, regardless of protocol (e.g., OPC, DDE, etc.). The minimum parser script consists of a single line:

    app.ProcessJson();

13.4.2.1. Testing a Receive Format

Once you have supplied the sample input, schema and scripts, press the “Test” button to submit the sample message as if it had been received via MQTT. The sample message will be compared to the schema to ensure that they match, and then the initialization script will run, followed by the parser script. Any debug, log, and error messages will be displayed in the test output panel.

If the script would have written data points to the DataHub data engine, a line will be added to the test output to indicate that a point would have been updated. No actual changes will be made to the data points when running a test.

If a script attempts to read a data point, the test execution will supply a synthetic numeric value instead of reading a point from the data engine. If a point does not exist in the data engine, the test execution will synthesize a value for it as if it had existed.