2pk03 / bacnet-mqtt-gateway

BACnet MQTT Gateway
Apache License 2.0
50 stars 27 forks source link
bacnet iot-device mqtt-broker npm opensource

BACnet MQTT Gateway

BACnet MQTT Gateway is gateway that connects BACnet devices via MQTT to the cloud. It is written in Javascript and uses node.

For BACnet connection the Node BACstack is used.

Functionalities

Getting started

  1. Clone repo and install npm dependencies:

    git clone https://github.com/2pk03/bacnet-mqtt-gateway.git
    cd bacnet-mqtt-gateway
    npm install
  2. Configure gateway:

    By default the gateway is configured to use infinimesh.cloud platform, but it can be used with any MQTT broker.

    Open config/default.json and change MQTT configuration by defining your device id and the path to the device certificate files.

    {
        "mqtt": {
            "gatewayId": "{{device id}}",
            "host": "mqtt.api.infinimesh.cloud",
            "port": 8883,
            "authentication": {
                "certPath": "{{device .crt file path}}",
                "keyPath": "{{device .key file path}}"
            }
        },
        "bacnet": {
            "configFolder": "./devices/"
        },
        "httpServer": {
            "enabled": true,
            "port": 8082
        }
    }
  3. Start the gateway and open admin interface

    npm start
    open http://localhost:8082/admin

Device polling configuration

The gateway can poll BACnet object present values and send the values via MQTT into the cloud. To configure polling for a BACnet device you can put a .json file into the devices folder.

{
    "device": {
        "deviceId": 114,
        "address": "192.168.178.55"
    },
    "polling": {
        "schedule": "*/15 * * * * *"
    },
    "objects": [{
        "objectId": {
            "type": 2,
            "instance": 202
        }
    }, {
        "objectId": {
            "type": 2,
            "instance": 203
        }
    }]
}

You need to define the device id, ip address, schedule interval (as CRON expression) and the objects to poll.

When the gateway is started it automatically reads the list of files from the directory and starts the polling for all devices.

REST API

To execute commands the gateway offers a REST API under http://localhost:8082/api/bacnet.

The following endpoints are supported:

Run with Docker

Gateway can also be run as a docker container. Just build the image and start a container:

docker build -t bacnet-mqtt-gateway
docker run -p 8082:8082 -v /mnt/bacnet-gateway/devices:/usr/src/app/devices -v /mnt/bacnet-gateway/config:/usr/src/app/config bacnet-mqtt-gateway

With the specified file mountings you can put the config file under /mnt/bacnet-gateway/config and the device configs under /mnt/bacnet-gateway/devices on the host system.