Nerves defines an entirely new way to build embedded systems with Elixir that could revolutionize an industry. Imagine booting to the BEAM VM in just a few seconds with your Elixir app in control of the entire system. Nerves makes this possible while replacing the traditional plethora of Linux init scripts or systemd configuration files with a toolchain that is delightful to use. The Nerves philosophy is that you already have a powerful, concurrent language to define what the system should do at start-up time: Elixir. Together, we'll explore the principles Nerves uses to create embedded systems that control 3d printers, power unmanned areal vehicles, and more. You'll see first-hand how Nerves can support service discovery, hot code swapping, and collaboration through PubSub messages and mesh networking. Finally, we will explore the Nerves development life-cycle; from running ExTest, to deployment and hot code reloading.
Talk objectives
* Introduce developing embedded systems in Elixir using Nerves
* Explore the Nerves development life-cycle
* Demonstrate autonomous robotics using service discovery and messaging
* Execute tests, create user interfaces with Phoenix, and perform hot code updates
Target audience
Creating devices and systems which enhance our environment is fundamental to our nature. The exploration into creating hardware that runs Elixir is geared toward the maker in all of us. Join us for an exciting demonstration into the creation of enhanced embedded systems with Elixir and Nerves.
20. WHAT IS NERVES
SUPPORTED TARGETS TARGET NAME
Raspberry Pi B / A+ /B+ / Zero rpi
Raspberry Pi 2 rpi2
Raspberry Pi 3 rpi3
BeagleBone Black bbb
Alix alix
AG150 ag150
Intel Galileo 2 galileo
Lego EV3 ev3
QEmu Arm qemu_arm
27. GETTING STARTED - NERVES PLATFORM
LETS MAKE THIS EASY
# install bake
Bakefile…
bake system get —target
bake toolchain get —target
bake firmware
bake burn
28. GETTING STARTED - NERVES PLATFORM
LETS MAKE THIS EASY
mix deps.get
mix firmware
mix firmware.burn
29. GETTING STARTED - NERVES PLATFORM
MIXING FIRMWARE
YOUR APP
ELIXIR
C CODE
NIF / PORTS
30. GETTING STARTED - NERVES PLATFORM
COMPILING ON YOUR MACHINE
YOUR APP
ELIXIR
C CODE
NIF / PORTS
MIX
BEAM
BINARY
YOUR APP
(ARCH SPECIFIC)
31. GETTING STARTED - NERVES PLATFORM
MIXING FIRMWARE WITH BAKE
YOUR APP
ELIXIR
C CODE
NIF / PORTS
BAKE MIX
YOUR APP
(FOR RPI2)
32. GETTING STARTED - NERVES PLATFORM
MIXING FIRMWARE WITH BAKE
BAKE MIX
YOUR APP
(FOR RPI2)
TOOLCHAIN
SYSTEM
rpi2
33. GETTING STARTED - NERVES PLATFORM
MIXING FIRMWARE
MIX
YOUR APP
(FOR RPI2)
TOOLCHAIN
SYSTEM
rpi2
Precompile
compile
34. GETTING STARTED - NERVES PLATFORM
TOOLCHAINS
TOOLCHAINTOOLCHAIN CONFIG• crosstool
ng
• for target
• host
configs
• compilers
• run on
host
• compile
for target
35. GETTING STARTED - NERVES PLATFORM
TOOLCHAIN CONFIG
CT_LOCAL_TARBALLS_DIR="${CT_TOP_DIR}/../dl"
CT_SAVE_TARBALLS=y
CT_PREFIX_DIR="${CT_TOP_DIR}/../x-tools/${CT_TARGET}"
# CT_REMOVE_DOCS is not set
CT_LOG_EXTRA=y
CT_ARCH_FLOAT_HW=y
CT_ARCH_arm=y
CT_KERNEL_linux=y
CT_KERNEL_V_3_4=y
CT_BINUTILS_LINKER_LD_GOLD=y
CT_BINUTILS_GOLD_THREADS=y
CT_BINUTILS_LD_WRAPPER=y
CT_BINUTILS_PLUGINS=y
…
36. GETTING STARTED - NERVES PLATFORM
SYSTEMS
SYSTEMSYSTEM CONFIG
• buildroot
• defconfig
• rootfs-
additions
• bootfoles
• rootfs
• linux
kernel
41. GETTING STARTED - NERVES PLATFORM
MIX FILE
defmodule Blinky.Mixfile do
use Mix.Project
@target System.get_env("NERVES_TARGET") || “rpi2"
…
end
42. GETTING STARTED - NERVES PLATFORM
MIX FILE
defmodule Blinky.Mixfile do
…
def project do
[app: :blinky,
version: "0.1.0",
archives: [nerves_bootstrap: "~> 0.1"],
target: @target,
deps_path: "deps/#{@target}",
build_path: "_build/#{@target}",
config_path: "config/#{@target}/config.exs",
aliases: aliases,
deps: deps ++ system(@target)]
end
end
43. GETTING STARTED - NERVES PLATFORM
MIX FILE
defmodule Blinky.Mixfile do
…
def system("rpi2") do
[{:nerves_system_rpi2, “~> 0.4.0”}]
end
def aliases do
["deps.precompile": ["nerves.precompile", "deps.precompile"],
"deps.loadpaths": ["deps.loadpaths", "nerves.loadpaths"]]
end
end
44. GETTING STARTED - NERVES PLATFORM
MIX FILE
defmodule Blinky.Mixfile do
…
def system("rpi") do
[{:nerves_system_rpi, "~> 0.4.0"}]
end
def system("rpi2") do
[{:nerves_system_rpi2, “~> 0.4.0”}]
end
def system("rpi3") do
[{:nerves_system_rpi3, “~> 0.4.0”}]
end
…
end
48. FIRMWARE A
GETTING STARTED - NERVES PLATFORM
THE RESULT
linux
erlinit
your_app
readonly
FIRMWARE B
linux
erlinit
your_app
BOOT APPDATA
read/write
EXTRA
readonly readonly
49. FIRMWARE A
GETTING STARTED - NERVES PLATFORM
THE RESULT
linux
erlinit
your_app
readonly
FIRMWARE B
linux
erlinit
your_app
BOOT APPDATA
read/write
EXTRA
readonly readonly
50. FIRMWARE A
GETTING STARTED - NERVES PLATFORM
THE RESULT
linux
erlinit
your_app
readonly
FIRMWARE B
linux
erlinit
your_app
BOOT APPDATA
read/write
EXTRA
readonly readonly
frequent
non
frequent
54. GETTING STARTED - NERVES FRAMEWORK
WIFI
WPA SUPPLICANT IPINTERFACE DETECTION
USB WLAN0 AP CONN CONN EST DHCP
Actor Actor Actor
Initialization Transitions
55. GETTING STARTED - NERVES FRAMEWORK
INTERACTING WITH HARDWARE
{:elixir_ale, “~> 0.4.0”}
{:ok, pid} = Gpio.start_link(1, :output)
Gpio.write(pid, 1)
62. ADVANCED - NERVES FIRMWARE
ADDING FILES TO THE ROOT FILE SYSTEM
config :nerves, :firmware,
rootfs_additions: "config/rpi2/rootfs-additions"
rootfs-additions
|- etc
|- my_utility.conf
ROOTFS
63. ADVANCED - NERVES FIRMWARE
ADDING FILES TO THE ROOT FILE SYSTEM
config :nerves, :firmware,
rootfs_additions: "config/rpi2/rootfs-additions"
rootfs-additions
|- etc
|- my_utility.conf
ROOTFS
64. ADVANCED - NERVES FIRMWARE
CHANGING FILES ON ROOT FILESYSTEM
config :nerves, :firmware,
rootfs_additions: "config/rpi2/rootfs-additions"
rootfs-additions
|- etc
|- erlinit.conf
# Uncomment to hang the board rather than rebooting when
Erlang exits
#--hang-on-exit