Skip to content

Instantly share code, notes, and snippets.

@pdgonzalez872
Last active May 4, 2018 22:34
Show Gist options
  • Save pdgonzalez872/16be5dbee0b43e517ab94747e09a8156 to your computer and use it in GitHub Desktop.
Save pdgonzalez872/16be5dbee0b43e517ab94747e09a8156 to your computer and use it in GitHub Desktop.
Distributed tasks and Nerves

Distributed tasks and Nerves

The idea was to play around with Nerves and put in practice one of the features Elixir has out of the box: connecting to other existing VM instances, or "nodes".

Here is the exercise I was completing: Our first distributed code

Here are the steps I took to make the above work using Nerves (RPi3 and ethernet):

1 - Use the boilerplate project here (HelloNetwork): https://github.com/nerves-project/nerves_examples/tree/master/hello_network

2 - Make the following edits:

  hello_network [master] :> git diff config/config.exs
  diff --git a/hello_network/config/config.exs b/hello_network/config/config.exs
  index 2601e7c..ef69705 100644
  -  mdns_domain: "hello_network.local"
  +  mdns_domain: "hello_network.local", # This needs a comma, I think the formatter removes it :)

  -# address_method: :dhcp,
  -# ifname: "eth0"
  +  address_method: :dhcp,
  +  ifname: "eth0"

3 - Continue to follow the steps on the readme for the boilerplate project

mix firmware
MIX_TARGET=rpi3 mix firmware.burn

4 - Then, thanks to @jschneck, use the following to create a named IEx session with the correct cookie:

iex --name host@0.0.0.0 --cookie "y3//+WLM8CI7g082flQzSDrSFI72BPRDi69Z9rYthm0DtiiYHj7ioY46ibAQJ9+i"`

Your IEx prompt will look like this:

  iex(host@0.0.0.0)1>

Then, you can connect to the target node:

  iex(host@0.0.0.0)1> Node.connect(:"hello_network@hello_network.local")
  true

And verify that you are connected:

  iex(host@0.0.0.0)2> Node.list
  [:"hello_network@hello_network.local"]

Then you can have some fun by passing messages between the nodes.

Notes:

config :nerves_init_gadget,
  node_name: :hello_network,
  mdns_domain: "hello_network.local",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment