Strange character received by MKR1400 GSM during sms.read()

I have the MKR1400 GSM up and receiving text messages. At the end of every text, I get a strange character that I can't seem to find on the character map or make any sense of in the SARA U201 chipset documentation within the AT+CMGL data specification section.

I am able to copy the character from PuTTy: ▒

Code:

void loop() {

 char c;
 char string1[20]="";
 int i=0, j=0;
 
 Serial.println("Made it to loop()");
  // Check the sms object to see if any SMS messages are ready to receive.
  if (sms.available()) {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal
    // Any messages starting with # should be discarded
    if (sms.peek() == '#') {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while ((c = sms.read()) != -1) 
    {
      string1[j]=(char)c; 
      Serial.print((char)c);
      if(!isalnum((char)c)){
        j=0;
        break;
      }
      j++;
    }
    
    if (string1=="1234")
    {
        Serial.println("Received PIN of 1234"); 
    }
    else
    {
      Serial.print("String was: "); 
      Serial.println(string1); 
    }

/*
 * --------MAKE SMS COMMANDS CASE INSENSITIVE----------/
 * int i = 0;
   
   while(string1[i]) {
      putchar (toupper(string1[i]));
      i++;
   }
 * 
 * ----------------TRIGGERING SECTION -----------------/
 * if(!(strncmp(c,"SAUSAGE FEST",12)))
    {
      digitalWrite(ACTUATOR_PUSH, LOW);
      digitalWrite(ACTUATOR_PULL, HIGH);
      delay(2000);
      digitalWrite(ACTUATOR_PULL, LOW);
    }  
   
   else if(!(strncmp(str,"RESET",5)))
    {
      digitalWrite(ACTUATOR_PULL, LOW);
      digitalWrite(ACTUATOR_PUSH, HIGH);       
      delay(2000);
      digitalWrite(ACTUATOR_PUSH, LOW);
    }
    else 
    {
    Reply with invalid command SMS.
    }
 */

    Serial.println("\nEND OF MESSAGE");

    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
    
  }

  
  Serial.println("Unavailable SMS, but looping.");
  delay(5000);
  

}

Some things to note:

1.) It does not show up in the message text when sms.available() echos the results of the AT+CMGL="REC UNREAD" command to the terminal, but rather after I start typecasting it in as a character from the returned byte out of sms.read().

2.) I have to throw alphanumeric detection in there, or else it will spam the bejesus out of my terminal with these strange characters and run repeatedly in the sms.read() while loop shown above.

3.) Am I doing anything inefficiently here with the message storage/manipulation going into the character array? I am still reacquainting to C syntax.

4.) As a context for this project, I am trying to get string1 to be the string I parse to read text commands sent to this device. The strings would ideally be a command, some data, then possibly a security code. It seems as though I should be breaking these up into array elements after parsing a space character.

Thanks

  1. Areyou reading directly (TTLout->TTLinput) or is there any transmission line (RS422...)?
  2. Did you try to print to monitor the ASCII number of this character?

Just realized I hadn’t attached this, an image of the terminal when running.

demkat1,not sure if this answers your questions, but:

1.) I am just utilizing the COM9 port via the USB connection to the controller.
2.) Not yet. Using an online string to ASCII converter, I get ‘226 150 146’. I will attempt this in the code.

arduino_putty.png

I think that you are running into unprintable message terminators for the sms text. If you knew the actual terminators, the reading routine could be modified to deal with them.
However, it looks like your use of !isalnum((char)c) is adequately finding whatever it is.

I would modify your reading routine to terminate the message string when the unprintable character is found. Try

while ((c = sms.read()) != -1)
{
  string1[j] = (char)c;
  //Serial.print((char)c);
  if (!isalnum((char)c)) {
    string1[j] = '\0'; 
    j = 0;
    break;
  }
  Serial.print((char)c);
  j++;

}

This syntax is not correct. You need to use strcmp().

if (string1=="1234")