4 years, 5 months ago.

Not getting expected result from ATCmdParser::recv using %s parameters

The following code does not work. It results in a failed request from timeout

The problem is the %2s parameter in the call to recv() :

  • If I remove the %2s the call succeeds but obviously I am not reading in any parameters.
  • Or, I can change the %2s to %s but only the first character is read.
  • I have also tried using %c instead of %s for all of the above scenarios but am getting the same results.

How can I read the whole string before the line deliminator ?

Bonus points if you can tell me how to read a string with a space in it !

Broken code

broken code

UARTSerial bus(PB_10, PB_11, 115200);
bus.set_flow_control(Serial::RTSCTS, PB_14, PB_13);
ATCmdParser parser(&bus, AT_DELIMINATOR);

char buffer[10];
parser.send("AT+CPIN?");
if (parser.recv("+CPIN: %2s", buffer))
{
    log->info("[AT+CPIN?] Returned result %s", buffer);
} else {
    log->info("[AT+CPIN?] Request failed");
}

Expected results

The expected result should be one of the following values :

  • READY
  • SIM PIN
  • SIM PUK
  • PH-SIM PIN
  • PH-FSIM PIN
  • PH-FSIM PUK
  • SIM PIN2
  • SIM PUK2
  • PH-NET PIN
  • PH-NET PUK
  • PH-NETSUB PIN
  • PH-NETSUB PUK
  • PH-SP PIN
  • PH-SP PUK
  • PH-CORP PIN
  • PH-CORP PUK
  • PH-MCL PIN
Be the first to answer this question.