Created
June 9, 2019 20:52
-
-
Save davedarko/2441c32d46b5412e9a94abce9904847e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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