I'm using an ESP-01 as a websocket server and it's communicating with an Arduino Nano. It's using software serial. So my client device(phone/web interface) connects and it sends a series of commands like a button being held down.
The software serial is a mess at 115200 baud rate so I just went with single characters/integers and checking/trimming... so I'll send something like this to the ESP: "F, F, F, F, F" at some fixed interval for forward.
While I have checks eg. "last command in progress", the issue is even after my client disconnects/no longer receiving commands, the motion keeps going for a bit(several seconds) then it stops... So I'm thinking maybe the serial input gets built up? I don't know if that even makes sense, or is it just my code is bad? Say I sent 10 F's and it only processed 3 F's so far and client disconnects...
I'm using while (ESPserial.available()) to get my serial data.
The motions are executed in a matter of seconds eg. 3 seconds at worst, the commands update in 40ms intervals so I don't think it's a slow response issue.
I think I got it... the .read() (not flush) and I had to use the ESPserial.read() call. That behaves better now, seems if I give it more time to respond it's more accurate to stop eg. half a second vs. less than a tenth.