urequests and Raspberry Pi Pico W

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Tabsy21
Posts: 3
Joined: Wed Jul 20, 2022 7:24 pm

urequests and Raspberry Pi Pico W

Post by Tabsy21 » Wed Jul 20, 2022 7:40 pm

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!

tepalia02
Posts: 99
Joined: Mon Mar 21, 2022 5:13 am

Re: urequests and Raspberry Pi Pico W

Post by tepalia02 » Thu Jul 21, 2022 4:06 am

You can try the memory saving tips in python / micropython

Tabsy21
Posts: 3
Joined: Wed Jul 20, 2022 7:24 pm

Re: urequests and Raspberry Pi Pico W

Post by Tabsy21 » Thu Jul 21, 2022 11:17 am

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)

Tabsy21
Posts: 3
Joined: Wed Jul 20, 2022 7:24 pm

Re: urequests and Raspberry Pi Pico W

Post by Tabsy21 » Thu Jul 21, 2022 5:25 pm

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

misan
Posts: 3
Joined: Wed May 05, 2021 6:01 am

Re: urequests and Raspberry Pi Pico W

Post by misan » Wed Aug 24, 2022 11:54 am

Thanks, @Tabsy21, you made my day.

Post Reply