Created
September 16, 2020 13:41
-
-
Save ThomasPe/455d3388a110121441241be67d2d0453 to your computer and use it in GitHub Desktop.
Reading Ruuvi Tag messages in IoT Edge
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
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