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.

$ 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 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 lib/mam.client.js

Make a new file called init_test.js

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.

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!


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