Customizing IEx for Elixir Nerves target device

Search for a command to run...

I wrote a script called phx-docker-compose-new that can be used instead of mix phx.new to generate a new Phoenix application. Building the development environment for a Phoenix application using Docker Compose is convenient because you can set up not...
この記事について Raspberry Pi、TensorFlow、Pythonのいずれにも詳しくない筆者が、物体検出をやって楽しんだ成果の記録です。 TensorFlow公式の物体検出のサンプルプログラムを実行します。 動作環境 ボード Raspberry Pi 4 Model B OS Raspberry Pi OS (32-bit または 64-bit) デスクトップ環境 カメラ Raspberry Pi カメラモジュール v2 Python Python ...
One day I was trying to upgrade one of my Phoenix 1.5 apps to Phoenix 1.6. In that app, I customize Bootstrap styles using SCSS. I want to talk about what I found and stumbled on when setting up SCSS. TIL All explained in Phoenix 1.6 Asset Managemen...
This is written in Japanese. I might convert it to English later, maybe. はじめに Elixirのテストでモックを用意するときに利用するElixirパッケージとして、moxが人気です。Elixir作者のJosé Valimさんが作ったからということもありますが、ただモックを用意するだけではなくElixirアプリの構成をより良くするためのアイデアにまで言及されているので、教科書のようなものと思っています。 一言でいうと「その場...
TIL Access supports keyword lists (Keyword) and maps (Map) out of the box, but not structs. There is a reason why Elixir does not implement Access behaviour for structs. Perfer data.key for accessing predefined atom keys of map or struct. Access be...
Today I talk about how I customize things that are printed when shelling into a Nerves target board (e.g., Raspberry Pi Zero W).

rootfs_overlay/etc/iex.exs file in your Nerves project directory.Here is an example.
IO.puts("""
\e[34m████▄▖ \e[36m▐███
\e[34m█▌ ▀▜█▙▄▖ \e[36m▐█
\e[34m█▌ \e[36m▐█▄▖\e[34m▝▀█▌ \e[36m▐█ \e[39mN E R V E S
\e[34m█▌ \e[36m▝▀█▙▄▖ ▐█
\e[34m███▌ \e[36m▀▜████\e[0m
""")
# Add Toolshed helpers to the IEx session
use Toolshed
if RingLogger in Application.get_env(:logger, :backends, []) do
IO.puts("""
RingLogger is collecting log messages from Elixir and Linux. To see the
messages, either attach the current IEx session to the logger:
RingLogger.attach
or print the next messages in the log:
RingLogger.next
""")
end
# Print information about the running system
IO.puts("")
uname
# Print information about the connected I2C devices
if Code.ensure_loaded?(Circuits.I2C) do
IO.puts("")
Circuits.I2C.detect_devices()
end
# Print information about local weather
try do
IO.puts("")
weather()
rescue
exception -> nil
end
# Alias some modules to save typing later on
alias HelloNerves.Worker
.iex.exs file in ElixirIt is a script that is loaded when IEx is started. For details, IEx documentation has a section that explains the iex.exs file.
.iex.exs file in Nerves target deviceThe template for the .iex.exs file is defined in nerves_bootstrap.
When we make a new Nerves project running the mix nerves.new command, that .iex.exs template is copied into the project's rootfs_overlay/etc directory.
The Nerves logo Ascii art was added in this PR in February 2021 so if you have any Nerves projects that are created before that, you do not see the logo in the IEx. In such a case you can manually paste the Ascii art into your rootfs_overlay/etc/.iex.exs file.
We can do whatever we want in our rootfs_overlay/etc/.iex.exs file, but here are some ideas I came up with.
weather/0, uname/0Circuits.I2C.detect_devices/0.weather/0 required the Internet connection. Please make sure that :inets is added to extra_application in your mix.exs file.
def application do
[
mod: {HelloNerves.Application, []},
extra_applications: [:logger, :runtime_tools, :inets]
]
end
That's it!