Git Product home page Git Product logo

node-mbus's Introduction

Hello out there πŸ‘‹

I spent most of my available time, beside family and job, to make IoT easier to use for everyone - using Node.js, TypeScript and JavaScript.

I'm one of the core developers of the smart home automation software ioBroker. Beside working on the central component js-controller I try to maintain over 200 adapters/plugins in the ioBroker Organization and in the Community Adapter Organization together with some other developers. Additionally to this I support the ioBroker project as Project manager for core topics and bigger releases and coordinate the work in the community and communication channels like Forum, Discord and Telegram. With all this work my goal is to deliver best possible quality for the users and community members and make the life easier and more convenient for all ioBroker developers.

One of my current main focus topics is to build, maintain and lead the JavaScript/TypeScript library for the Matter protocol in the official project-chip organization to allow the JavaScript community build devices and controllers for the new Matter smart home standard.

Furthermore I also maintain some own ioBroker adapters and some Libraries to bring IoT protocols into the Node.js world. I always try to develop libraries that are usable by all JS/TS developers out there. E.g. I do maintain projects to interact with Amazon Alexa Devices, Daikin Devices, Daikin Cloud Devices, MBus devices, Meross Devices, Smartmeters and last but not least HomeKit HAP Controller and I also co-maintain and contribute libraries for some other protocols like Coap or Tuya.

If you want to support me, you can:

Apollon77 GitHub stats

node-mbus's People

Contributors

apollon77 avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar greenkeeper[bot] avatar hasanheroglu avatar jkrhb avatar laurin avatar lvogt avatar robertslando avatar samkrew avatar sjlongland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-mbus's Issues

Timeouts of libmbus are too short on some cases

In my project I need longer timeouts in libmbus to work properly.

I can change source of libmbus and compile it and test it but:
how to compile node-mbus (need it in node-red)?

Resolved by myself using node-gyp:
node-gyp install node-gyp configure node-gyp build

Promisify functions

To promisify 'callback functions' we could use something like this:

function promisify(func) {
  return (...args) =>
    new Promise((resolve, reject) => {
      const callback = (err, data) => err ? reject(err) : resolve(data)
      
      func.apply(this, [...args, callback])
    })
}

About what type of promises to use, I see most package go for bluebird promises instead of native promises. We could decide what is better based on this: https://pub.clevertech.biz/native-javascript-promises-vs-bluebird-9e58611be22

Summary: It tells that third party promises are more performant than native but this lib is your so you should decide

Device values not updated

I have an electricity meter and the values are read correctly the first time than are always the same. If I manually rebuild the libmbus library the value is correctly read than I always receive the same response with the same values every time (just timestamps change but values are the same). I think it is a problem related with the library itself.

Check slack channel πŸ˜ƒ

Where is the Unit value coming from?

We're trying to make sense of the Unit field of the data record, which seem to lack consistency. Here are some examples:

  • "Volume (m m^3)"
  • "External temperature (1e-2 deg C)"
  • "Energy (100 Wh)"

I understand that reverse-engineering the field might never get fully accurate, but if feels like it's just a free text field. Having a look at the libmbus library, it looks like pretty structured, but perhaps the Unit value is derived from somewhere else?

Cheers

Cant seem to get the correct value Id info

Hi

Hoping for some help.
I am using your library in a new driver of mine where the mbus device has a lot if value Id's.
But I cant seem to figure out what data it is outputting and how to get to the end of the results.

I am hoping these pictures can help me explain a bit better:
There are the current "clipped" results:
image

But these are the values I was expecting to see:
image

Any assistance would be greatly appreciated.

Another question

Hello again,
Our requirements have changed and I lack both skill and time to develop it. I was wondering if you were up for a short consult gig as you clearly have the skill (but perhaps not the time ;) ).

Should you choose to accept this mission (hopefully not impossible):

It has been decided the parsing and decryption of messages should be done in a cloud application rather than on the IoT device, so we need to submit raw mbus data readings.
The problem is that I still need to parse the data on the device to compare it to the white-list (received from the cloud application).
So.. in short... create a reader that returns the header and the raw data Eg.

{
  "SlaveInformation": {
    "Id": 68024764,
    "Manufacturer": "ELV",
    "Version": 31,
    "ProductName": "",
    "Medium": "Unknown medium (0x1b)",
    "AccessNumber": 82,
    "Status": 0,
    "Signature": 0
  },
"Radata": [0x68, 0x36, 0x36, 0x68, 0x08, 0x01, 0x72, 0x64, 0x47, 0x02, 0x68, 0x96, 0x15, 0x1F, 0x1B, 0x51, 0x00, 0x00, 0x00, 0x0C, 0x78, 0x53, 0x16, 0x00, 0x62, 0x02, 0x75, 0x01, 0x00, 0x01, 0xFD, 0x71, 0x13, 0x2F, 0x2F, 0x02, 0x65, 0xA9, 0x08, 0x42, 0x65, 0xA9, 0x08, 0x02, 0xFD, 0x1B, 0x30, 0x43, 0x0D, 0xFD, 0x0F, 0x05, 0x35, 0x2E, 0x30, 0x2E, 0x33, 0x0F, 0x8B, 0x16];
    
}

I totally understand if you're not up for it, but I though I'd check with you first as you know this stuff :)

Cheers

Get devices primary IDs

Is there a way to know devices primary id? SlaveInformation just contains device secondary ID. I also think that the scan is made throught primary IDs because if 2 devices has the same primary id it doesn't find both but only one

Asyncronous Reading of Secondar Addresses

Firstly, thank you to everyone who has contributed to this library. It has honestly helped me a lot.
I was wondering is it is even a possibility to be able to read mbus devices (through the TCP/IP transparent gateway) in parallel (async) versus reading one after the other (synchronous).

I have multiple sites that have about 750 devices to read on each Gateway. It takes forever. Almost an hour sometimes.
And I read my devices every hour lol. But I want to be able to read in 15-minute intervals, but the driver is bottlenecking the ingestion.

Any ideas or suggestions (If this is even possible)?

TIA Darryl

NPM install error

when i try to npm install i get error:
"MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual St
udio 2005 or 3) add the location of the component to the system path if it is installed elsewhere. [C:\Develop\Converters\z-Protoccol-Test\m-bus-client\node_modu
les\node-mbus\build\binding.sln]".

i try to install windows-build-tools still dont work

Failed to send/receive M-Bus request

Hi (long time no see)
We have been using node-mbus for quite a while without any issues, but I just ran into one that I can't resolve...

Our gateway which is running the node-mbus package is connected to an mbus master (Elvaco) which in turn has four of meters connected to it. We can read two of them, but while reading the others we get this:

mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
mbus_serial_recv_frame: Got 0 byte [remaining 1, len 0]
mbus_serial_send_frame: Dumping M-Bus frame [5 bytes]: 10 7B FD 78 16
mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
mbus_serial_recv_frame: Got 0 byte [remaining 1, len 0]
mbus_sendrecv_request: No M-Bus response frame received.
mbus_serial_send_frame: Dumping M-Bus frame [5 bytes]: 10 7B FD 78 16
mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
mbus_serial_recv_frame: Got 1 byte [remaining 1, len 0]
68
mbus_serial_recv_frame: Attempt to read 2 bytes [len = 1]
mbus_serial_recv_frame: Got 2 byte [remaining 2, len 1]
77 77
mbus_serial_recv_frame: Attempt to read 122 bytes [len = 3]
mbus_serial_recv_frame: Got 59 byte [remaining 122, len 3]
68 08 19 72 25 70 90 68 2D 2C 1D 16 C9 00 00 00 04 13 4F 7F 1D 00 04 93 3C 00 00 00 00 04 22 53 3C 00 00 02 3B B6 00 01 67 18 22 3B 00 00 12 3B BF 04 21 67 18 11 67 1B 01 E7 FF
mbus_serial_recv_frame: Attempt to read 63 bytes [len = 62]
mbus_serial_recv_frame: Got 0 byte [remaining 63, len 62]
mbus_serial_recv_frame: Attempt to read 63 bytes [len = 62]
mbus_serial_recv_frame: Got 0 byte [remaining 63, len 62]
mbus_serial_recv_frame: Attempt to read 63 bytes [len = 62]
mbus_serial_recv_frame: Got 0 byte [remaining 63, len 62]
mbus_serial_recv_frame: Timeout
mbus_sendrecv_request: Received invalid M-Bus response frame.
mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
mbus_serial_recv_frame: Got 0 byte [remaining 1, len 0]
mbus_serial_send_frame: Dumping M-Bus frame [5 bytes]: 10 7B FD 78 16
mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
mbus_serial_recv_frame: Got 0 byte [remaining 1, len 0]
mbus_sendrecv_request: No M-Bus response frame received.
mbus_serial_send_frame: Dumping M-Bus frame [5 bytes]: 10 7B FD 78 16
mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
mbus_serial_recv_frame: Got 1 byte [remaining 1, len 0]
68
mbus_serial_recv_frame: Attempt to read 2 bytes [len = 1]
mbus_serial_recv_frame: Got 2 byte [remaining 2, len 1]
77 77
mbus_serial_recv_frame: Attempt to read 122 bytes [len = 3]
mbus_serial_recv_frame: Got 59 byte [remaining 122, len 3]
68 08 19 72 25 70 90 68 2D 2C 1D 16 CA 00 00 00 04 13 4F 7F 1D 00 04 93 3C 00 00 00 00 04 22 53 3C 00 00 02 3B B6 00 01 67 18 22 3B 00 00 12 3B BF 04 21 67 18 11 67 1B 01 E7 FF
mbus_serial_recv_frame: Attempt to read 63 bytes [len = 62]
mbus_serial_recv_frame: Got 0 byte [remaining 63, len 62]
mbus_serial_recv_frame: Attempt to read 63 bytes [len = 62]
mbus_serial_recv_frame: Got 0 byte [remaining 63, len 62]
mbus_serial_recv_frame: Attempt to read 63 bytes [len = 62]
mbus_serial_recv_frame: Got 0 byte [remaining 63, len 62]
mbus_serial_recv_frame: Timeout
mbus_sendrecv_request: Received invalid M-Bus response frame.
mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
mbus_serial_recv_frame: Got 0 byte [remaining 1, len 0]
mSB: DEBUG: [mBusSerialReader]=>Error reading sensor (689070252D2C1D16: Error: Error: Failed to send/receive M-Bus request frame[689070252D2C1D16].)

Error: Failed to receive M-Bus response frame[1].

I'm getting this error when using the method getData(addr, cb) .
Here is the output:

0|node-red | mbus_serial_send_frame: Dumping M-Bus frame [5 bytes]: 10 40 FD 3D 16 
0|node-red | mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
0|node-red | mbus_serial_recv_frame: Got 0 byte [remaining 1, len 0]
0|node-red | mbus_serial_send_frame: Dumping M-Bus frame [5 bytes]: 10 40 FD 3D 16 
0|node-red | mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
0|node-red | mbus_serial_recv_frame: Got 0 byte [remaining 1, len 0]
0|node-red | mbus_serial_send_frame: Dumping M-Bus frame [5 bytes]: 10 5B 01 5C 16 
0|node-red | mbus_serial_recv_frame: Attempt to read 1 bytes [len = 0]
0|node-red | mbus_serial_recv_frame: Got 1 byte [remaining 1, len 0]
0|node-red | 68 
0|node-red | mbus_serial_recv_frame: Attempt to read 2 bytes [len = 1]
0|node-red | mbus_serial_recv_frame: Got 2 byte [remaining 2, len 1]
0|node-red | 71 70

Using method getData with address 1

(If you want we can speak about this in node-mbus channel on slack)

I have also tried to do a scan and after long time (15 minutes I got 0 devices found). Here part of the log of the scan:

scan_log.txt

Cannot rebuild

After downloading I run 'npm i' and i am getting this error preventing me:

Warning: Missing input files:
C:\Users\David\Desktop\node-mbus-master\build..\libmbus\mbus\mbus-tcp.c
C:\Users\David\Desktop\node-mbus-master\build..\libmbus\mbus\mbus-protocol-aux.c
C:\Users\David\Desktop\node-mbus-master\build..\libmbus\mbus\mbus-serial.c
C:\Users\David\Desktop\node-mbus-master\build..\libmbus\mbus\mbus-protocol.c
C:\Users\David\Desktop\node-mbus-master\build..\libmbus\mbus\mbus.c
C:\Users\David\Desktop\node-mbus-master\build..\libmbus\win\termiWin.c
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
mbus-protocol-aux.c
mbus-protocol.c
mbus-serial.c
mbus-tcp.c
c1 : fatal error C1083: Cannot open source file: '..\libmbus\mbus\mbus-tcp.c':
No such file or directory [C:\Users\David\Desktop\node-mbus-master\build\libmbu
s.vcxproj]
c1 : fatal error C1083: Cannot open source file: '..\libmbus\mbus\mbus-protocol
.c': No such file or directory [C:\Users\David\Desktop\node-mbus-master\build\l
ibmbus.vcxproj]
c1 : fatal error C1083: Cannot open source file: '..\libmbus\mbus\mbus-serial.c
': No such file or directory [C:\Users\David\Desktop\node-mbus-master\build\lib
mbus.vcxproj]
c1 : fatal error C1083: Cannot open source file: '..\libmbus\mbus\mbus-protocol
-aux.c': No such file or directory [C:\Users\David\Desktop\node-mbus-master\bui
ld\libmbus.vcxproj]
mbus.c
termiWin.c
c1 : fatal error C1083: Cannot open source file: '..\libmbus\mbus\mbus.c': No s
uch file or directory [C:\Users\David\Desktop\node-mbus-master\build\libmbus.vc
xproj]
c1 : fatal error C1083: Cannot open source file: '..\libmbus\win\termiWin.c': N
o such file or directory [C:\Users\David\Desktop\node-mbus-master\build\libmbus
.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\David\Desktop\node-mbus-master
gyp ERR! node -v v10.6.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\David\AppData\Roaming\npm-cache_logs\2018-07-11T12_11_12_073Z-debug.log

C:\Users\David\Desktop\node-mbus-master

Error when running on AWS Lambda function

When testing a connection on local machine, everything works accordingly, but as soon I push to an AWS Serverless Lambda function I get the following error:

{
"errorType": "Error",
"errorMessage": "/var/task/node_modules/node-mbus/build/Release/mbus.node: invalid ELF header",
"code": "ERR_DLOPEN_FAILED",
"stack": [
"Error: /var/task/node_modules/node-mbus/build/Release/mbus.node: invalid ELF header",
" at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)",
" at Module.load (internal/modules/cjs/loader.js:950:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
" at Module.require (internal/modules/cjs/loader.js:974:19)",
" at require (internal/modules/cjs/helpers.js:101:18)",
" at bindings (/var/task/node_modules/bindings/bindings.js:112:48)",
" at Object. (/var/task/node_modules/node-mbus/index.js:7:38)",
" at Module._compile (internal/modules/cjs/loader.js:1085:14)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
" at Module.load (internal/modules/cjs/loader.js:950:32)"
]
}

Running on NodeJs 14 locally and on Lambda.

Is there anything I can try to resolve this?
TIA

An in-range update of nyc is breaking the build 🚨


🚨 Reminder! Less than one month left to migrate your repositories over to Snyk before Greenkeeper says goodbye on June 3rd! πŸ’œ πŸššπŸ’¨ πŸ’š

Find out how to migrate to Snyk at greenkeeper.io


The devDependency nyc was updated from 15.0.1 to 15.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nyc is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • βœ… continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • ❌ continuous-integration/appveyor/branch: AppVeyor build failed (Details).

Commits

The new version differs by 5 commits.

  • de7baa4 chore(release): 15.1.0
  • 992359a feat(experimental): Support using --all with node.js ESM (#1320)
  • 086fd20 chore: Regenerate package-lock, update source-map-support test (#1314)
  • b20f751 chore: add bugs (used, e.g., by npmjs) (#1313)
  • 6898e88 chore: Fix CHANGELOG.md version header

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Information: Hardware advice on readme

I think we should give some advice to users that want to use our libraries. We could create a section with tested hardware converters (also with prices ?). What do you think about this?

IPv6 does not work

Describe the bug
Connect to IPv6 M-Bus server is not possible. Which make problems with IPv6 only networks or places where already ISP can not give public IPv4 because was exhausted in 2012. Would be nice after 12 years able to use IPv6.

I can connect over netcat, so it is not network problem.

To Reproduce
Steps to reproduce the behavior:

  1. Use example from web page
  2. Fill host filed with IPv6 address (no care if aaaa:bbb or [aaaa:bbbb] format, both does not work)
  3. Run it
  4. See error Error: No connection possible to MBus Host

Expected behavior
Get data

Screenshots & Logfiles

$ node client.js 
err: Error: No connection possible to MBus Host aaaa:aaaa:5100:dddd:860d:8eff:abcd:d0c8:1234
data: undefined
$ node client.js 
err: Error: No connection possible to MBus Host [aaaa:aaaa:5100:dddd:860d:8eff:abcd:d0c8]:1234
data: undefined

Versions:

  • Adapter version: latest in time of writing Bug Report
  • JS-Controller version: do not know, I am not NodeJS programmer mainly
  • Node version: v21.6.1
  • Operating system: Arch Linux, but this is OS independent, also debian, raspbian have same problem

Additional context
Add any other context about the problem here.

secondary addresses

Great work! this is surely going to save my bacon.

I cannot understand how to query a secondary address with getData?
Am I missing something?
I can scan successfully through a Cme3000.

mbus Slave

Hello !

THanks for your great work :)

Is there a way to make work this driver as modbus slave ?

VIF value resolution

Hello !

Is there a way to get value resolution from meter ?

Thanks for your help !

Wireless M-Bus

Does this work with a wireless M-Bus Device like Amber AMB8465-M?

An in-range update of nyc is breaking the build 🚨

The devDependency nyc was updated from 14.1.0 to 14.1.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nyc is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 9 commits.

  • fe3311b chore(release): 14.1.1
  • 85ec479 docs: Link to test-exclude in place of inline list of default excludes [skip ci] (#1109)
  • 57debc1 fix(cli): Report error if unwanted positional arguments are received (#1100)
  • b3dfae8 docs: Point to updated location of default exclude list (#1107)
  • 0cc7309 docs(readme): Fix Slack badge image insecure content warning [skip ci] (#1105)
  • 3cdfb8e docs: Mention extension in the CHANGELOG about exclude-after-remap
  • b5b67de fix(check-coverage): make the --temp-dir option visible (#1101)
  • 21fe1e7 chore: Regenerate snapshots for tap >= 12.6.3 (#1098)
  • 65478be docs: Reorganize readme (#1093)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Missing values

Hi Ingo, sorry to bother you again. It's all working perfectly now, but I'm still missing values from my sensors:

{
  "SlaveInformation": {
    "Id": 68024764,
    "Manufacturer": "ELV",
    "Version": 31,
    "ProductName": "",
    "Medium": "Unknown medium (0x1b)",
    "AccessNumber": 17,
    "Status": 0,
    "Signature": 0
  },
  "DataRecord": [
    {
      "id": 0,
      "Function": "Instantaneous value",
      "StorageNumber": 0,
      "Unit": "Energy (1e7 J)",
      "Value": "",
      "Timestamp": "2018-04-17T21:14:21Z"
    }
  ]
}

As you can see the Value is "". This might not have anything to do with node-mbus, but I'm struggling to understand the debug output (see attached file). Question: Can you see from the output if I get a value?
Thank you again.
log.log

Extend node-mbus library to allow sending a custom frame to a slave meter

Hi,

Thank you for creating this very useful library, however, it would be super useful to have a function that allows sending a custom frame to a secondary slave.

I have a CMex40 M-bus master connected to a breaker device which I need to turn on and off by sending it a simple frame 01 fd 1a 40. How can this be achieved with this library?

I appreciate the help as I am only a beginner developer learning nodejs but found no other library that handles m-bus communication.

Bug: Segmentation Error

I have been able to replicate the bug 'Segmentation Error: Core Dump created'. It happens when you try to close the client while there is a scan or a device read in progress. Test it with this code that is like example.js but edited with a close after the scan and not inside (I have tested it with a serial connection OS: Ubuntu 16.1):

var MbusMaster = require('../index.js');

/* CONNECTION EXAMPLES

var mbusOptions = {
host: '127.0.0.1',
port: port,
autoConnect: true
};

var mbusOptions = {
    serialPort: '/dev/ttyUSB0',
    serialBaudRate: 9600,
    autoConnect: true
};

*/

var mbusOptions = {};

function logUsage(){
  console.log("USAGE");
  console.log("SERIAL: node ./example/example.js -serialPort /dev/ttyUSB0 -serialBaudrate 9600 -autoConnect true");
  console.log("TCP: node ./example/example.js -host 127.0.0.1 -port 2000 -autoConnect true");
}

//PARSE OPTIONS
var args = process.argv.slice(2);

for (var i = 0; i < args.length; i++) {
  if(args[i].startsWith('-'))
    mbusOptions[args[i].substring(1)] = i+1 < args.length ? args[++i].trim() : null;
}

mbusOptions.autoConnect = mbusOptions.autoConnect === 'true';

if(mbusOptions.serialPort && !mbusOptions.serialBaudrate){
  console.log("Missing serial baudRate");
  logUsage();
}
else if(!mbusOptions.serialPort && mbusOptions.serialBaudrate){
  console.log("Missing serial port");
  logUsage();
}
else if(mbusOptions.host && !mbusOptions.port){
  console.log("Missing TCP port");
  logUsage();
}
else if(!mbusOptions.host && mbusOptions.port){
  console.log("Missing TCP host");
  logUsage();
}
else{

  console.log("Connecting with options: " + JSON.stringify(mbusOptions, null, 2));

  var mbusMaster = new MbusMaster(mbusOptions);

  if (!mbusMaster.connect()) {
    console.log('Connection failed.');
    process.exit();
  }

  console.log('Reading device ID 1...');

  // request for data from devide with ID 1
  mbusMaster.getData(1, function(err, data) {
    console.log('err: ' + err);
    console.log('data: ' + JSON.stringify(data, null, 2));

    console.log('Scanning network...');

    mbusMaster.scanSecondary(function(err, data) {
      console.log('err: ' + err);
      console.log('data: ' + JSON.stringify(data, null, 2));

      console.log('Closing client...');
      mbusMaster.close(function(err){
        if(err)
          console.log('Error while closing client');
        else {
          console.log('Client closed');
        }
      });
    });

    console.log('Closing client...');
    mbusMaster.close(function(err){
      if(err)
        console.log('Error while closing client');
      else {
        console.log('Client closed');
      }
    });
  });
}

node-mbus orders of magnitude slower than equivalent `libmbus` CLI tools

Describe the bug

When performing a getDataAsync poll on a M-Bus slave using primary addressing, node-mbus is taking orders of magnitude longer to complete than the equivalent libmbus CLI command.

To Reproduce
Steps to reproduce the behaviour:

  1. Check out https://github.com/sjlongland/pyMbusSlave
  2. Run python3 slave.py --device tcp:20000
  3. In a separate terminal; create a new directory, enter it and run npm install node-mbus
  4. Create test.js (see below) and run it:
// test.js
const MBusMaster = require("node-mbus");

const master = new MBusMaster({"host":"127.0.0.1","port":20000,"timeout":30000});
async function fetch() {
	const start = Date.now();
	const result = await master.getDataAsync(3);
	return {result, duration: Date.now() - start};
}

master.connectAsync().then(() => {
	return fetch();
}).then((res) => {
	console.log(res);
});

Expected behavior

Shown here, using libmbus binary tools…

stuartl@LPA075:~/vrt/projects/widesky/edge/mbus/privdoc/libmbus$ time bin/mbus-tcp-request-data localhost 20000 3
<?xml version="1.0" encoding="ISO-8859-1"?>
<MBusData>

    <SlaveInformation>
        <Id>12345678</Id>
        <Manufacturer>TST</Manufacturer>
        <Version>1</Version>
        <ProductName></ProductName>
        <Medium>Other</Medium>
        <AccessNumber>0</AccessNumber>
        <Status>00</Status>
        <Signature>0000</Signature>
    </SlaveInformation>

    <DataRecord id="0">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit> V</Unit>
        <Value>1234</Value>
        <Timestamp>2023-06-07T03:52:41Z</Timestamp>
    </DataRecord>

    <DataRecord id="1">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Volume ( m^3)</Unit>
        <Value>456</Value>
        <Timestamp>2023-06-07T03:52:41Z</Timestamp>
    </DataRecord>

</MBusData>

real    0m0.008s
user    0m0.005s
sys     0m0.004s
stuartl@LPA075:~/vrt/projects/widesky/edge/mbus/privdoc/pyMbusSlave$ python3 slave.py --device tcp:20000
INFO:pyMbusSlave:pyMbusSlave
INFO:pyMbusSlave:  Serial device:   tcp:20000
INFO:pyMbusSlave:  Baudrate:        2400
INFO:pyMbusSlave:  Slave address:   3
INFO:pyMbusSlave:  Slave device ID: 12345678
DEBUG:pyMbusSlave:Will bind to any address port 20000
INFO:pyMbusSlave:Listening ...

# libmbus command run here

INFO:pyMbusSlave:TCP connection from ('127.0.0.1', 54126)
DEBUG:pyMbusSlave:Short Frame
DEBUG:pyMbusSlave:C Field: 0x5b
DEBUG:pyMbusSlave:My Address: 3
DEBUG:pyMbusSlave:Checksum received: 5e vs stored: 5e
DEBUG:pyMbusSlave:Frame received: 5b
INFO:pyMbusSlave:Request for User Data 2
DEBUG:pyMbusSlave:Sent data

Screenshots & Logfiles

stuartl@LPA075:/tmp/mbustmp$ node test.js
{
  result: {
    SlaveInformation: {
      Id: 12345678,
      Manufacturer: 'TST',
      Version: 1,
      ProductName: '',
      Medium: 'Other',
      AccessNumber: 0,
      Status: 0,
      Signature: 0
    },
    DataRecord: [ [Object], [Object] ]
  },
  duration: 123956
}

123956ms, meanwhile on the slave:

stuartl@LPA075:~/vrt/projects/widesky/edge/mbus/privdoc/pyMbusSlave$ python3 slave.py --device tcp:20000
INFO:pyMbusSlave:pyMbusSlave
INFO:pyMbusSlave:  Serial device:   tcp:20000
INFO:pyMbusSlave:  Baudrate:        2400
INFO:pyMbusSlave:  Slave address:   3
INFO:pyMbusSlave:  Slave device ID: 12345678
DEBUG:pyMbusSlave:Will bind to any address port 20000
INFO:pyMbusSlave:Listening ...

# node test.js run here

INFO:pyMbusSlave:TCP connection from ('127.0.0.1', 35078)
DEBUG:pyMbusSlave:Short Frame
DEBUG:pyMbusSlave:C Field: 0x40
DEBUG:pyMbusSlave:Network Address NOT selected: 253
DEBUG:pyMbusSlave:Checksum received: 3d vs stored: 3d
DEBUG:pyMbusSlave:Frame received: 40
DEBUG:pyMbusSlave:Frame not for us
DEBUG:pyMbusSlave:Short Frame
DEBUG:pyMbusSlave:C Field: 0x40
DEBUG:pyMbusSlave:Network Address NOT selected: 253
DEBUG:pyMbusSlave:Checksum received: 3d vs stored: 3d
DEBUG:pyMbusSlave:Frame received: 40
DEBUG:pyMbusSlave:Frame not for us
DEBUG:pyMbusSlave:Short Frame
DEBUG:pyMbusSlave:C Field: 0x40
DEBUG:pyMbusSlave:My Address: 3
DEBUG:pyMbusSlave:Checksum received: 43 vs stored: 43
DEBUG:pyMbusSlave:Frame received: 40
INFO:pyMbusSlave:Slave Initialization
DEBUG:pyMbusSlave:Sent data
DEBUG:pyMbusSlave:Short Frame
DEBUG:pyMbusSlave:C Field: 0x5b
DEBUG:pyMbusSlave:My Address: 3
DEBUG:pyMbusSlave:Checksum received: 7e vs stored: 7e
DEBUG:pyMbusSlave:Frame received: 5b
INFO:pyMbusSlave:Request for User Data 2
DEBUG:pyMbusSlave:Sent data

Versions:

  • node-mbus release 2.0.0
  • libmbus git master (commit b2f36f49109af48b901e07d8cfd2783fe668ddde)
  • Python 3.10.6 (for pyMbusSlave simulator)
  • NodeJS v16.18.1 (sadly, work requires me to use this release)
  • Operating System: Ubuntu Linux/AMD64 22.04 LTS
  • Adapter version: not known
  • JS-Controller version: iobroker not installed

Additional context

As the slave is a simulated slave communicating over a TCP socket on the loopback device, we can rule out any delays related to the physical layer. Similarly, as it takes a mere 5ms for libmbus CLI tools to poll the simulated device, we can rule out libmbus.

It would appear that the library is erroneously attempting secondary address selection, timing out, then switching to the primary address that's set in slave.py.

@serialport/bindings dependency seems to cause issues with Node.js 22

Describe the bug
In node-wot we tried to add Node.js 22 as CI dependency and the run fails with issues w.r.t. to @serialport/bindings

https://github.com/eclipse-thingweb/node-wot/actions/runs/8846329944/job/24291988667?pr=1274#step:5:13

To Reproduce
See eclipse-thingweb/node-wot#1274.
node-wot uses mbus in package binding-mbus.

Expected behavior npm ci or npm install should work.

Versions:
Tested node-mbus 2.1.0 and 2.2.2.

BTW, I noticed that https://www.npmjs.com/package/@serialport/bindings has been moved to https://www.npmjs.com/package/@serialport/bindings-cpp and has new version
Maybe updating to the latest version of @serialport/bindings-cpp is enough.

An in-range update of mocha is breaking the build 🚨

The devDependency mocha was updated from 6.2.1 to 6.2.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

mocha is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/appveyor/branch: Waiting for AppVeyor build to complete (Details).
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v6.2.2

6.2.2 / 2019-10-18

πŸ› Fixes

πŸ“– Documentation

Commits

The new version differs by 12 commits.

  • 843a322 6.2.2
  • aec8b02 update CHANGELOG for v6.2.2 [ci skip]
  • 7a8b95a npm audit fixes
  • cebddf2 Improve reporter documentation for mocha in browser. (#4026)
  • 3f7b987 uncaughtException: report more than one exception per test (#4033)
  • ee82d38 modify alt text of image from Backers to Sponsors inside Sponsors section in Readme (#4046)
  • e9c036c special-case parsing of "require" in unparseNodeArgs(); closes #4035 (#4063)
  • 954cf0b Fix HTMLCollection iteration to make unhide function work as expected (#4051)
  • 816dc27 uncaughtException: fix double EVENT_RUN_END events (#4025)
  • 9650d3f add OpenJS Foundation logo to website (#4008)
  • f04b81d Adopt the OpenJSF Code of Conduct (#3971)
  • aca8895 Add link checking to docs build step (#3972)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Not able to get values...

Hi, and thanks for this repo!
I'm trying to use the node-mbus repo to receive data from a CMeX50. It was very easy to get started and I received data:

err: null
data: {
  "SlaveInformation": {
    "Id": 68024764,
    "Manufacturer": "ELV",
    "Version": 31,
    "ProductName": "",
    "Medium": "Unknown medium (0x1b)",
    "AccessNumber": 33,
    "Status": 0,
    "Signature": 0
  },
  "DataRecord": [
    {
      "id": 0,
      "Function": "Instantaneous value",
      "StorageNumber": 0,
      "Unit": "Energy (1e7 J)",
      "Value": "",
      "Timestamp": "2018-04-15T11:48:27Z"
    }
  ]
}

Queston 1: The sensor is a therometer and should have values. Is there anyway I can get the unparsed data to verify?

Queston 2: Is there a way of getting data from all sensors sort of getData('ALL'...)?

Queston 3: The scanSecondary function logs other sensors to the console. Is there a way to get that list so that I can continue?

Found a device on secondary address 610003609615011B [using address mask 61FFFFFFFFFFFFFF]
Found a device on secondary address 6200165396150331 [using address mask 62FFFFFFFFFFFFFF]
Found a device on secondary address 6802476496151F1B [using address mask 68FFFFFFFFFFFFFF]
err: null
data: [] // be nice it this was populated...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.