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

victronenergy-modbustcp-api

v1.0.0

Published

victronenergy-modbustcp-api

Downloads

197

Readme

victronenergy-modbustcp-api: helps to read and write Victron Energy GX Modbus-TCP Registers

npm-version npm-week-downloads

The library helps to read and write Victron Energy GX Modbus-TCP Registers
Please read Documentation » ccgx » GX Modbus-TCP Manual before starting.
The library is designed for the package 'conextra'.

Table of contents

Installation

npm install victronenergy-modbustcp-api

Usage example: console-victronenergy-modbustcp-api

var modbus_api = require("victronenergy-modbustcp-api");
var util = require('util');
var modbusPort = 502;
var modbusHostname = "192.168.8.106";

// request: `/$modbus/{UnitID}?${RegisterAddress}=${setValue}`
var requests = [

    // /Ac/Consumption/L1+L2+L3/Power
    `/$modbus/100?817+818+819`
];

requests.forEach(function (request) {

    requestModbusTCP(
        modbusHostname,
        modbusPort,
        request.substring(9),
        function (err, result) {

            if (err) { console.error(err); }
            console.log(util.inspect(result, { showHidden: false, depth: null, colors: true }));
        }
    );
});

Result:

result

Usage example: simple-modbus-api

'use strict';

var requestModbusTCP = require("victronenergy-modbustcp-api");
var server = require("tiny-https-server");
var options = require("config-sets");
options.init({
    modbusPort: 502,
    modbusHostname: "192.168.8.106"
});

server.on("request", function (req, res, next) {

    if (req.url.startsWith("/$modbus/")) {

        requestModbusTCP(
            options.modbusHostname,
            options.modbusPort,
            req.url.substring(9),
            function (err, result) {

                res.writeHead(200, { "Content-Type": "text/json" });
                res.write(JSON.stringify(err || result));
                res.end();
            }
        );
    }
    else
        next();
});


var port = options.tiny_https_server.port;
if (port === 80 || port === 443) { port = ""; }
else { port = ":" + port; }

/**
 * `http://localhost/$modbus/${UnitID}?${Address}=${setValue}`
 * example http://localhost/$modbus/228?33=4
 * see info: https://www.victronenergy.com/live/ccgx:modbustcp_faq
 */
var urls = [

    // /Ac/Consumption/L1+L2+L3/Power
    `http://localhost${port}/$modbus/100?817+818+819`,

    //// /Ac/Grid/L1+L2+L3/Power
    //`http://localhost${port}/$modbus/100?820+821+822`,

    //// /Dc/Battery/Power
    //`http://localhost${port}/$modbus/100?842`,

    //// /Dc/Battery/Temperature
    //`http://localhost${port}/$modbus/228?61`,

    //// /Dc/Battery/Soc
    //`http://localhost${port}/$modbus/100?843`,

    //// /Hub4/Sustain
    //`http://localhost${port}/$modbus/228?73`,

    //// //Serial
    //`http://localhost${port}/$modbus/100?800`,

    //// //Serial
    //`http://localhost${port}/$modbus/30?2609`,

    //// /Settings/Cgwacs/AcPowerSetPoint
    //`http://localhost${port}/$modbus/100?2700`,

    //// /Settings/Cgwacs/MaxChargePercentage
    //`http://localhost${port}/$modbus/100?2701`,

    //// /Settings/Cgwacs/MaxDischargePercentage
    //`http://localhost${port}/$modbus/100?2702`,

    //// /Settings/Cgwacs/AcPowerSetPoint
    //`http://localhost${port}/$modbus/100?2703`,

    //// /Settings/Cgwacs/Hub4Mode
    //`http://localhost${port}/$modbus/100?2902`,

    //// /State
    //`http://localhost${port}/$modbus/228?31`,

    //// /Switch Position
    //`http://localhost${port}/$modbus/228?33=4`,

    //// /Ac/L1|L2|L3/Energy/Forward|Reverse
    //`http://localhost${port}/$modbus/30?2603+2604+2605+2606+2607+2608`,

    //// /Ac/L1|L2|L3/Voltage|Current
    //`http://localhost${port}/$modbus/30?2616+2617+2618+2619+2620+2621`,

    //// /gps
    //`http://localhost${port}/$modbus/100?2800+2802+2804+2805+2806+2807+2808`,
];

// Opens the URLs in the browser.
while (urls.length) {
    require("browse-url")(urls.shift());
}

Result:

result

'victronenergy-modbustcp-api' Reference


/**
 * 
 * Request Modbus TCP 
 * 
 * request: `{UnitID}?${RegisterAddress}=${setValue}`
 * example: requestModbusTCP("192.168.8.106", 502, "100?817+818+819", (err, result) => { ... })
 * see info: https://www.victronenergy.com/live/ccgx:modbustcp_faq
 * 
 * @param {string} host
 * @param {number} port example: 502
 * @param {string} request `{UnitID}?${RegisterAddress}=${setValue}`
 *  example: "100?817+818+819"
 * @param {(err:any, result:object)=>void} callback
 */
function requestModbusTCP(host, port, request, callback) 

License

The MIT License MIT

The MIT License (MIT)

Copyright (c) 2023 Manuel Lõhmus <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.