web-dev-qa-db-ja.com

GSMモジュールSIM800とArduinoUnoでSMSを送信する方法は?

SIM800GSMモジュールを介してArduinoからテキストメッセージを送信しようとしています。メッセージは指定された番号に届きますが、正しい形式ではありません。 「メッセージフォーマットはサポートされていません」と表示されます。

私はここに私のコードを含めています、そして速い返事は大いに感謝されます。

#include <SoftwareSerial.h>
SoftwareSerial GPRS(11, 12); //11 = TX, 12 = RX
unsigned char buffer[64]; //port
int count=0;
int i = 0; //if i = 0, send SMS.
void setup() {
  GPRS.begin(9600); // the GPRS baud rate
  Serial.begin(9600); // the Serial port of Arduino baud rate.
  Serial.print("I'm ready");
  Serial.print("Hello?");
}

void loop() {
  if (GPRS.available()) {
    // if date is coming from softwareserial port ==> data is coming from GPRS shield
    while(GPRS.available()) {
      // reading data into char array
      buffer[count++]=GPRS.read();
      // writing data into array
      if(count == 64)
        break;
    }
    Serial.write(buffer,count);
    // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();
    // call clearBufferArray function to clear the stored data from the array
    count = 0; // set counter of while loop to zero
  }
  if (Serial.available())
    // if data is available on hardwareserial port ==> data is coming from PC or notebook
    GPRS.write(Serial.read()); // write it to the GPRS shield
  if(i == 0) {
    GPRS.write("AT+CMGF=1\r"); //sending SMS in text mode
    delay(1000);
    Serial.println("AT+CMGF=1\r");       
    GPRS.write("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // phone number
    delay(1000);
    Serial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r");       
    GPRS.write("Hello how are you?\r"); // message
    delay(1000);
    Serial.println("Hello how are you?\r"); 
    delay(1000);
    GPRS.write(0x1A);
    //send a Ctrl+Z (end of the message)
    delay(1000);
    Serial.println("SMS sent successfully");
    i++;
  }   
}

void clearBufferArray(){
  // function to clear buffer array
  for (int i=0; i<count;i++){
    buffer[i]='\0';
    // clear all index of array with command NULL
  }
}
2
root

簡単な方法は、Arduinoに移動してarduinoのgrpsライブラリを追加することですIDE-> Sketch-> Library-> Manage Libraries-次に、gprsと入力すると、ライブラリを取得してインストールします。このサンプルコードを試してくださいそれをテストするには、

    #include <gprs.h>
    #include <SoftwareSerial.h>

   GPRS gprs;

   void setup() {
     Serial.begin(9600);
     while(!Serial);
     gprs.preInit();
     delay(5000);  //wait for 5 seconds
     while(0 != gprs.init()) {
     delay(1000);
     Serial.print("Not connected,try again\r\n");
    }  
    Serial.println("Sending SMS");
    gprs.sendSMS("844******8","Testing the Module"); //Enter your phone number 
   and text
   }

   void loop() {
    //If you want the to send the Text continuously then add the code here
   }
2
vallabh

次のATコマンド:AT + CSCS =” GSM”をモデムに送信して、モデムの文字セットを「GSM」に設定してみてください。このコマンドを追加した後のコードは次のようになります。

if(i == 0){
    GPRS.write("AT+CMGF=1\r"); //sending SMS in text mode
    delay(1000);
    Serial.println("AT+CMGF=1\r");
    GPRS.write("AT+CSCS=\"GSM\"\r"); //set modem character set to 'GSM'
    delay(1000);     
    GPRS.write("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // phone number
    delay(1000);
1
Torgil