0.3.0 • Published 1 year ago

@gapit/node-red-contrib-gapit-modbus v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

node-red-contrib-gapit-modbus

The gapit-modbus Node-RED node reads modbus register and decode modbus registers acording to data types specified in the Gapit code. The Gapit code structures and names data, preparing it for insertion into a database. The complementary gapit-results-to-influx-batch node transforms the output of this node to the format required by the influx batch node (from node-red-contrib-influxdb).

So to read a standard set of data and insert it into InfluxDB, a flow like this is all you need:

Example Flow

Here's a fragment of a Gapit code:

{
  "objects": [
    {
      "group_name": "EB Current Bar",
      "read_priority": 0,
      "address_type": "dec",
      "register_type": "holding",
      "group": [
        {
          "address": 8200,
          "description": "Breaker 1",
          "scaling_factor": 1,
          "unit": "A",
          "byte_type": "SINT16"
        },
        {
          "address": 8201,
          "description": "Breaker 2",
          "scaling_factor": 0.1,
          "unit": "A",
          "byte_type": "SINT32"
        }
      ]
    }
  ]
}

This would get inserted into a InfluxDB measurement called "EB Current Bar" (from the group_name field), with fields called "Breaker 1" and "Breaker 2" (from the description field).

The output of gapit-modbus, which is parsed by gapit-results-to-influx-batch, is msg.gapit_results. This has the same structure as the Gapit code, except with .value added for each address.

Other destinations/databases?

If you want to insert the data into a different database, you can parse the msg.gapit_results structure, and transform it into the required format.

gapit-results-to-influx-batch node

The gapit-results-to-influx-batch node is packaged as a separate module, node-red-contrib-gapit-results, which is automatically installed with this module. It is a packaged as a separate module to enable sharing with other nodes which yield results in the same msg.gapit_results structure.

The node-red-contrib-gapit-results module may be expanded with new nodes in the future.

Installation

Install from the Node-RED interface

Install using Manage palette -> Install.

You need to refresh your browser for the gapit-results-to-influx-batch node to be available in the node palette. If you are running Node-RED 1.2 or older, you will need to restart Node-RED for it to be visible.

If you are using an ancient version of NPM, you will need to manually install node-red-contrib-gapit-results.

Install using the command line

Run the following command in your Node-RED user directory - typically ~/.node-red

npm install @gapit/node-red-contrib-gapit-modbus

and then restart Node-RED.

Usage

Example flow

This is the JSON for the flow pictured above.

[
  {
    "id": "4baf4f334b779050",
    "type": "tab",
    "label": "gapit modbus",
    "disabled": false,
    "info": ""
  },
  {
    "id": "738d78ca6f672b59",
    "type": "influxdb batch",
    "z": "4baf4f334b779050",
    "influxdb": "99e22e92c3be98de",
    "precision": "",
    "retentionPolicy": "",
    "name": "",
    "database": "modbus",
    "precisionV18FluxV20": "ms",
    "retentionPolicyV18Flux": "",
    "org": "organisation",
    "bucket": "bucket",
    "x": 1240,
    "y": 280,
    "wires": []
  },
  {
    "id": "f1a98ce54346cd03",
    "type": "gapit-modbus",
    "z": "4baf4f334b779050",
    "name": "",
    "host": "nodered",
    "port": "502",
    "deviceName": "123-123-123",
    "deviceNameDbTag": "uid",
    "unitId": "1",
    "gapitCode": "{\"objects\":[{\"group_name\":\"EB Current Bar\",\"read_priority\":0,\"address_type\":\"dec\",\"register_type\":\"holding\",\"group\":[{\"address\":8200,\"description\":\"Breaker 1\",\"scaling_factor\":1,\"unit\":\"A\",\"byte_type\":\"SINT16\"},{\"address\":8201,\"description\":\"Breaker 2\",\"scaling_factor\":0.1,\"unit\":\"A\",\"byte_type\":\"SINT32\"}]}]}",
    "customTags": "{\"foo\":\"test\",\"baar\":10}",
    "scalingType": "general",
    "x": 420,
    "y": 280,
    "wires": [["d32ef3b037c73222", "3438922f9c6b25ca"]]
  },
  {
    "id": "c80bd9f665e8a5b9",
    "type": "debug",
    "z": "4baf4f334b779050",
    "name": "",
    "active": false,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 1010,
    "y": 220,
    "wires": []
  },
  {
    "id": "d32ef3b037c73222",
    "type": "debug",
    "z": "4baf4f334b779050",
    "name": "",
    "active": false,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "true",
    "targetType": "full",
    "statusVal": "",
    "statusType": "auto",
    "x": 590,
    "y": 220,
    "wires": []
  },
  {
    "id": "3438922f9c6b25ca",
    "type": "gapit-results-to-influx-batch",
    "z": "4baf4f334b779050",
    "use_timestamp_from_msg": false,
    "timestamp_property": "ts",
    "name": "",
    "x": 760,
    "y": 280,
    "wires": [["738d78ca6f672b59", "c80bd9f665e8a5b9"]]
  },
  {
    "id": "28060540b4b95271",
    "type": "inject",
    "z": "4baf4f334b779050",
    "name": "",
    "props": [],
    "repeat": "1",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "x": 170,
    "y": 280,
    "wires": [["f1a98ce54346cd03"]]
  },
  {
    "id": "99e22e92c3be98de",
    "type": "influxdb",
    "hostname": "127.0.0.1",
    "port": "8086",
    "protocol": "http",
    "database": "database",
    "name": "modbus-test",
    "usetls": false,
    "tls": "8b3094b6.5fc088",
    "influxdbVersion": "1.8-flux",
    "url": "http://influx:8086",
    "rejectUnauthorized": false
  },
  {
    "id": "8b3094b6.5fc088",
    "type": "tls-config",
    "name": "",
    "cert": "",
    "key": "",
    "ca": "",
    "certname": "GapitBroker.crt",
    "keyname": "",
    "caname": "",
    "servername": "",
    "verifyservercert": false
  }
]

Supported data types

The Gapit-modbus supports these data types.

ParameterDescription
BIT1Decodes a single bit register to integer value
BIT16Decodes a single bit register to integer value depending on witch bit is selected in the gapit code
BIT16-SWDecodes a single bit SW register to integer value depending on witch bit is selected in the gapit code
BIT32Decodes a single bit register to integer value depending on witch bit is selected in the gapit code
BIT32-SWDecodes a single bit SW register to integer value depending on witch bit is selected in the gapit code
UINT8Decodes a 8 bit register to unsigned integer value
UINT16Decodes a 16 bit register to unsigned integer value
UINT32Decodes a 32 bit register to unsigned integer value
UINT64Decodes a 16 bit register to unsigned integer value
SINT16Decodes a 16 bit register to signed integer value
SINT32Decodes a 32 bit register to signed integer value
SINT64Decodes a 16 bit register to signed integer value
FLOAT32Decodes a 32 bit register to floating point value
FLOAT64Decodes a 64 bit register to floating point value
DUMMY16Skipping a 16 bit register
DUMMY32Skipping a 32 bit register
DUMMY64Skipping a 64 bit register
HEXDecodes a register depending on length specified in the gapit code to a hex decimal value
ASCIIDecodes a register depending on length specified in the gapit code to a ASCII value
ASCII-SWDecodes a SW register depending on length specified in the gapit code to a ASCII value

Gapit codes

A library of ready-made Gapit codes is forthcoming.

gapit-modbus

The node needs to be configured with, at a minimum:

  • MODBUS config (IP address, port, Unit ID etc.)
  • Gapit code
ParameterDescription
NameNode name
HostModbus host
PortModbus port
Device nameThe device name database records will be tagged with (e.g. "ups1")
Device name db-tagThe database tag for device name (e.g. "devname")
Unit IDThe ID modbus uses to select which unit to read
Custom tagsExtra tags to add to database records, see below
Gapit codeThe Gapit code JSON
ScalingSpecify scaling type

Custom tags

Add database tags, formatted as JSON with tag_name: value.

Example:

{
  "floor": "1",
  "room": "101"
}

gapit-results-to-influx-batch

To use a Node-RED timestamp with influxdb (enabled by default), add a property containing a timestamp in your inject node. The default name is msg.ts.

ParameterDescription
NameNode name
Use timestamp from MessageUse a timestamp injected in the flow (default on)
Timestamp propertyThe msg property to get the timestamp from (default: "ts")

N.B.! Check the InfluxDB time precision

If using timestamps from Node-RED, note that while this works "out-of-the-box" with InfluxDB v2, you will have to set the influx batch node to match the millisecond resolution of Node-RED if you're using InfluxDB v1. You can do this by checking Advanced Query Options on the influx batch node, and then choosing Milliseconds (ms) from the Time Precision popup menu.

0.3.0-beta.2

1 year ago

0.3.0

1 year ago

0.3.0-alpha.2

1 year ago

0.3.0-alpha.3

1 year ago

0.3.0-alpha.4

1 year ago

0.3.0-alpha.5

1 year ago

0.3.0-alpha.0

1 year ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago