Qqwy

Qqwy

TypeCheck Core Team

Nerves: How to switch between Access Point and WiFi-connection mode while providing an mDNS name?

Hi there! I have asked some slightly related questions on the Nerves Slack channel already, but that is of course not a medium to treat an in-depth question in much detail.

Here is my use case: For a pilot, I am building/programming a raspberry pi, which at its core reads data from a smart electicity meter, and forwards this data to a server.

Since each of these devices ends up in the home of another person, with another WiFi network, it is important to be able to easily set up the correct WiFi connection settings (and also be able to change them later).

So the current idea was to let the Nerves device switch between AP mode and WiFi mode every minute or so, until a successful connection can be made with the configured WiFi settings. As soon as someone visits the Phoenix web-interface where you can configure these settings, the device will stop switching mode until you leave it, to not drop the connection at an inappropriate time.

From the pointers other people already gave me in the Nerves slack channel, I know that the VintageNetWizard exists, which theoretically does more or less this. However, it is currently still missing some features that the system I am building would require:

  1. mDNS support. nerves_init_gadget supports this (although until now I have only been able to make nerves_init_gadget’s mDNS work over an external WiFi and not over Rpi-as-AP) but it conflicts with VintageNet. Another possibility would be a ‘Captive Portal’ (the kind of “log in to wifi” portal that you also see on public WiFi networks) but I have no idea how those are set up (and findinf information about them online proved rather difficult).
  2. Because of the confict with nerves_init_gadget, VintageNet also does not allow e.g. updating firmware over SSH and other quality-of-life improvements to the development phase that I really appreciatae.

So then it seems like I should just use NervesNetwork and build my own simple abstraction for persistence of settings and a web-UI on top of that. However, I have not been able to configure Nerves.Network and Nerves.InitGadget properly to switch at runtime between Rpi-as-AP and Rpi-connected-to-remote-WiFi modes.

It would be really appreciated if someone can help me with the way these libraries ought to be configured for this use case. Especially Nerves.InitGadget seems to mostly be built to be configured in the Mix config files only. However, looking in the code it does seem like its configuration is only applied once a connection is (re)starteed so maybe Application.put_env should be used?

And if you have information on how to solve this problem in any other way, then that would of course also be very welcome! :smiley:

Marked As Solved

fhunleth

fhunleth

Co-author of Nerves

While VintageNet is in development and isn’t ready for general Nerves usage yet, it does work fine with mdns, ssh, and sending firmware updates over ssh.

nerves_init_gadget is really only a library aggregator to make starting out with Nerves easier. It does have a decent amount of glue code to support the USB gadget use case, but it doesn’t sound like you need that.

Entone wrote the mdns support. You can find the ssh firmware update library at nerves_firmware_ssh. Both are configurable independent from nerves_init_gadget and it may even be easier to configure them separately.

As for AP mode configuration, FarmBotOS supports this with nerves_network. I don’t know where the code is offhand, but I think you might be able to search through their repository to find it. However, they are helping out with VintageNet and are migrating over to it since it makes adding some enterprise WiFi features they need easier (and maybe other reasons).

Also Liked

entone

entone

Hey there, I’m the author of the mDNS library. One thing to note is that none of the mobile browsers work with mDNS! It’s very frustrating. They really push you to build an app in their ecosystem to do any sort of local network stuff.

I’ve got a project that does work in the way you are describing, but not with a mobile browser obviously. It’s really quite old code using some of the old networking libraries, probably not worth looking at, but feel free, cicada/lib/network_manager at master · rosetta-home/cicada · GitHub

Basically, you should get an event from SystemRegistry that you have a bound IP address, whether that’s the AP or the DHCP given out from the router, you want to tell mDNS to register your name with that address, or change the registration once it’s authed to the router.

Qqwy

Qqwy

TypeCheck Core Team

Thank you very much for your in-depth reply, @fhunleth!
I’ll probably need some help with the proper configuration of mdns, vintage_net and the other applications that make up Nerves’ new networking stack, but for now this has answered my basic question. Thank you! :heart:

ConnorRigby

ConnorRigby

Nerves Core Team

Following up on this thread check out GitHub - pcmarks/mdns_lite: A simple implementation of an mDNS (multicast Domain Name System) server. · GitHub. It’s a new library that works very well with VintageNet.

EDIT: For those still looking for a nerves_network implementation you can check it out here

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement