Hello,
I'm trying to implement a "stateful" communication with a serial device. The device is a modem and accepts AT commands. In order not to have the Arduino wait, either by endlessly looping in a function or by waiting a set amount of milliseconds, I decided to code a simple state machine.
Problem is, I'm lost in my code. The device accepts AT commands and responds accordingly (either instantly or after some seconds). The device can also send data when I'm not expecting to, for example when data arrive through TCP/UDP.
This is what I have currently in mind and semi-implemented. That's a simple scenario, most functions will follow the same pattern:
- .begin() is called, Arduino sends the device "AT+WAKEUP", normal execution follows
- some weird interrupt is triggered (or I trigger a .update() function) and a buffer is filled (byte by byte?)
- when the buffer has a specific string in it (+WAKEUP:OKDUDE), I do something (set a variable)
Is that a good way of implementing? How can I implement the buffer? Any ideas or code is highly appreciated.
Thanks!