The class StdService has a stub method shutDown() that is called when the engine stops. Just override it and run close().
On Wed, Dec 22, 2021 at 4:21 PM Seth Ratner <[email protected]> wrote: > 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. > > Here's the service: > https://github.com/lordratner/weewx_gpio_raingauge/blob/main/gpio_rain_service.py > > 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! > > -- > You received this message because you are subscribed to the Google Groups > "weewx-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/weewx-user/6fbe0d9b-1df1-46df-8862-645dfd0fc04an%40googlegroups.com > <https://groups.google.com/d/msgid/weewx-user/6fbe0d9b-1df1-46df-8862-645dfd0fc04an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "weewx-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/CAPq0zEBe712X8ZTpLPCSficepMDnJ0Mc9TNrRwqotFmpPMgS2A%40mail.gmail.com.
