Distributed Erlang
Introduction
Distributed Erlang lets you join multiple Erlang instances (nodes) together to enable near-transparent message passing in programs, debugging, and remote code updates. This Livebook shows a couple ways of using it with the Nerves Livebook image.
Setup
First, you’ll need to know the name of this node and the cookie.
"My name is '#{node()}' and my cookie is '#{Node.get_cookie()}'."
Now try connecting to this node by running the following command in a shell on your computer:
"iex --cookie '#{Node.get_cookie()}' --name me@myhost.local --remsh #{node()}"
You should get an IEx prompt. Everything you type at that prompt will run on the device and not your computer. To verify this, try running the following:
iex> use Toolshed
iex> uname
Nerves nerves-2e6d nerves_livebook 0.1.0 (9e61db44-bbfd-5430-ab73-daedf5ebce81) arm
Use CTRL-C to exit when you’re done. If you run :init.stop()
, you’ll end up
rebooting the device (probably not what you want).
Remote Livebook
You can run Livebook on your laptop and connect to the device! This is useful if you want to save your code notebooks locally. To do this,
- Follow the Livebook usage instructions and start Livebook running on your laptop.
- Open or create a new Livebook
- Go to Settings -> Runtime and select Attached Node
- Paste in this node’s name and Connect
Observer
Observer is a graphical tool for exploring an Erlang runtime. Connect to this device by first starting IEx on your laptop with the same cookie we’re using here. For example:
"iex --cookie '#{Node.get_cookie()}' --name me@myhost.local"
Then at the IEx prompt, run :observer.start()
. Go to the Nodes menu and
Connect node. Copy in this device’s node name like we found above and the
UI should quickly update to reflect what’s running here.