I have been racking my Brain on how to implement what i am looking to use. Obviously I am using Arduino rather than any of the Node MCU Lua etc,
What I am after:
It will be controlling a machine that I have buttons for but also I want to have an APP on a phone that can control it from anywhere.
I can program Android so that is not a problem and I can have PHP on the web as an api interface.
The Process would be as follows, Device is not paired, It goes into server mode and announces its own SSID, The app would connect to this and would (like an alexa) allow entering of local Wifi credentialsonce it is connected then it will connect to the remote server and register itself along with the APP id so that this device can only be controlled by this current device.
In the case of losing internet the device will try say 10 times at ever growing times and if it still does not connect it will again go into connect mode, however if the device has already registered on the php server then although any app can enter credentials it will revert to the id of the master controlling app when reconnected.
The problem i have is how do i allow the app "using http/s" to instant control the device, I need an almost 0 latency response, someone has suggested make the ESP do a get from the server and when it times out reget, so as soon as the message comes in from the app it can respond, part of the mechanism is an up / down linear actuator and if it doesnt stop in time the carried items could be damaged so I need this level of control possibly from across the globe.
How would be the best way to implement this connectivity and is there any hidden clever way of doing this sort of client-server-client connectivity.