Page 1 of 1

urequests and Raspberry Pi Pico W

Posted: Wed Jul 20, 2022 7:40 pm
by Tabsy21
Hello,

I would like to build a Telegram chatbot on the Raspberry Pi Pico W. This should only be able to send sensor values and not process incoming messages. I know that this Pi is not quite suitable for this, but maybe someone can help me with this problem.

To send a message I wrote this:

Code: Select all

requests.post("MyURLForTelegram")
This works fine, but every time after 4 sent messages this error comes up:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 25, in <module>
  File "urequests.py", line 120, in post
  File "urequests.py", line 62, in request
OSError: [Errno 12] ENOMEM
I found out that this error means that the RAM is full. I tried to clear the RAM after each message sent with this piece of code:

Code: Select all

def clearram():
    gc.collect()
    gc.mem_free()
This worked with a request from another URL where the same error came up after a few requests. After I implemented the clearram() this error did not come with the other URL any more. But with the Telegram URL this error still comes unchanged after 4 sent messages.

I am grateful for any help!

Re: urequests and Raspberry Pi Pico W

Posted: Thu Jul 21, 2022 4:06 am
by tepalia02
You can try the memory saving tips in python / micropython

Re: urequests and Raspberry Pi Pico W

Posted: Thu Jul 21, 2022 11:17 am
by Tabsy21
tepalia02 wrote:
Thu Jul 21, 2022 4:06 am
You can try the memory saving tips in python / micropython
I do not know how I can optimize the memory, because the only thing what the code does is to request the URL in a while loop and after every request sleep(3) (to test how many messages I can send without an error)

Re: urequests and Raspberry Pi Pico W

Posted: Thu Jul 21, 2022 5:25 pm
by Tabsy21
I have solved the problem with this line of code:

Code: Select all

response = requests.post("MyTelegramURL")
 response.close()
Thanks anyway for the effort :D

Re: urequests and Raspberry Pi Pico W

Posted: Wed Aug 24, 2022 11:54 am
by misan
Thanks, @Tabsy21, you made my day.