Skip to content

Instantly share code, notes, and snippets.

@ThomasPe
Created Sep 16, 2020
Embed
What would you like to do?
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