bmxx80-mqtt

command module
v0.0.0-...-b23d79d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2019 License: MIT Imports: 9 Imported by: 0

README

bmxx80-mqtt

Reads a BMP180/BME280/BMP280 environmental sensor over I²C and publishes the readings to an MQTT broker.

Okay this was really an excuse to try Golang after finding out that the Raspberry Pi Zero doesn't support .NET Core. If you're interested, I'm using this with Mosquitto, Node-RED, InfluxDB and Grafana to track temperature, pressure and humidity.

Getting Started

These instructions mainly focus on the Raspberry Pi running Raspbian, but the idea is the same for any platform.

Building for the Pi Zero (ARMv6) is easy peasy:

$ env GOOS=linux GOARCH=arm GOARM=6 go build

Running will require at least the MQTT topic and broker address (runs in the background):

$ nohup ./bmxx80-mqtt -topic="sensor/test" -broker="tcp://10.10.1.1:1883" &

Use --help to see all options.

Run on Boot

Start by creating a new service:

# nano /lib/systemd/system/bmxx80.service

Paste in the following (being sure to update your broker and topic):

[Unit]
Description=Environmental Sensor

## Make sure we only start the service after network is up.
Wants=network-online.target
After=network.target

[Service]
ExecStart=bmxx80-mqtt -broker="tcp://10.10.1.1:1883" -topic="sensor/test"

[Install]
WantedBy=multi-user.target

Move your bmxx80-mqtt executable to /usr/local/sbin:

# mv bmxx80-mqtt /usr/local/sbin

Test your service works:

# systemctl start bmxx80

Enable the service:

# systemctl enable bmxx80

Using with Node-RED and InfluxDB

Sensor readings are published to the MQTT broker in JSON format. Make sure you set your MQTT in node output property to a parsed JSON object. You can then simply pipe this into an InfluxDB out node.

If you have multiple sensors, then use a wildcard for your MQTT topic (for example: sensor/#). Then simply use the topic as your InfluxDB measurement by means of a function node:

return {
    measurement: msg.topic.split("/").pop(),
    payload: msg.payload
};

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL