Build a Weather Station with Elixir and Nerves: %Mint.TransportError connecting from Pi to Phoenix on host

Hi All,

I’ve followed pretty much all of the book so have most of the pieces in place. Really enjoyed it so far!

Running on a rpi4. Using wifi to talk to the rpi4. I can ssh onto and download firmware to the rpi4 no problem. I can’t seem to get measurements off the rpi4 though.

From the log I get this message every 10s when the rpi4 tries to publish the measurements to the Phoenix server on my host machine:

23:31:03.506 [debug] Server response: {:error, %Mint.TransportError{reason: :econnrefused}}

My host machine is Windows 11, with WSL2 running ubuntu. On this machine I start phx.server logs:


graham@DESKTOP-Q3UO4M4:~/weather_tracker$ mix phx.server
warning: use Mix.Config is deprecated. Use the Config module instead
config/config.exs:8

warning: use Mix.Config is deprecated. Use the Config module instead
config/dev.exs:1

[info] Running WeatherTrackerWeb.Endpoint with cowboy 2.9.0 at 0.0.0.0:4000 (http)
[info] Access WeatherTrackerWeb.Endpoint at http://localhost:4000

I’ve set up the http://localhost:4000 in mu config/target/exs as:

config :sensor_hub, :weather_tracker_url,
http://localhost:4000/api/weather-conditions

So I think I have all that correct. But I receive no measurements. When I go on to the rpi4 I only see the messages wit the TransportError.

It feels like a network config problem but I’m new to nerves and elixir would appreciate any advice you have.

Many thanks,
Graham

The timescaledb and postgres look all good - I can send ‘test’ measurements via curl and they are inserted into the DB.

I can also view those ‘test’ measurements in grafana so that side looks OK too.

It just seems to to be the connectivity between the rpi4 and Phoenix on my host PC :man_shrugging:

Hi All,

I figured it out. My dev environment had a network config issue so the Pi couldn’t send the weather-conditions to the Phoenix Server on my dev machine.

In case it helps anyone, here’s what I had to do.

Host dev environment: Windows 11 Home, running WSL2 with an Ubuntu VM.
Target environment: Raspberry Pi 4 running Nerves and sensor_hub firmware.
The Pi 4 and my PC communicated over wifi.

tl;dr - Unlike WSL1, WSL2 provides a virtualized ethernet adaptor with a unique IP address. This means you have to provide a route from Windows to the Ubuntu VM.

David Bombal’s video on the subject explained it really well: WSL 2 Networking - YouTube