Replies: 2 comments 1 reply
-
See
Why do we dare to create documentation ? Nobody seems to read it. |
Beta Was this translation helpful? Give feedback.
-
The freezing issue you are experiencing when using the urequests library inside a callback function is likely due to the blocking nature of the library. The urequests.post() function blocks the execution until it receives a response from the server, which can cause the ESP to freeze or become unresponsive. To avoid this issue, you can try using the non-blocking version of HTTP requests, such as the uasyncio library, which provides asynchronous capabilities to MicroPython. Here's an example of how you can modify your code to use uasyncio: Function to send dataasync def send_data():
async def main(): Run the event looploop = asyncio.get_event_loop() In this modified version, we use uasyncio to create an event loop and schedule the send_data() function to be called periodically using asyncio.sleep(). The send_data() function is defined as an asynchronous function, allowing it to run concurrently with other tasks. Note that you will need to have the uasyncio and urequests libraries installed on your ESP board. Make sure to install them before running the modified code. By using uasyncio, you can achieve non-blocking behavior and prevent the freezing issue caused by blocking operations in a callback function. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, so here is the issue:
I have a function that send information recollected form a sensor, I need that this funcion to be called in a period bases, for this I am using Timers like this:
tim0 = Timer(0)
tim0.init(period=90000, mode=Timer.PERIODIC, callback=send_data)
I've made some test and it freezes the esp exactly in the "response = urequests.post(url, data=json_data, headers=headers)" line.
Function to send data
def send_data(t):
If i call the function directly from main, as shown below, it works perfectly fine, it seems that the combination of callbacks and urequest have some issues.
#Function main
def main():
Any assistance will be very much appriciated :)
Beta Was this translation helpful? Give feedback.
All reactions