Skip to content

Instantly share code, notes, and snippets.

@johncmckim
Created September 19, 2016 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johncmckim/1449cbfa25d63ce5ff6fb8d245455af1 to your computer and use it in GitHub Desktop.
Save johncmckim/1449cbfa25d63ce5ff6fb8d245455af1 to your computer and use it in GitHub Desktop.
Garden Aid - IoT Hub - Device
const awsIot = require('aws-iot-device-sdk');
const interval = 1000 * 60 * 1; // one minute
const device = awsIot.device({
keyPath: './path/to/your/private.pem.key',
certPath: './path/to/your/certificate.pem.crt',
caPath: './path/to/your/verisign-ca.pem',
clientId: 'garden-aid-client-test-js',
region: 'ap-southeast-2'
});
device.on('connect', function() {
console.log('connect');
setInterval(function() {
const level = 1.1; // or generate a random level
const options = {};
const message = JSON.stringify({
Level: level
});
device.publish(topic, message, options, function(err, result) {
console.log('Err: ', err);
console.log('Result: ', result);
});
}, interval);
});
@krizon
Copy link

krizon commented Sep 15, 2017

Hi @johncmckim thank you for this example and your blogposts about the garden-aid iot project. One remark: topic is not defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment