ENOMEM in Wireless Plasma Kit demo program

For fun I’ve just got one of those Pimoroni Wireless Plasma Kits (with the star shaped bottle) and am playing around with it.

I noticed quite quickly that the included weather.py program doesn’t work in that it gets an initial weather report but then stays on that one forever after instead of updating every 15 minutes as it is clearly meant to.

Initial investigation shows that the first call to get_data() works, but every subsequent one (issued from a timer thread) fails with an ENOMEM error.

I shall be investigating this myself but I thought I’d mention it here in case anyone had any pointers.

ENOMEM means you’re running out of RAM - are you just running the weather.py example as is or have you made any modifications?

I wonder if it needs some garbage collection (gc.collect()) in there…

EDIT: I’m getting the same error - will try and figure out what’s changed and how to get it to work again :)

The only modification I’ve made is to the latitude and longitude constants.

Perhaps not enough stack in the timer thread? (I’m not familiar with how the internals of Python work).

I’m currently playing with a modified version where the function invoked from the timer merely sets a global flag variable and then the main loop checks that and invokes get_data() again.

Ah no - that fails with the same error.

Does using http instead of https in the URL help?

Yes, that seems to make all the difference. Thank you for your help.

1 Like

Further data point - doing a “gc.collect()” immediately before each attempted data retrieval also seems to make it work, even with the “https:” version of the URL.

I’m not sure of the implications of doing a garbage collection within a timer thread so I have tried this only in my version where the timer thread just sets a flag and then the invocation of get_data() is done from within the main loop.

CORRECTION: no it doesn’t. It works for about three times around, then we’re back to ENOMEM again.

Yeah, I played around with gc.collect() a little but it still seemed to fail a lot of the time with https . I wonder what has changed - pretty sure it was working before. Maybe Openmeteo have changed something on their end?

I’ve updated this example to use http instead! Use http instead of https to avoid memory errors by helgibbons · Pull Request #599 · pimoroni/pimoroni-pico · GitHub