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

@adamfraczkowski/mqtt_bridge

v1.0.7

Published

MQTT bridge interface

Downloads

19

Readme

MQTT_BRIDGE

A simple package that allows you to create a bridge between mqtt and a serial port

INSTALLATION

npm install -g @adamfraczkowski/mqtt_bridge

HOW TO USE

  1. Create config json file. allowed parameters:
  • mqttConnectionString - mqtt connection string ex: "mqtt://test.mosquitto.org", follow MQTT.js to determine correct connection string
  • mode - "serial","terminal" or "gpio",
  • baud - baudrate for serial device,
  • port - serial port id,
  • dataFormat - "hexstring" or "raw". In "hexstring" dataformat Buffer bytes from serial are converted to hexstring. Hex string values published to mqtt are converted to buffer,
  • inputTopic - topic for publishing data TO device,
  • outputTopic - Topic where you can receive data from device
  • commandTopic - Topic where you can send custom command to mqtt bridge.
  • shell - In terminal mode - terminal shell - for example "cmd.exe", "bash", "powershell.exe"
  • gpioConfig - In gpio mode - JSON object that determine gpio configs - see config_gpio.json
  1. execute command:
mqtt_bridge config <path to your config json file>

COMMAND LIST

  • terminate - command that terminates mqtt bridge. When your device not working well you can try to restart mqtt_bridge executing that command. After that your process manager like PM2 can restart your mqtt_bridge process

GPIO mode

bridge uses WiringPI as backend. It uses GPIO tool utility. It should be available in the system as gpio command. Example:

 gpio readall 

For banana pi use this version:

https://github.com/bontango/BPI-WiringPi2

GPIO inputs:

Emitted objects (JSON):

    {
        "pin":<pin from wiringPI>,
        "dir":<"in"/"out">,
        "timestamp":<timestamp in millis>,
        "value":<true/false>,
        "event":<"press"/"longpress">
    }

Objects to send:

    {
        "cmd":<"setpin"/"blinkpin"/"start"/"stop">,
        "data":{
            "pin":<pin from wiringPI>,
            "value":<true/false>,
            "onTime":<on time in milliseconds - for blink>,
            "offTime":<off time in milliseconds - for blink>,
            "times":<number of blinks - for blink>
        }
    }

Example config file:

serial mode:

{
   "mqttConnectionString":"mqtt://test.mosquitto.org",
   "mode":"serial",
   "baud":57600,
   "port":"COM2",
   "dataFormat":"hexstring",
   "inputTopic":"serial-device/input",
   "outputTopic":"serial-device/output"
}

terminal mode:

{
   "mqttConnectionString":"mqtt://broker.hivemq.com:1883",
   "mode":"terminal",
   "shell":"cmd.exe",
   "inputTopic":"terminal-bridge/input",
   "outputTopic":"terminal-bridge/output",
   "commandTopic":"mqtt-bridge/command"
}

gpio mode:

{
   "mqttConnectionString":"mqtt://broker.hivemq.com:1883",
   "mode":"gpio",
   "gpioConfig":[
       {"pin":15,"dir":"in","pull":"down"},
       {"pin":16,"dir":"in","pull":"down"},
       {"pin":7,"dir":"out","pull":"down"},
       {"pin":8,"dir":"out","pull":"down"},
       {"pin":9,"dir":"out","pull":"down"}
   ],
   "inputTopic":"gpio-bridge/input",
   "outputTopic":"gpio-bridge/output",
   "commandTopic":"gpio-bridge/command"
}