Hi everyone.
I have WeeWX set up on a Raspberry Pi with the GW1000 driver. I'm also using a service I wrote to add a wired rain gauge to the GPIO pins using the gpiozero library.
The setup is on the bitter edge of a wifi network, so the components drop in and out of the connection. When the GW1000 drops out, WeeWX tries three times to query it, then seems to shutdown the loop:
ERROR user.gw1000: Unable to obtain live sensor data
INFO weewx.engine: Main loop exiting. Shutting engine down.
INFO weewx.engine: Shutting down StdReport thread
DEBUG weewx.engine: StdReport thread has been terminated
INFO user.gw1000: Gw1000Collector thread has been terminated
CRITICAL __main__: Caught WeeWxIOError: Failed to obtain response to command 'CMD_GW1000_LIVEDATA' after 3 attempts
CRITICAL __main__: **** Waiting 60 seconds then retrying...
It then goes through the whole process of launching the engine. When it gets to my service:
DEBUG weewx.engine: Loading service user.gpio_rain_service.GpioRainGauge
The service throws an error when it tries to reinitialize the GPIO pin. The pin is still set in gpiozero from before the loop exited, and you can't set a pin twice.
How can I make my service run the close() process when the main loop is exited? This would free up the pin to be reassigned when the loop restarts.
Thanks!