From Arduino to Tangle

The full article was originally published by Lewis Daly on Medium. Read the full article here.

A guide to Johnny Five, Arduino and IOTA’s MAM

In my previous post, we started looking into IOTA’s Masked Authenticated Messaging (MAM) module, and how to apply it to a simple pub/sub application.

In this post, we’re going to explore a simple case of getting MAM interfacing with an Arduino, using Johnny Five. This post was inspired by @Chrislaive on Discord, with his great example of MAM and Arduino, which you can find here. Thanks Chris!

Set Up

Aside from the Gists you see below, you can see all of the code for this tutorial here. As always, comments, corrections and pull requests are welcome!

Step 1: Arduino + Johnny Five

First, we need to get johnny five running on the arduino. This is pretty easy to do nowadays. I followed this guide here.

Then, we can run the traditional arduino blink.

https://medium.com/media/9de604eb74bc745ece5a8cc9f4b693d7/href

$ node blink_test.js

Step 2: IOTA and MAM Libs

Ok, now that we can run JS on our Arduino, we need to get the IOTA libs working.

Shout out to @Chrislaive on Discord for the pointer to https://github.com/rwaldron/johnny-five#setup-and-assemble-arduino. We’re going to use this to get us started with the IOTA libs on Arduino and Johnny-Five

Install the required dependencies:

$ yarn add iota.lib.js
$ mkdir lib
#Add the submodule - you don't have to do this if you're working from my code!
$ git submodule add https://github.com/iotaledger/mam.client.js.git lib/mam.client.js

Make a new file called init_test.js

https://medium.com/media/e6e7710b91f38477d9dcb144c2871d06/href

Here, we’re just making sure that we are including our libraries correctly, and initializing IOTA and MAM properly.

$ node init_test.js

Hopefully this should run correctly, and we should see some output about MAM in the console.

From Arduino -> Tangle

Next up, we’re going to try and actually send a message to the tangle. Unfortunately I left all of my cool sensors at home, so the message won’t have any meaning, but we can at least get it working for a later tutorial.

https://medium.com/media/bef042dff128f55840d02ca519237322/href

Here, once the board is ready we send a message of Hello World (in trytes of course) publicly using MAM. The publish function is pretty close to what we did in my last tutorial for reference.

Now I should note here that the code isn’t running on our Arduino, but on our development machine. Once you close the Johnny-Five console, the execution stops. So while this is great for a demo, and Javascript is much more forgiving than C or C++, we need to find another solution to get a network of connected IoT devices publishing data to the Tangle using MAM — which is my ultimate goal.

Stay tuned for my next post, where I look at getting data from actual sensors to the Tangle, without needing to use Johnny Five.

If you enjoyed this post, or have any suggestions or questions, let me know in the comments. If you liked this post, give it a ❤ or a 👏, or whatever you crazy cats are calling it nowadays.

P.S. Donations are always welcome!

BJSLSJNPWSM9QLO9JYJAG9A9LLAUKZAQJGYZLNN9YMBNPCUUS9E9EYE9PIKIKNYHXAPNFAMDGXVIPVKIWGDUVDALPD

Read the full Article

The full article was originally published by Lewis Daly on Medium, where people are continuing the conversation by highlighting and responding to this story.

You might also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More