npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iotedgemodbusmqtt

v1.1.0

Published

IoT Edge Router/Controller communicates locally with modbus device and interfaces to the cloud via mqtt

Downloads

4

Readme

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!