Skip to content

udaygin/mqtt2rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mqtt2rest (Work in Progress)

Simple Nodejs Server to subscribe to a group of mqtt topics on a given mqtt broker and serve the received data as json over http

Warning : This autostarting service capabilities fo the project are desingend for linux(Ubuntu systemd) only. rest of the code should work fine even on windows.

Background

How to

Download

cd /opt/
sudo git clone https://github.com/udaygin/mqtt2rest.git
sudo chown -R $USER:$USER mqtt2rest

Installation

Background service installation

Note : skip this service installation section if you just want to run it manually from command line

Edit username to match yours(or any other user that you want to run this as )

cd /opt/mqtt2rest
sed -i 's/uday/`whoami`/g' /opt/mqtt2rest/mqtt2rest.service

install this as a linux auto starting service

sudo systemctl enable /opt/mqtt2rest/mqtt2rest.service

Standalone

No action needed.

Usage

Configuration

Ath the minimum, you need to configure two things

  • Mqtt broker connection details
  • Topics to watch
  • Port to serve json content on
Configure mqtt broker connection details

Replace values of properties under [mqtt] section in file /opt/mqtt2rest/config.ini with the correct ones to your broker.

[mqtt]
broker.ip=<your mqtt broker ip>
client.id=
client.user=
client.pwd=
Configure mqtt topics to watch

Edit the value of property topic.prefix under [mqtt] section to match your topic prefix For Ex: if you have below topics for devices in your home

  • /devices/livingroom/speakers
  • /devices/livingroom/thermostat
  • /devices/bedroom/thermostat
  • /devices/bedroom/smartlight
  • /devices/kitchen/eggtray and if you want to monitor all the devices in all rooms , your topic.prefix should be "/devices/" Note: don't forget the trailing slash on the other hand, if you want only bedroom devices to be monitored your topic.prefix should be "/devices/bedroom/" Note: don't forget the trailing slash
Configure port to start the server on

By default, this script starts the http server on port 3000. you can change it by editing

[rest]
listen.port=3000
Configure database file name (optional)

By default the database file name is mqttdata.json and you can customize it by editing database.name under [misc] section. Please note that yoou dont need to specify .json extenstion in the property value.

[misc]
database.name=mqttdata

Start the server

For Background service

start the service install this as a auto starting service

sudo systemctl start mqtt2rest
For manual run
cd /opt/mqtt2rest
node main.js

About

Simple Nodejs Script to serve data received by group of mqtt topics as a http endpoint

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published