极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10621|回复: 2

请问一下,GSM库给收短信的例子怎么不管用?

[复制链接]
发表于 2013-5-15 10:57:26 | 显示全部楼层 |阅读模式
如题,代码如下,是不是板子的问题?我的是uno r3,模块是gprs v1.1
  1. // include the GSM library
  2. #include <GSM.h>

  3. // PIN Number for the SIM
  4. #define PINNUMBER ""

  5. // initialize the library instances
  6. GSM gsmAccess;
  7. GSM_SMS sms;

  8. // Array to hold the number a SMS is retreived from
  9. char senderNumber[20];  

  10. void setup()
  11. {
  12.   // initialize serial communications and wait for port to open:
  13.   Serial.begin(19200);
  14.   while (!Serial) {
  15.     ; // wait for serial port to connect. Needed for Leonardo only
  16.   }

  17. Serial.println("SMS Messages Receiver");
  18.    
  19.    connection state
  20.   boolean notConnected = true;
  21.   
  22.   // Start GSM connection
  23.   while(notConnected)
  24.   {
  25.     if(gsmAccess.begin(PINNUMBER)==GSM_READY)
  26.       notConnected = false;
  27.     else
  28.     {
  29.       Serial.println("Not connected");
  30.       delay(1000);
  31.     }
  32.   }
  33.   
  34.   Serial.println("GSM initialized");
  35.   Serial.println("Waiting for messages");
  36. }

  37. void loop()
  38. {
  39.   char c;
  40.   
  41.   // If there are any SMSs available()  
  42.   if (sms.available())
  43.   {
  44.     Serial.println("Message received from:");
  45.    
  46.    // Get remote number
  47.     sms.remoteNumber(senderNumber, 20);
  48.     Serial.println(senderNumber);

  49.      //An example of message disposal   
  50.     // Any messages starting with # should be discarded
  51.     if(sms.peek()=='#')
  52.     {
  53.      Serial.println("Discarded SMS");   
  54.      sms.flush();
  55.   }
  56.    
  57.     // Read message bytes and print them
  58.     while(c=sms.read())
  59.       Serial.print(c);
  60.       
  61.     Serial.println("\nEND OF MESSAGE");
  62.    
  63.     // Delete message from modem memory
  64.     sms.flush();
  65.     Serial.println("MESSAGE DELETED");
  66.   }

  67.   delay(1000);

  68. }
复制代码
回复

使用道具 举报

发表于 2013-7-31 13:13:07 | 显示全部楼层
“gprs v1.1”??芯片是M10?
回复 支持 反对

使用道具 举报

发表于 2013-7-31 13:50:15 | 显示全部楼层
那个还没研究到!!楼主分享得好好研究一下.....
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-6 23:47 , Processed in 0.067075 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表