1.1.0 • Published 5 years ago

iotedgemodbusmqtt v1.1.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

iotedgemodbusmqtt

https://bitid.co.za

https://blog.bitid.co.za/iotedgemodbusmqtt

Note this edgeRouter has been tested and verified for use on the bitid.co.za IoT platform providing phone app, push notifications and dashboards. This edgeRouter can be used with any mqtt server.

Modbus Registers are read continously and monitored for when they change. When a change is detected, the change is sent via MQTT to the server. Change Modbus Register values remotely via MQTT Monitor and Control via any MQTT client (Nice for Smart Phone use)

config.js

To run the test: Create config.json

{
    "rtuId": 65534,
    "mqttServer": "mqtt://xxx.co.za",
    "mqttPort": 1883,
    "mqttUserName": "xxx",
    "mqttPassword": "xxx",
    "mqttSubscribe": "xxx"
}

Read Commands

Below is an example of commands to load on startup. Note the modbus register of 4354 will be placed into input: AI1. If the value of AI1 changes by more than the cofsSP, the payload will be sent via mqtt. cofs stands for "change of state"

let commands = [
    {
        "index": 0,
        "RTUAddress": 1,
        "functionCode": 3,
        "register": 4354,
        "output": [],
        "input": "AI1",
        "cofsSP": 1,
        "cofsValue": null
    },
    {
        "index": 1,
        "RTUAddress": 1,
        "functionCode": 3,
        "register": 4355,
        "output": [],
        "input": "AI3",
        "cofsSP": 3,
        "cofsValue": null
    }
]

Update Read Commands

Send via MQTT

{
    "txType": "updateCommands",
    "commands": [
        {
            "index": 0,
            "RTUAddress": 1,
            "functionCode": 3,
            "register": 4354,
            "output": [],
            "input": "AI1",
            "cofsSP": 1,
            "cofsValue": null
        },
        {
            "index": 1,
            "RTUAddress": 1,
            "functionCode": 3,
            "register": 4355,
            "output": [],
            "input": "AI3",
            "cofsSP": 3,
            "cofsValue": null
        }
    ]
}

Write Command

{
    "txType": "control",
    "data": {
        "modbusId": 1,
        "modbusRegister": 6,
        "value": 200
    }
}

Status Command

{
    "txType": "statusCommands",
    "data": null
}

Server-Side Payload

{
    "rtuId": 1234,
    "txType": "cofs",         //cofs, fixedTx
    "data": {
                "time": 5875757,
                "date": "2019-10-10 00:00:00",
                "TxFlag": 0,
                "digitalsIn": 0,
                "AI1": 0,
                "AI2": 0,
                "AI3": 0,
                "AI4": 0,
                "AIExt1": 0,
                "AIExt2": 0,
                "AIExt3": 0,
                "AIExt4": 0,
                "AIExt5": 0,
                "AIExt6": 0,
                "AIExt7": 0,
                "AIExt8": 0,
                "CI1": 0,
                "CI2": 0,
                "CI3": 0,
                "CI4": 0,
                "CI5": 0,
                "CI6": 0,
                "CI7": 0,
                "CI8": 0,
                "BATT": 0,
                "SIG": 0
            } 
}

Example - How to use this package

'use strict'

let edgeRouter = require('iotedgemodbusmqtt')
let config = require('./config.json')


let commands = [
    {
        index: 0,
        RTUAddress: 1,
        functionCode: 3,
        register: 4354,
        output: [],
        input: "AI1",
        cofsSP: 1,
        cofsValue: null
    },
    {
        index: 1,
        RTUAddress: 1,
        functionCode: 3,
        register: 4355,
        output: [],
        input: "AI3",
        cofsSP: 3,
        cofsValue: null
    }
]

let options = {
    rtuId: config.rtuId,
    commPort: '/dev/ttyUSB0',
    baud: 19200 , 
    commands: commands, 
    mqttServer: config.mqttServer,
    mqttPort: config.mqttPort,
    mqttUserName: config.mqttUserName,
    mqttPassword: config.mqttPassword,
    mqttSubscribe: config.mqttSubscribe, 
    txTimeSP: 10,
    enable232: 'true'
}

edgeRouter.start(options)

Docker Image

https://github.com/shanebowyer/iotedgemodbusmqtt_docker

MODBUS TCP

Currently this module only supports serial communication. I will be adding MODBUS TCP soon!

1.1.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago