Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including rpi2mqtt with all npm packages installed. Try it out:

var rpi2mqtt = require("rpi2mqtt")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

rpi2mqtt v2.0.0

Connect a RaspberryPi 1-Wire and GPIOs to MQTT


License NPM version Dependency Status Build Status XO code style License

Connect RaspberryPi GPIOs and 1-Wire temperature sensors to MQTT


Prerequisite: Node.js version 6.0 or above. I suggest to use to install a recent version of Node.js.

Install rpi2mqtt: $ sudo npm install -g rpi2mqtt

To run rpi2mqtt in background an start on system boot I suggest to use PM2.


Usage: rpi2mqtt [options]

  -c, --config         use config file                                                          [default: "~/.pi2mqtt/config.json"]
  -l, --log            log to file                                                              [default: "~/.pi2mqtt/daemon.log"]
  -v, --verbosity      possible values: "error", "info", "debug"                                [default: "error"]
  -a, --alias          alias topics. can be used multiple times. See examples                 
  -i, --in, --input    use gpio as input. can be used multiple times. See examples            
  -o, --out, --output  use gpio as output. can be used multiple times. See examples           
  -p, --payload        type of the mqtt payload. possible values are "plain" and "json"         [default: "plain"]
  -r, --retain         publish with retain flag                                               
  -t, --topic          topic prefix                                                             [default: "<hostname>"]
  -x, --testament      topic for connect and last will message                                  [default: "connected"]
  -u, --url            broker url. See    [default: "mqtt://"]
  -s, --w1-wait        seconds to wait before reading /sys/bus/w1/devices/                      [default: 30]
  -n, --w1-interval    polling interval for 1-wire temperature sensors in seconds               [default: 30]
  -w, --w1-disable     disable 1-wire                                                         
  -h, --help           show help                                                              
  --version            Show version number                             

MQTT Topics

Default prefix is the hostname. You can disable the topic prefix with empty option --topic

1-Wire Temperature Sensors (DS1820)


Example: raspberrypi/status/w1/28-000005908b0e


Example input <prefix>/status/gpio/<gpio-number>


You can set individual topics with the --alias option.
Example: rpi2mqtt -a w1/28-000005908b0e:"Temperature/Garden"

Mind that aliases don't affect the configured prefix. So rpi2mqtt -o 17 -a gpio/17:Garden -t Light would result in topic Light/Garden for GPIO17


  • PiFace
  • Displays
  • uart/spi/i2c?


MIT Copyright (c) Sebastian Raff

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free