Created
September 19, 2016 10:05
-
-
Save johncmckim/1449cbfa25d63ce5ff6fb8d245455af1 to your computer and use it in GitHub Desktop.
Garden Aid - IoT Hub - Device
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
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @johncmckim thank you for this example and your blogposts about the garden-aid iot project. One remark: topic is not defined.