Arduino GSM短信和GPRS - Xively。不能同时进行

时间:2013-08-15 12:26:49

标签: sms arduino gsm gprs xively

嗨Arduino初学者在这里。

我正在使用官方Arduino GSM模块的Arduino UNO R3。 IDE 1.0.5。

我正在尝试将数据上传到Xively,但也可以接收短信。

我已经能够独立完成这两项工作(甚至为两者创建功能)。

两者都很有效 - 独立。

一旦我尝试同时实现它们,我就会遇到问题。

我已将序列打印数字标记放入并发现问题所在(我认为使用 - xivelyclient.put(feed, xivelyKey);

该程序将实现 - 上传1个单一数据点然后卡在这里。短信不会工作,也不会上传其他数据点。奇怪的是,如果省略了SMS功能,那么EXACT相同的功能将起作用。我需要做两件事。

这是串行终端输出:

  

SMS消息接收器

     

启动Xively客户端。

     

GSM初始化

     

等待讯息

     

读取传感器值807.00

     

1

     

将其上传至Xively

问题在于Xviley代码猜测或其他什么。

附上我的代码 - 我很难过 - 任何帮助都会非常感激。

#include <GSM.h>   // include the GSM library
#include <stdlib.h>
#include <HttpClient.h>
#include <Xively.h>


GSM gsmAccess;     // initialize the library instances
GSM_SMS sms;
GSMClient client;
GPRS gprs;

#define PINNUMBER ""  // PIN Number for the SIM
#define xivelyFeed 2026168855
char xivelyKey[] = "WwRCfO61e28WASeUcfGHJmyoo4g7mXczEC1pBMGYc3VgGgBX";

#define sensorPin A0
#define ledPin 9

#define GPRS_APN       "internet" // replace with the APN of the GPRS provider
#define GPRS_LOGIN     "" // empty on bluevia, replace with your GPRS login if needed
#define GPRS_PASSWORD  "" // empty on bluevia, replace with your GPRS password 

char senderNumber[20];
char server[] = "api.xively.com";      // name address for xively API

unsigned long lastConnectionTime = 0;         // last time you connected to the server
boolean lastConnected = false;                  // state of the connection last 
const unsigned long postingInterval = 10*1000;  //delay between updates to Pachube.com

char sensorID[] = "Light";  //datastreams
char ledID[] = "LED";

XivelyDatastream datastreams[] = {
XivelyDatastream(sensorID, strlen(sensorID), DATASTREAM_FLOAT),
XivelyDatastream(ledID, strlen(ledID), DATASTREAM_FLOAT),
};


// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 2 /* number of datastreams */);

XivelyClient xivelyclient(client);

void setup()
{

Serial.begin(9600);

 Serial.println("SMS Messages Receiver");
 Serial.println("Starting Xively client.");

boolean notConnected = true;



 while(notConnected)
  {
   if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
    (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
  notConnected = false;

  else
 {
  Serial.println("Not connected");
  delay(1000);
    }
  }


  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
  pinMode(sensorPin, INPUT);

}

void loop()
{




// if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available())
  {
    char c = client.read();
     Serial.print(c);
  }


  UploadData(); 
  delay(10);
  CheckSMS();




}

void UploadData( ){
  //read sensor values
  int sensorValue = analogRead(sensorPin);
  datastreams[0].setFloat(sensorValue);

  //print the sensor valye
  Serial.print("Read sensor value ");
  Serial.println(datastreams[0].getFloat());

  Serial.println(1);


  //send value to xively
  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);

  Serial.println(2);

  //return message
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);
  Serial.println("");

  Serial.println(3);
  //delay between calls
  delay(15000);  
} 

void CheckSMS(){

  char c; // variable for the SMS message
  int password =0;
  pinMode(12,OUTPUT);
  int incomingByte=0;

  if (sms.available())
  {
    Serial.println("Message received from:");
    sms.remoteNumber(senderNumber, 20); // Get remote number
    Serial.println(senderNumber);

    if(sms.peek()=='#')                    // An example of message disposal    
                        // Any messages starting with # should discarded
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    while(c=sms.read())                      // Read message bytes and print them
     {
      Serial.print(c);

      password += c;

      Serial.print("instance 1");
      Serial.println(password);

      incomingByte = password;

      if (incomingByte == 150) {
      digitalWrite(12,HIGH);
      delay(5000);
      digitalWrite(12,LOW);
      incomingByte= 222;   }


     }
    Serial.println("\nEND OF MESSAGE");
    sms.flush();                            // Delete message from modem memory
    Serial.println("MESSAGE DELETED");
    Serial.println(password);
   }
   delay(1000);

    } 

2 个答案:

答案 0 :(得分:0)

很难确切地说出你的问题是什么。你也可以发布串口显示器的内容吗?

尝试同时执行这两项操作时,可能会遇到内存问题。 Xively库非常庞大,并且经常会遇到Uno上的内存问题。您可以尝试使用MemoryFree库检查并打印循环中每个步骤后剩余的内存量。另一件事是在Arduino Mega上运行相同的代码,如果你有权访问一个。 Mega具有更多的SRAM,不会遇到这些问题。

答案 1 :(得分:0)

if((gsmAccess.begin(PINNUMBER)== GSM_READY)&amp;     (gprs.attachGPRS(GPRS_APN,GPRS_LOGIN,GPRS_PASSWORD)== GPRS_READY))

应该是if((gsmAccess.begin(PINNUMBER)== GSM_READY)&amp;&amp;(DOUBLE&amp;)     (gprs.attachGPRS(GPRS_APN,GPRS_LOGIN,GPRS_PASSWORD)== GPRS_READY))

相关问题