text - 如何使用GSM模块SIM800和Arduino Uno发送短信?

标签 text arduino sms gsm

我正在尝试通过 SIM800 GSM 模块从 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
  }
}

最佳答案

简单的方法是通过转到 Arduino IDE ->Sketch->Library->Manage Libraries 为 arduino 添加 grps 库 - 然后键入 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
   }

关于text - 如何使用GSM模块SIM800和Arduino Uno发送短信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44839087/

相关文章:

CSS 停止文本大小调整到最底部

php - 将arduino sketch中的另一个数据列添加到mysql数据库中

ios - MFMessageComposeViewController canSendText 类在模拟器上返回 YES

Android:检测短信传出,计数不正确

sms - 我可以从我的电脑向手机发送短信吗?

java - 使用 java html 解析器提取文本

iphone - iOS 7 对文本应用字距调整和行距

macos - 如何在 Mac 上的 IOBluetooth 框架中获取更具描述性的错误

c++ - Arduino IDE 无法检测到 ZumoMotor.H(PIXY PET)

python - 同时读取多个文件的每一行