Working around TCP communication blocking loop()

So I’m trying to get the Electron to send a POST request using the TCPClient whenever an event is detected. My issue is with the communication blocking the main loop, which checks for events, until the HTTP response is received.

I’ve thought of either using a software timer to periodically send batches of requests, which doesn’t really resolve the issue, or to somehow incorporate threading. However, there doesn’t seem to be too much information on multithreading on the Electron. Can somebody lend a hand?

TCPClient and TCPServer cannot be used from the non-loop thread on the Electron, so you can’t call it from a software timer or a separate thread. You’ll immediately SOS fault, so that’s not going to work as a solution.

Though only the TCPClient connect() method is blocking, however. As long as you connect using an IP address instead of a hostname it usually only takes at most a few seconds.

Or you can put all of the other code into a thread, I suppose.