Skip to content

Instantly share code, notes, and snippets.

@ThomasPe
Created September 16, 2020 13:41
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 ThomasPe/455d3388a110121441241be67d2d0453 to your computer and use it in GitHub Desktop.
Save ThomasPe/455d3388a110121441241be67d2d0453 to your computer and use it in GitHub Desktop.
Reading Ruuvi Tag messages in IoT Edge
Client.fromEnvironment(Transport, function (err, client) {
if (err) {
throw err;
} else {
client.on('error', function (err) {
throw err;
});
// connect to the Edge instance
client.open(function (err) {
if (err) {
throw err;
} else {
console.log('IoT Hub module client initialized');
initRuuviTag();
}
});
}
});
// listens to ruuvi tags nearby and subscribes to their messages
function initRuuviTag() {
ruuvi.on('found', tag => {
console.log('Found RuuviTag, id: ' + tag.id);
tag.on('updated', async data => {
var json = JSON.stringify(data, null, '\t')
var sensorMsg = new Message(json);
// send received ruuvi message through module identity
client.sendOutputEvent('output1', sensorMsg, printResultFor('Sending ble payload'));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment