Node.js implementation of a MQTT to Influxdb bridge for recording sensor data transmitted over MQTT to InfluxDB
Prerequisites
- Node.js 12
- MQTT Broker
- InfluxDB
Yarn
yarn install
yarn run dev
NPM
npm install
npm run dev
ENV_VARS=something node index.js
Using this MQTT bridge your message payload must have a similar schema:
{ "temperature": 21.1 }
You can also have multiple measurements per payload for example:
{ "temperature": 21.1, "pressure": 1020, "humidity": 37 }
Which will then be converted into the following schema and written to InfluxDB:
{
"measurement" : "temperature",
"tags": {
"topic": "/my-topic/sensor/bme280",
},
"fields": {
"value": 21.10
}
}...
NOTE: The value is expected to be a float
To use the bridge you need to set a series of environment variables:
INFLUX_HOST
Required - defines the hostname of the Influxdb instanceINFLUX_PORT
Default 8086 - defines the port to use to contact the Influxdb instanceINFLUX_DB_NAME
Required - database name to write toINFLUX_USERNAME
Required - database username to connect withINFLUX_PASSWORD
Required - database password to connect with
MQTT_HOST
Required - defines the hostname of the MQTT brokerMQTT_USERNAME
Required - MQTT usernameMQTT_PASSWORD
Required - MQTT passwordMQTT_PROTOCOL
Defaults to tlsMQTT_TOPICS
Required - comma seperated list of topics to listen to e.gMQTT_TOPICS=/topic1,/topic2
or use#
for all topics on broker
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D