I am trying to implement a rpc service that sends data to an uart and then wait for the response but I have no idea how to “wait” without blocking the event loop.
You have a few options. First, you wouldn’t go into a loop waiting for data from the UART. You would have a big loop for the entire app. Each time through you would check the see if data is available and process it. In the Arduino world, the textbook example is called “blink without delay” which is the same concept. Try to google that.
Another option is to make a separate task to process incoming data. You can use FreeRTOS for this. I’ll post an example in a separate thread of how to use FreeRTOS.
thanks for your anwser, I am used to work with event loops but in this case I am using http as rpc mechanism for mongooseos and I need to send back the answer, that’s where i am. I tried keeping a pointer on the struct mg_rpc_request_info * structure to answer in the uart read callback but it got me a core panic :x
I searched and looked at “blink without delay” but I fail to see how it help me here
nevermind I have it running, I got the core panic because I responded twice to the same mg_rpc_request_info.
What I am doing is: send the request & save the mg_rpc_request_info * associated with the request I sent and in the read handler for the uart I respond to the query when I get the result.