Skip to content

Instantly share code, notes, and snippets.

@davedarko
Created June 9, 2019 20:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davedarko/2441c32d46b5412e9a94abce9904847e to your computer and use it in GitHub Desktop.
Save davedarko/2441c32d46b5412e9a94abce9904847e to your computer and use it in GitHub Desktop.
var mqtt = require('mqtt');
var HOST = '192.168.43.10';
var client = mqtt.connect("mqtt:\/\/" + HOST, { port: 1883 });
client.on('connect', function () {
console.log("Connected to " + HOST);
client.subscribe('hermes/intent/#');
});
client.on('message', function (topic, message) {
// When receiving an MQTT message, trigger and action...
if (topic.startsWith('hermes/intent/')) {
var payload = JSON.parse(message);
var name = payload["intent"]["intentName"];
var slots = payload["slots"];
var value = slots[0].rawValue;
console.log('Intent: '+ name);
console.log(' value: '+value);
client.publish('R8J4/move', value);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment