angryelectron / xbmq-js

NodeJS XBee to MQTT Gateway
GNU General Public License v3.0
7 stars 3 forks source link

XBee to MQTT Gateway

xbmq is a NodeJs XBee-over-MQTT gateway. It allows two-way communication with XBee networks through MQTT messages and aims to do as little processing as possible, allowing it to run reliably and on low-power / embedded devices.

xbmq does not enable MQTT messages to be sent through an XBee network. Instead, it enables XBee API frames to be sent and received by MQTT clients.

Quick Start

Install xbmq via npm install xbmq or npm install -g xbmq.

Configure the local XBee:

Configure xbmq with your mqtt and serial port settings using command-line arguments. The arguments and their default values are:

Then start the gateway with xbmq <options> (for global install). Alternatively, if installed locally (vs. globally), you can use a config file. Copy or rename config.json.sample to config.json and lauch using ./xbmq.js (or via pm2).

Note: Command-line arguments override config.json.

Operation

All MQTT messages (to and from the XBee network) are published to subtopics of rootTopic/gatewayIdentifier, where rootTopic is configured as above and gatewayIdentifier is the NI value of the local XBee. If NI is not set, the radio's 64-bit address will be used instead.

Topic: rootTopic/gatewayIdentifier/online

Topic: rootTopic/gatewayIdentifier/response

Topic: rootTopic/gatewayIdentifier/request

Messages

xbee-api frames received from the XBee network will be converted to JSON and published to the broker, but there are a few shortcuts and things to keep in mind when building xbee-api frames to send via mqtt:

Tips for Using with MQTT Clients

MQTT module for NodeJS

Node-Red

Embedded Application Note

xbmq-js is intended to run on single board computers, OpenWrt routers, and other devices with limited resources that either can't access npm repositories, don't have native compilers, or just take forever to run npm install.

This is why dependencies without native components have been bundled with the application. serialport is listed as an optional dependency because installing it involves native compiling, which typically can't be done on these limited devices.

Troubleshooting

Confirm your mqtt settings by connecting to the broker using another tool, like mosquitto_sub, and subscribing to all topics:

mosqsuitto_sub -v -h <broker> -u <username> -P <password> -t '<rootTopic>/#'

Then start xbmq with the same MQTT settings. Once xbmq has connected successfully to the broker, you should see the value 1 be published to <rootTopic>/<XBee NI name>/online. Stopping xbmq will publish 0.

Use another XBee on the network to transmit some data, like an IOSample. You should see an xbee-api frame published to <rootTopic>/<XBee NI name>/response

About

xbmq is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

xbmq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with xbmq. If not, see http://www.gnu.org/licenses/.