├── .gitignore ├── README.md ├── package.json ├── mbusreader.js └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MBusReader 2 | This package uses Node.js to read base64 encoded mbus packages. It uses MBusParser to parse the received messages. 3 | 4 | ## Disclaimer 5 | This project is only developed as an example and may break at any time. (Tested on a Raspberry Pi 3) 6 | 7 | ## Pre-Reqs 8 | * Connect Oss-brikken to available USB Port 9 | * Update to correct port in mbusreader.js 10 | * node, npm, and git installed 11 | 12 | ## Get started 13 | ```bash 14 | git clone https://github.com/ossno/mbusreader 15 | cd mbusreader 16 | npm install 17 | node mbusreader.js 18 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mbusreader", 3 | "version": "1.0.0", 4 | "description": "Example program that reads mbus data from a serial port and decodes with MBusParser", 5 | "main": "mbusreader.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Oss Norge AS", 10 | "license": "MIT", 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/ossno/readmbus" 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/ossno/readmbus/issues" 17 | }, 18 | "homepage": "https://github.com/ossno/readmbus#README", 19 | "dependencies": { 20 | "mbusparser": "git+https://github.com/ossno/mbusparser", 21 | "serialport": "^7.0.2" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mbusreader.js: -------------------------------------------------------------------------------- 1 | const MBusParser = require("mbusparser"); 2 | const OssBrikkenUSB = "/dev/ttyS13"; 3 | const SerialPort = require('serialport') 4 | 5 | const port = new SerialPort(OssBrikkenUSB, { 6 | baudRate: 115200 7 | }, function (err) { 8 | if (err) { 9 | return console.log('Error: ', err.message) 10 | } 11 | }) 12 | 13 | let prevData = Buffer.alloc(0); 14 | port.on('data', function (data) { 15 | prevData = Buffer.concat([prevData, data], prevData.length + data.length); 16 | let parsed = new MBusParser(prevData.toString('base64')); 17 | if (parsed.type != "error") { 18 | // Successfully parsed 19 | prevData = Buffer.alloc(0); 20 | console.log("---------------------------"); 21 | console.log(new Date().toLocaleString()); 22 | console.log(parsed); 23 | } 24 | }) 25 | 26 | port.on('error', function (err) { 27 | console.log('Error: ', err.message) 28 | }) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Oss 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. --------------------------------------------------------------------------------