Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: Weird characters when parsing incoming SMS SM5100B-D on: May 02, 2012, 06:23:35 pm
Thanks - I'm new to the Arduino scene so a bit in the deeper end but i have a good knowledge of programming so its more the actual interfacing and how its all handled.
2  Using Arduino / Networking, Protocols, and Devices / Re: Weird characters when parsing incoming SMS SM5100B-D on: May 01, 2012, 07:04:58 am
Is there a better way i can handle an incoming message then?
3  Using Arduino / Networking, Protocols, and Devices / Weird characters when parsing incoming SMS SM5100B-D on: May 01, 2012, 04:02:35 am
Hi guys,

Recently got myself a Uno and a SM5100B-D GSM which i've got successfully calling and hanging up. Done the same with SMS but now i'm wanting to read incoming messages.

I've found a few bits and pieces around and came across this:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294527225

Code:
/* Cellular shield code, by Phil Gordon http://mrphilipgordon.com
 This code assumes a pull down pushbutton switch attached to pin 9.

 Code expects text in the format x,number1,number2 with number1 being either 1 or 2.

 It will store number2 in a variable depending on number 1.

 Values of variables will be printed on press of pushbutton attached to pin 9

 */




#include <NewSoftSerial.h>         //Include the NewSoftSerial library to send serial commands to the cellular module.
NewSoftSerial cell(2,3);           //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

char c = 0;                        //Will hold the incoming character from the Serial Port.
int ATReady = 0;                   //Cellular shield ready
char module1[128];                 //Value for module1
char module2[128];                 //Vue value for module2
int index;                         //Array index
long lastPress = 0;                //For debounce pushbutton
long debounceDelay = 500;          //Delay between represses             


void setup()
{
  Serial.begin(9600);              //Initialize serial ports for communication.
  cell.begin(9600);
  Serial.println("Starting SM5100B Communication...");
}

void loop() {
  if(cell.available() >0)           //If a character comes in from the cellular module...
  {
    c=cell.read();                  //Get the character from the cellular serial port.
    Serial.print(c);                //Print that character to serial monitor
    if(c == '+')                   
    {
      c=cell.read();
      Serial.print(c);
      switch(c)
      {
      case 'S':
        c=cell.read();
        Serial.print(c);
        delay(10);
        c=cell.read();
        Serial.print(c);
        delay(10);
        c=cell.read();
        Serial.print(c);
        delay(10);
        c=cell.read();
        Serial.print(c);
        delay(10);
        c=cell.read();
        Serial.print(c);
        delay(10);
        c=cell.read();
        Serial.print(c);
        switch(c)
        {
        case '3':                                  //Check for initiallisation statud, waiting for command
          Serial.print("\n \rAlmost there...");    //  +SIND: 4
          break;
        case '4':
          Serial.print("\n \rNetwork established");
          ATReady=1;                 
          cell.println("AT+CMGF=1");               //Set message mode to text
          cell.println("AT+CNMI=3,3,0,0");         //Display messages when received
          break;
        case '7':
          Serial.print("\n \rSomething b0rked");
          ATReady=0;
          break;
        }
        break;
      case 'C':
        c=cell.read();
        Serial.print(c);
        delay(10);
        if(c == 'M')
        {
          c=cell.read();
          Serial.print(c);
          delay(10);
          if(c == 'T')
          {
            while(c != 'x')            //Wait untill the character 'x' is displayed
            {
              c=cell.read();
              Serial.print(c);
            }
            c=cell.read();
            Serial.print(c);
            delay(10);
            c=cell.read();
            Serial.print(c);
            switch(c)
            {
            case '1':                  //Run this code if number1 is a 1
              index=0;                 //Reset array index
              c=cell.read();
              Serial.print(c);
              delay(10);
              c=cell.read();
              Serial.print(c);
              while(c != '\r')         //Run loop till end of the line
              {
                module1[index] = c;    //Add character to the array
                c=cell.read();
                Serial.print(c);
                index++;               //Advance array
              }
              module1[index]='\0';     //Terminate array
              break;
            case '2':
              index=0;
              c=cell.read();
              Serial.print(c);
              delay(10);
              c=cell.read();
              Serial.print(c);
              while(c != '\r')
              {
                module2[index] = c;
                c=cell.read();
                Serial.print(c);
                index++;
              }
              module2[index]='\0';             
              break;       
            }

            break;
          }
        }
      }
    }
  }
  if(Serial.available() >0)              //If a character is coming from the terminal to the Arduino...
  {
    c=Serial.read();                     //Get the character coming from the terminal
    cell.print(c);                       //Send the character to the cellular module.
  }

  if (digitalRead(9) == HIGH && (millis() - lastPress) > debounceDelay)   //stop button repeatedly sending commands.
  {
    lastPress = millis();
    Serial.println();
    Serial.print("Module1: ");
    Serial.println(module1);
    Serial.print("Module2: ");
    Serial.println(module2);
  }

}

It works fine, until a message comes in and in the serial window i see

Code:
+CMT: "+642********","+642********","12/05/01,21:00:56+00",4
Test
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

Then the ÿ characters keep spamming and eventually freezes up.
Pages: [1]