captain-coredump / weatherflow-udp

WeatherFlow Personal Weather Station driver for weewx, via UDP broadcast packets
GNU General Public License v3.0
54 stars 18 forks source link

FreeBSD 12.2 Jail bind() doesn't work with default udp_address #18

Closed piercej closed 2 years ago

piercej commented 2 years ago

I am trying to run WeeWX w/ the Weatherflow-UDP driver in a FreeBSD 12.2 Jail. I installed all the requirements using python3.8, and I have my jail configured so it can use promiscuous mode (this required using VNET, and enabling BPF... before I did this, I couldn't tcpdump the UDP traffic from the weatherflow), but weewx is crashing in weatherflow-udp...

Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: Caught OSError: [Errno 49] Can't assign requested address Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: Traceback (most recent call last): Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: File "bin/weewxd", line 157, in main Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: engine.run() Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: File "/usr/home/weewx/bin/weewx/engine.py", line 208, in run Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: for packet in self.console.genLoopPackets(): Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: File "/usr/home/weewx/bin/user/weatherflowudp.py", line 298, in genLoopPackets Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: s.bind((self._udp_address,self._udp_port)) Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: OSError: [Errno 49] Can't assign requested address Dec 1 01:54:06 weewx2 weewx[49521] CRITICAL main: **** Waiting 10 seconds then retrying...

I'm a novice at python and BSD, but some random googling suggests you have to use a different technique to listen to UDP broadcasts

captain-coredump commented 2 years ago

Have you tried changing either of these options? MacOS is a BSD Unix derivative, and I suspect that 0.0.0.0 is also what works with FreeBSD:

udp_address =

udp_address = 0.0.0.0

# udp_address = 255.255.255.255

This is the broadcast address that we should be listening
on for packets.  If the driver throws an error on start,
try one of the other commented-out options (in order).
This seems to be platform-specific.  All three work on
Debian Linux and my Raspberry Pi, but only 0.0.0.0 works
on my Macbook running OS-X or MacOS.  Don't ask about
Windows, since I don't have a test platform to see
if it will even work.

. . . share_socket = False

Whether or not the UDP socket should be shared with other
local programs also listening for WeatherFlow packets.  Default
is False because I suspect that some obscure Python implementation
will have problems sharing the socket.  Feel free to set it to
True if you have other apps running on your weewx host listening
for WF UDP packets.

--  Sent from my iEtch-a-Sketch via subspace

piercej commented 2 years ago

ahhhh, and that worked!

udp_address = 0.0.0.0
share_socket = False

now getting...

root@weewx2:/home/weewx # bin/weewxd LOOP: 2021-12-01 12:21:12 PST (1638390072) dateTime: 1638390072, maxSolarRad: 469.1360269299783, rainRate: 0.0, usUnits: 1, windDir: 200, windSpeed: 1.7448146445126576 LOOP: 2021-12-01 12:21:15 PST (1638390075) dateTime: 1638390075, maxSolarRad: 469.1139807988268, rainRate: 0.0, usUnits: 1, windDir: 200, windSpeed: 0.49212720742664695 LOOP: 2021-12-01 12:21:18 PST (1638390078) dateTime: 1638390078, maxSolarRad: 469.0919345063639, rainRate: 0.0, usUnits: 1, windDir: 159, windSpeed: 0.8724073222563288 LOOP: 2021-12-01 12:21:22 PST (1638390082) dateTime: 1638390082, maxSolarRad: 469.06247239100963, rainRate: 0.0, usUnits: 1, windDir: 132, windSpeed: 0.7381908111399704 LOOP: 2021-12-01 12:21:23 PST (1638390083) dateTime: 1638390083, maxSolarRad: 469.0550567111635, rainRate: 0.0, usUnits: 1, windDir: 132, windSpeed: 0.2013247666745374 LOOP: 2021-12-01 12:21:26 PST (1638390086) dateTime: 1638390086, maxSolarRad: 469.0328763706615, rainRate: 0.0, usUnits: 1, windDir: 132, windSpeed: 0.06710825555817913 LOOP: 2021-12-01 12:21:29 PST (1638390089) dateTime: 1638390089, maxSolarRad: 469.01062905796977, rainRate: 0.0, usUnits: 1, windDir: 132, windSpeed: 0.022369418519393044 LOOP: 2021-12-01 12:21:32 PST (1638390092) dateTime: 1638390092, maxSolarRad: 468.9883147716301, rainRate: 0.0, usUnits: 1, windDir: None, windSpeed: 0.0 LOOP: 2021-12-01 12:21:33 PST (1638390093) UV: 3.18, altimeter: 30.031705054569453, barometer: 30.017009739797103, cloudbase: 7248.745805803905, dateTime: 1638390093, dewpoint: 48.22551845446283, heatindex: 77.98928000000001, humidex: 80.30552108893059, maxSolarRad: 468.9808989093717, outHumidity: 34.24, outTemp: 78.80000000000001, outTempBatteryStatus: 2.812, pressure: 29.705100325874998, radiation: 393, rain: 0.0, rainRate: 0.0, usUnits: 1, windBatteryStatus: 2.812

thanks much. I was pulling my hair out on this til 2am, but decided to sleep on it before posting.

kevans91 commented 2 years ago

I checked out changing this on FreeBSD to allow <broadcast>/255.255.255.255, but after a bit of reading I think it might be better to just default to 0.0.0.0 globally in this configuration. Linux's ip(7) says this[1] on the matter:

       There are several special addresses: INADDR_LOOPBACK (127.0.0.1)
       always refers to the local host via the loopback device;
       INADDR_ANY (0.0.0.0) means any address for binding;
       INADDR_BROADCAST (255.255.255.255) means any host and has the
       same effect on bind as INADDR_ANY for historical reasons.

<broadcast> = 255.255.255.255 = INADDR_BROADCAST is supported for historical reasons, 0.0.0.0/INADDR_ANY can be inferred from this to be the preferred spelling of it.

[1] https://man7.org/linux/man-pages/man7/ip.7.html