Simple Nodejs Script to serve data received by group of mqtt topics as a http endpoint
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.
cd /opt/
sudo git clone https://github.com/udaygin/mqtt2rest.git
sudo chown -R $USER:$USER mqtt2rest
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
No action needed.
Ath the minimum, you need to configure two things
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=
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
By default, this script starts the http server on port 3000. you can change it by editing
[rest]
listen.port=3000
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 service install this as a auto starting service
sudo systemctl start mqtt2rest
cd /opt/mqtt2rest
node main.js