Skip to content

Instantly share code, notes, and snippets.

@questsin
Created February 20, 2019 14:55
Show Gist options
  • Save questsin/b94bf8ecf0fbf766a005e1f539a02b8d to your computer and use it in GitHub Desktop.
Save questsin/b94bf8ecf0fbf766a005e1f539a02b8d to your computer and use it in GitHub Desktop.
var AWSMqtt = require('aws-mqtt-client').AWSMqtt;
//Create an IAM role and asign predefined AWSIoTDataAccess policy
const mqttClient = new AWSMqtt({
accessKeyId: '',
secretAccessKey: '',
sessionToken: '',
endpointAddress: '',
region: 'eu-west-1'
});
mqttClient.on('connect', () => {
mqttClient.subscribe('test-topic');
console.log('connected to iot mqtt websocket');
});
mqttClient.on('message', (topic, message) => {
console.log(message.toString());
});
//mqttClient.publish(MQTT_TOPIC, message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment