gus
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!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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
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
This is a bold statement, do you have any sources that can confirm this?
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
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
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
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
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_binaryas mentioned by @D4no0. If I run into any while testing though, I’ll be sure to update here!gus
Horde.Registrylooks 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 theMIX_TARGETthe code was compiled for - see below:It would be nice to have that functionality available in a lightweight way - ie, only have the changes apply on the host side
gus
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?