2017-04-03 4 views
1

현재 "Internet of Things"도메인하에 미니 프로젝트를 진행 중입니다. GSM 모듈을 사용하여 무선 게시판을 디자인하기로 결정했습니다.Embedded C에서 GSM 모뎀의 메시지를 읽는 방법은 무엇입니까?

프로젝트를 두 개의 모듈로 나눴습니다. 첫째, 완벽하게 완성 된 Arduino-LED 보드 인터페이스.

둘째, GSM-Arduino 인터페이스. 기본적으로 메시지/SMS가 휴대 전화에서 GSM 모듈로 전송 된 다음 Arduino를 사용하여 GSM 모듈에서 해당 메시지를 읽어야합니다. 나는 여기서 문제를 직면하고있다. 메시지가 GSM 모뎀으로 전송되었지만 읽을 수 없습니다. 다른 코드 작성을 시도했지만 작동하지 않습니다. 메시지가 표시되지 않습니다.

다음은 내가 시도한 코드 단편입니다.

`#include SoftwareSerial.h 

SoftwareSerial SIM900A(2,3);// RX | TX 

// Connect the SIM900A TX to Arduino pin 2 RX 

// Connect the SIM900A RX to Arduino pin 3 TX. 


void setup() 
{ 

     SIM900A.begin(9600); // Setting the baud rate of GSM Module 

     Serial.begin(9600); // Setting the baud rate of Serial Monitor(Arduino) 

     Serial.println ("SIM900A Ready"); 

     delay(100); 

     Serial.println (" Press s to send and r to recieve "); 

} 

void loop() 
{ 

    if (Serial.available()>0) 

    switch(Serial.read()) 

    { 

     case 's': SendMessage(); 
       break; 

     case 'r': RecieveMessage(); 
       break; 

     } 

    if (SIM900A.available()>0) 

     Serial.write(SIM900A.read()); 

} 


void SendMessage() 
{ 

    SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode 

    delay(1000); // Delay of 1000 milli seconds or 1 second 

    Serial.println ("Set SMS Number"); 

    SIM900A.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); //Replace with your mobileno. 

    delay(1000); 

    Serial.println ("Set SMS Content"); 

    SIM900A.println("Hello, I am SIM900A GSM Module");// The SMS text you want to send 

    delay(100); 

    Serial.println ("Finish"); 

    SIM900A.println((char)26);// ASCII code of CTRL+Z 

    delay(1000); 

    Serial.println (" ->SMS Sent"); 
} 


void RecieveMessage() 
{ 

    Serial.println ("SIM900A Receiving SMS"); 

    delay (1000); 

    SIM900A.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS 

    delay(1000); 

    Serial.write (" ->Unread SMS Recieved"); 

}` 
+0

하드웨어가 작동하는지는 알 수 없습니다. 하드웨어 디버깅을 지원할 수는 없습니다. 줄의 범위가 무엇으로 보입니까? – ThingyWotsit

+0

하드웨어가 정상적으로 작동합니다! GSM 모듈에 SIM 카드를 삽입하고 휴대 전화에서 보낼 때 메시지가 수신되는지 여부를 테스트 할 때 완전히 작동합니다. 수신 메시지를 읽는 방법은 문제가있는 부분입니다. GSM에서 메시지를 읽을 수 없습니다. –

+0

'Arduino 인터페이스에서 데이터를 수신 할 수 없다면 어떻게 테스트합니까? – ThingyWotsit

답변

0

당신은 명령을 사용하여 SIM 카드에 선호하는 SMS 스토리지를 설정해야 할 수 있습니다, 또한

SIM900A.print("AT+CPMS=\"SM\"\r"); 

을 설정()로이 명령을 이동 :

SIM900A.print("AT+CMGF=1\r"); 

마지막 주 어떻게 SIM900A.println() 대신 SIM900A.print()를 사용하고 각 명령 다음에 '\ r'또는 0x0d를 보내면됩니다. println()은 "\ n \ r"을 전송하고 일부 모뎀에서는 문제가 발생합니다.

+0

또한 모뎀의 전송 속도가 9600인지 확인해야 할 수도 있습니다. 대부분의 모뎀은이를 구성 할 수 있으므로 다른 값으로 변경되었을 수 있습니다 –