/mqtt-html

Script thats make a simple interface between MQTT and a HTTP RESTful API

Primary LanguageJavaScript

Script MQTT -> API RESTful

Script that make an interface between MQTT topics and a HTTP RESTful API

Configuration

Obviously: npm install

Put your topics here

const TO_SUBSCRIBE = ['humidite'];

Change the MQTT host (to have encrypted connection please refer you MQTT.js documentation)

const MQTT_HOST = '127.0.0.1';

Change the HTTP port

const HTTP_PORT = 3000;

Usage

Every topic that is on subscribeList is available with this URL http://HOSTNAME:PORT/TOPIC

Example

Example topic temperature

http://HOSTNAME:PORT/temperature

Response:

{
  "message": "43.22",
  "date": 1498222988924
}
  • Message : (String) Received message
  • Date : Timestamp

All

Get all registered topics

http://HOSTNAME:PORT/all

Response:

{
	"temperature": {
  		"message": "43.22",
  		"date": 1498222988924
	},
  	"door/opened": {
  		"message": "false",
  		"date": 1498222988924
	}
}

Empty data

http://HOSTNAME:PORT/unknown

Response:

{
  "message": null,
  "date": null
}