Nicd

Nicd

Nerves app structuring

I have an app structuring question regarding Nerves. First I’ll generally describe my app on a high level.

I’m making a game where RFID readers will play an integral part. The game consists of many devices (different kinds of Raspberry Pi) acting as a network and synchronising game state together. There are initially three types of devices:

  1. Player device: This is worn by the player and contains an RFID reader. Each player also has an RFID tag in their hand. The player device connects to the others with WiFi. If the RFID reader detects another player’s code, that player has tagged the wearing player and the wearing player’s tag will be disabled from affecting other players (by communicating this to all other players). Then that player must go to read their tag at a respawn station to reactivate their tag.
  2. Respawn device: This is stationary somewhere and will connect via Ethernet most likely. When the respawn station’s RFID reader detects a tag, it should communicate to all the devices that that player’s tag is active again.
  3. “Judge” that coordinates the whole game. This device should also offer a web page probably with Phoenix that can be used to set up and follow the game. Another feature could be permanent storage of game info to PostgreSQL/SQLite for example.

Now my issue is, how should I structure my code? The two first devices are similar enough, but the third would also have Phoenix and maybe other stuff, but it still needs the game coordination code that is common to all three. I know of umbrella applications but I thought they are not the solution if you only want to start part of the applications in some environments, or am I wrong?

Most Liked Responses

outlog

outlog

1 & 2 could(should?) be simple clients that have a socket connection open to 3 (perhaps with GitHub - J0/phoenix_gen_socket_client: Socket client behaviour for phoenix channels · GitHub).. so they could share code and configs would decide if it was respawn for gameX or playerX for gameX..

you will face and be fighting latency issues - player A tags B, and then B tags A - however wifi latency etc. can change the order of those messages. so you will need to timestamp the event messages on the device.. (you might need a device with RTC or add it to the board Breakout Boards, Clocks Products Category on Adafruit Industries - so clocks don’t drift)..

and even then you still need logic on the ‘judge’ if a tag event comes in it should wait x ms to see if another and contrary event comes in - and then decide based on the timestamps if A gets the tag or not.

mnesia doesn’t solve this logic so I would not venture there. start with ets and then you can always lazily persist things to sqlite etc.

also you will face rfid latency.. you might have to use battery assisted tags..

outlog

outlog

ok, maybe go with this Add simple Erlang Distribution example to `hello_network` by GregMefford · Pull Request #71 · nerves-project/nerves_examples · GitHub
hardcode the ‘judge’ node in a config
and then after the :net_kernel.start([node_name]) you can do the node.connect to judge

and then a single genserver, and the judge can dynamic config that a device should be a ‘respawn’ or ‘player_x’ (kept in genserver state) - and the devices then does remote calls to the judge according to their state and events..

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement