Arduino的发送短信在GSM SIM900错误 [英] Arduino sending sms in GSM sim900 error

查看:278
本文介绍了Arduino的发送短信在GSM SIM900错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Arduino兆2560和SIM900 GSM模块。
我接口他们成功,并写入code。它的工作,但我只可以在while循环一次发送1短信。这意味着,当我写一个while循环使用whil​​e循环执行sendsms()的5倍。只有一个短信发送..它停止...

在code是如下:

 的#include< SoftwareSerial.h>
#包括LT&;&STRING.H GT;
SoftwareSerial mySerial(52,53);无效设置()
{
     mySerial.begin(19200); // GPRS的波特率
     Serial.begin(19200); // GPRS的波特率
     延迟(500);}INT X = 0;循环()
{    而(X小于5)
    {
     SendTextMessage();
     X ++;
     } }
无效SendTextMessage()
{
 mySerial.print(AT + CMGF = 1 \\ r);
 延迟(100);
 mySerial.println(AT + CMGS = \\+ 94776511996 \\);
 延迟(100);
 mySerial.println(哎哇);
 延迟(100);
 mySerial.println((char)的26);
 延迟(100);
 mySerial.println();
}


解决方案

您不能只是转储你在AT SIM900与延时100ms命令,并期望它的工作。该SIM900响应AT命令(通常与OK),你应该等待发出下一个命令之前,此响应。您可以忽略这些反应夺路而逃只有当你提供足够的延迟AT命令之间,以确保后SIM900有足够的时间来previous响应一次每个命令只发送。为了使这种快速验证,我想补充的延迟(10000) - 10秒延时 - 在你sendTextMessage()函数的末尾。这将(可能)给SIM900足够的时间移动到下一个前完成SMS传输。

I have an Arduino Mega 2560 and a sim900 gsm module. I interfaced them successfully and written the code. Its working, but I can only send 1 sms at a time in the while loop. That means when I write a while loop to execute the sendsms() 5 times by using a while loop. Only one sms is sent.. and it stops...

The code is below:

#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(52, 53);

void setup()
{
     mySerial.begin(19200);      // the GPRS baud rate   
     Serial.begin(19200);    // the GPRS baud rate 
     delay(500);

}

int x = 0;

loop()
{

    while (x<5)
    {
     SendTextMessage();  
     x++;
     }  

 }


void SendTextMessage()
{
 mySerial.print("AT+CMGF=1\r");
 delay(100);
 mySerial.println("AT + CMGS = \"+94776511996\"");
 delay(100);
 mySerial.println("hey wow");
 delay(100);
 mySerial.println((char)26);
 delay(100);
 mySerial.println();
}

解决方案

You can't just dump your AT commands at the SIM900 with 100mS delay, and expect it to work. The SIM900 responds to AT commands (typically with "OK"), and you should wait for this response before issuing the next command. You can getaway with ignoring these responses only if you provide enough delay between AT commands to make sure that every command is only sent after the SIM900 had enough time to respond to the previous one. To make a quick verification of this, I would add a delay(10000) - a 10 seconds delay - at the end of your sendTextMessage() function. This will (probably) give the SIM900 enough time to complete the SMS transmission before moving on to the next one.

这篇关于Arduino的发送短信在GSM SIM900错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆