Script that make an interface between MQTT topics and a HTTP RESTful API
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;
Every topic that is on subscribeList is available with this URL http://HOSTNAME:PORT/TOPIC
Example topic temperature
http://HOSTNAME:PORT/temperature
Response:
{
"message": "43.22",
"date": 1498222988924
}
- Message : (String) Received message
- Date : Timestamp
Get all registered topics
Response:
{
"temperature": {
"message": "43.22",
"date": 1498222988924
},
"door/opened": {
"message": "false",
"date": 1498222988924
}
}
Response:
{
"message": null,
"date": null
}