I saw in an oldish forum thread that trying to call TCPClient.connect() from a threaded function will not work on the electron (but for some reason will work on the photon?). I suppose this means that you have to call the TCPClient.connect() from the main loop function (which means the main loop will be blocked while this happens).
Would it be possible to write a facade/wrapper class for the TCPClient? Lets call it TCPWrapper for example, containing a TCPClient tcpClient member object. Could I have functions such as TCPWrapper::connect() which checks if a boolean TCPWrapper::tcpBusy is set to true, and if so blocks until false, at which point we set the boolean to true , then call TCPWrapper::tcpClient.connect(), then set the boolean to false and return the result?
The same sort of thing will be written for all the necessary functions of TCPClient like write, read etc. Basically if any other thread/function etc is already doing something with the tcpClient the wrapper function will block the caller until nothing is using the tcpClient.
I’m hoping this will allow me to call all the wrapper functions from any thread.
Is this possible or is there some intrinsic thing about the class in spark_wiring_tcpclient.h that doesn’t allow this?
I’m currently halfway through writing it, but I’m concerned that some indeterminate error will pop up and it will be because of some intrinsic RTOS/ Particle OS thing which is quite hard to debug on the electron.