LoraWAN and IOTA: Proof of Concept of storing data in real time in the Tangle

My wish for 2019 was to create a proof of concept around LoraWAN with IOTA. The obvious thing to do is to store data sent by a LoraWAN device directly into the Tangle. This would be awesome, so… I did!

The LoraWAN device I used bought at AliExpress → Link to the device

The process is super easy. You send a message using LoraWAN and The Things Network, listen to a specific application using MQTT, receive the message and send it to the Tangle using powsrv.io for lightning fast speeds.

I used The Things Network as free backend for receiving the messages. Although you don’t need to run your own gateway at The Things Network to use the network, at ElaadNL we run one.

The gateway at the ElaadNL premises
The data received from the LoraWAN device in The Things Network dashboard

This a visualization of how the message is received, parsed and sent to the Tangle in real time. We use, obviously, NodeJS to connect to the MQTT server of The Things Network and forward the message to the IOTA Tangle.

What does a transaction like that look like when you forward the full JSON message received via MQTT? Like this:

The transaction can be found using TheTangle.org → Transaction

This use case allows for real time data storage in the Tangle, which gives the user an immutable way of data storage. Think about cooling trucks, which have to prove that a certain good is kept below a certain temperature all the time. LoraWAN devices could be used to send the data, the Tangle could be used to store that data in an immutable and secure way. Let me know what kind of use cases you think about in the comments!

Thanks to Ton Smets for helping setting up the demo and hardware.

The LoraWAN device with antenna and FTDI programmer

The magic code

Feel free to use, change, adapt and spread the word!

var ttn = require("ttn")
var usePowSrvIO = require('iota.lib.js.powsrvio')
let IOTA    = require('iota.lib.js');
let seed = 'PLWYXEQISUOXOJCDJ9JBCA9GMPMYBOEPDXRBWVQYXOEDUGSW9AGXTPODSZOJJSAR9GGUMMFXFNQUCWDPK';
let iota = new IOTA({
'host': 'http://node04.iotatoken.nl:14265',
'port': 14265

});
usePowSrvIO(iota, 5000, null)
var appID = "lorawanstoredinthetangle";
var accessKey = "ttn-account-v2.met4bmyI7lGOgTGNKSWpWvCy62aGlKx0OXyV3RrRRv4";
ttn.data(appID, accessKey)
.then(function (client) {
client.on("uplink", function (devID, payload) {
console.log("Received uplink from ", devID)
console.log(payload)
let messageTrytes = iota.utils.toTrytes(JSON.stringify(payload));
var transfer = [
{
'address': 'LORAWANTOTHETANGLELORAWANTOTHETANGLELORAWANTOTHETANGLELORAWANTOTHETANGLELORAWANTOLWXETXGEW',
'value': 0,
'tag': 'LORAWANANDIOTA',
'obsoleteTag': 'LORAWANANDIOTA',
'message': messageTrytes
}
]
iota.api.sendTransfer(seed, 4, 14, transfer, function(e, bundle) {
if (e) throw e;
console.log("Successfully sent your transfer: ", bundle);
})
})
})
.catch(function (error) {
console.error("Error", error)
process.exit(1)
})

🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕

Keep in mind that this proof of concept doesn’t cover full end to end integrity of the data. Adding an additional digital signature at the LoraWAN devices to the message would solve that part. Making use of Masked Authenticated Messaging (MAM) would even make it better and secure!