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

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

问题描述

我有一个 Arduino Mega 2560 和一个 sim900 gsm 模块.我成功地连接了它们并编写了代码.它可以工作,但我只能在 while 循环中一次发送 1 条短信.这意味着当我编写一个 while 循环来使用 while 循环执行 sendms() 5 次时.只发送一条短信..它停止了......

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...

代码如下:

#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();
}

推荐答案

您不能仅仅以 100 毫秒的延迟将您的 AT 命令转储到 SIM900,并期望它能够工作.SIM900 响应 AT 命令(通常为OK"),您应该等待此响应,然后再发出下一个命令.只有在 AT 命令之间提供足够的延迟以确保每个命令仅在 SIM900 有足够的时间响应前一个命令之后才发送,您才可以忽略这些响应.为了快速验证这一点,我会在 sendTextMessage() 函数的末尾添加一个 delay(10000) - 一个 10 秒的延迟.这将(可能)让 SIM900 有足够的时间完成 SMS 传输,然后再进行下一个.

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天全站免登陆