gus

gus

Nerves Core Team

Hey all, happy 2024!

I think I have on my hands a configuration and OTP problem - I’m pretty sure I have all the pieces, just not sure how to put it together.

I have a Nerves device which is connected to a sensor. I have created a GenServer to read the sensor periodically, save the data and provide it upon a caller’s request. This device also a has a LiveView UI which graphs the value of the sensor over time. This all works great on the device.

Where it breaks down is in development - I want to be able to develop the UI on my local machine, but use live data by calling the GenServer running on the device. I have enabled epmd and can connect to the remote node through iex, but now I’m trying to figure out how to ‘re-route’ all of the calls to the sensor GenServer to the Nerves device when running the application on the host.

I am considering two approaches to this problem. First, GenServer will accept any name registration as outlined in the docs, including processes on remote nodes. I think I could look up the remote PID on application start, and store that in application config for use later. As a second approach, I think there should be a way to use Registry or :global to lookup the correct process to direct the requests to.

Are there any recommendations on how to best do this?

Thanks!

Showing Posts 1 to 10

hubertlepicki

hubertlepicki

Is the device you deploy Nerves on, and your workstation have similar CPU architecture, i.e. both are ARM or both are Intel CPU instruction based? I never tried if it actually is a problem, but endianness may be a problem Endianness - Wikipedia if you try talking between x86 and ARM64 nodes in the cluster.

hubertlepicki

hubertlepicki

But answering your question, you can use Horde, and in particular Horde.Registry Horde.Registry — Horde v0.10.0 to register the Pids of all the GenServers in the cluster and then use it just like normal Registry to find those Pids. The APIs are the same. I am using it in the homogenous cluster of the same machines and it works great, again, I am not sure if the endianness won’t mess it up.

D4no0

D4no0

This is a bold statement, do you have any sources that can confirm this?

tj0

tj0

Also curious about the endianness, as I’ve only done homogeneous clusters, but I wouldn’t have thought it would be an issue as it is being packed by BEAM.

For instance, I had to receive/decode a packet from an Erlang machine and it took me a minute to realize that the packet header (2-bytes to indicate the size of the packet) was in big-endian format.

hubertlepicki

hubertlepicki

No, and it’d be interesting to see what works and what doesn’t work.

I am mentioning it because I saw the erlang/elixir code explicitly handling endiness in some blog posts about handling data from smart sensors, and I suspect that the distribution protocol will handle it just fine but the payloads you send between nodes may require conversion. For example: Smart Sensors with Erlang and AtomVM: Smart cities, smart houses and manufacturing monitoring - Erlang Solutions

D4no0

D4no0

Well that is another question.

I am not entirely sure, but my thinking is that inter-node communication is using functionality from term_to_binary, there seems to be a more comprehensive documentation here: External Term Format — OTP 29.0.2 (erts 17.0.2)

sleipnir

sleipnir

Hi.
Maybe the Spawn project GitHub - eigr/spawn: Spawn - Actor Mesh · GitHub (I’m a co-creator) can help you. If you need, you can open a discussion in the repository and we’ll continue there. Or on our discord channel (link in repo).

gus

gus OP

Nerves Core Team

Hey thanks for the suggestion! While I am on different architectures (ARM Raspberry Pi 3 vs Intel Mac), I haven’t run into endianness as an issue yet. I do have to be careful about endianness when reading the sensors, because each one is different according to its own data sheet. However, when sending messages between BEAM nodes I haven’t had any issues. I assume that it is taken care of by term_to_binary as mentioned by @D4no0. If I run into any while testing though, I’ll be sure to update here!

gus

gus OP

Nerves Core Team

Horde.Registry looks like a decent option. I do notice that it looks like I would have to structure my whole application around using their registry instead of the built-in one. I’d like to avoid that, but it would work for debugging purposes.

What I was thinking is that for Nerves application.ex, we have a pathway to configure different supervision trees based on the MIX_TARGET the code was compiled for - see below:

defmodule MyApp.Application do
  @moduledoc false

  use Application

  @impl true
  def start(_type, _args) do
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]

    children =
      [
        # children for both targets here
      ] ++ children(target())

    Supervisor.start_link(children, opts)
  end

  # List all child processes to be supervised
  def children(:host) do
    [
      # children for host

      # possible to do some sort of "remote" sensor here?
      {MyApp.Sensor.Remote, node: "nerves@nerves.local"}
    ]
  end

  def children(_target) do
    [
      # children for targets
      {MyApp.Sensor, polling_interval: 1_000}
    ]
  end

  def target() do
    Application.get_env(:my_app, :target)
  end
end

It would be nice to have that functionality available in a lightweight way - ie, only have the changes apply on the host side

gus

gus OP

Nerves Core Team

Looks interesting! I’ve not heard of the project before. After a Quick Look through the docs though, it looks a little more heavy-weight than I think I need in this situation? I don’t have a DB and not using Kubernetes. Was there a specific module in the project you think would help that I can look deeper into?

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews