I was having a similar problem with connecting to a raspberry pi with a Nerves project.
Config:
Raspberry Pi Zero 2 W
Windows 11 running WSL2
MIX_TARGET = rpi3a
Using the instructions from the “Build a Weather Station with Elixir and Nerves”
The main issue was that I was unable to ping or ssh to the device over USB. I tried multiple USB cables, confirmed I was using the gadget port (not the power only port), tried another firmware file (circuits_quickstart_rpi3a.fw) from GitHub - elixir-circuits/circuits_quickstart: Try out Elixir Circuits on Nerves!, all unsuccessfully.
I also tried several attempts at getting mDNS/zeroconf/Bonjour working on both WSL2 and Windows 11, which I thought might be part of the problem. I learned some things, but didn’t solve the problem.
One solution proposed here seemed promising, which was to set the NERVES_WIFI_SSID and _PASSWORD as env variables or pass them as arguments to fwup. However, due to how WSL2 works, with limited access to MicroSD cards, mix burn
passes this off to fwup.exe on the Windows side, so the arguments and env vars are not honored, as far as I can tell.
My solution was to configure WiFi in advance, before creating the firmware file, by updating config/target.exs in the project. By adding my wireless ssid and psk to the wlan0 section, the RPi pulled an address through dhcp and I could ssh/ping it over WiFi.
This is basically the instructions from the book mentioned above and the VintagetNetDirect site (GitHub - nerves-networking/vintage_net_wifi: WiFi networking for VintageNet), doing it before you burn the firmware.
To be more explicit, assuming you have the “sensor_hub” project from the book all set up, edit the config/target.exs file ensuring it has a section that looks like this (there might be other interfaces in there, like usb0 and eth0, that’s fine:
config :vintage_net,
config: [
{"wlan0",
%{
type: VintageNetWiFi,
vintage_net_wifi: %{
networks: [
%{
key_mgmt: :wpa_psk,
ssid: "my_network_ssid",
psk: "a_passphrase_or_psk",
}
]
},
ipv4: %{method: :dhcp},
}
}
]
Then run mix firmware
and mix burn
as usual. Swap the SD card to the pi. In my case it has a steady green LED. I checked my router for devices pulling addresses and after a tense few moments, “nerves-8821” showed up on my network, and was able to ssh to the device.
I hope that helps someone else.