You must always explicitly enable all the different UR codes you want to listen to on a specific given serial interface. If you have several serial interfaces open and run AT+CNMI=2
on one of them you cannot assume that +CNMI: ...
will occur on any other interfaces than the on that ran the AT+CNMI command. Assume nothing is remembered if you open, close and then reopen.
So, in your code above, add a call to write AT+CNMI with the mode you want, and then read and parse everything you get back from the moden until you get the OK
final result code before continuing with the code expecting to receive +CNMI: ...
UR codes. (BTW you should rather use readLine
than readAll
since AT command responses should always be handled line by line.)