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

dashbutton2mqtt

v2.1.0

Published

Publish dash button presses to a MQTT broker

Downloads

9

Readme

dashbutton2mqtt

NPM version Dependency Status Build Status XO code style License

Publish dash button presses to a MQTT broker. 🔘📡

Based on node-dash-button by Alex Hortin - all credits belong to him.

Getting started

Tested on macOS and Linux. If you're running on Linux you have to install libpcap-dev:

  • Ubuntu, Debian, Raspbian, ... $ sudo apt-get install libpcap-dev
  • Fedora, CentOS $ sudo yum install libpcap-devel

Install

Prerequisite: Node.js version 6.0 or above. I suggest to use https://github.com/tj/n to install a recent version of Node.js.

$ sudo npm install -g dashbutton2mqtt

Find dash buttons

$ sudo dashbutton2mqtt --scan

The scan shows only MAC Addresses that are known to be registered by Amazon. If you want to see all detected addresses add the option -v debug.

Create a JSON mapping file

Create a JSON file that maps dash button mac addresses to MQTT topics and payloads.

Example:

{
    "50:f5:da:60:20:10": {
        "topic": "dashbutton/foo"
    },
    "50:f5:da:60:20:11": {
        "topic": "dashbutton/bar",
        "payload": "press"
    }
}

If you omit the payload attribute an empty string will be published.

Start

$ sudo dashbutton2mqtt -m /path/to/mapping.json

Caveats

  • Since node-dash-button uses libpcap to scan for dash button arp packets this tool must be run with superuser.
  • This tool has to be executed on a host that is connected to the same wifi network as the dash buttons.
  • Due to the nature of the dash buttons there will be a latency of ~4 seconds between a button press and the MQTT publish.
  • As long as the LED of the dash button is blinking you can't do further button presses.

Binding To Specific Network Interface

By default this tool binds to the first network interface. To bind to a specific interface, such as eth6, pass the name of the interface with the --interface option.

Adjusting the Timeout

If multiple presses are detected you can increase the timeout between presses. Default is 5000ms, depending on your network this may not be enough, you can set a higher timeout with the --timeout option.

Command line options

Usage: dashbutton2mqtt [options]

Options:
  -v, --verbosity  possible values: "error", "warn", "info", "debug"
                                                               [default: "info"]
  -s, --scan       scan for dash buttons
  -m, --mapping    json file containing dashbutton-mqtt mappings (see Readme)
         [default: "/Users/basti/WebstormProjects/dashbutton2mqtt/example.json"]
  -n, --name       instance name. used as mqtt client id and as prefix for
                   connection topic                      [default: "dashbutton"]
  -u, --url        mqtt broker url. See
                   https://github.com/mqttjs/MQTT.js#connect-using-a-url
                                                   [default: "mqtt://127.0.0.1"]
  -i, --interface  bind to network interface to listen for dash button presses
                                                                 [default: null]
  -p, --protocol   protocol to use for button detection. possible values: "arp",
                   "udp", "all"                                 [default: "all"]
  -t, --timeout    timeout between button presses.               [default: 5000]
  -h, --help       Show help                                           [boolean]
  --version        Show version number                                 [boolean]

Run as service

I suggest PM2 to run dashbutton2mqtt in the background and start on system boot.

Contributions

Pull requests welcome! 😀

License

MIT © Sebastian Raff