0

嗨 Arduino 初学者在这里。

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

我正在尝试将数据上传到Xively但也能够接收短信。

我已经能够独立完成两者(甚至为两者创建函数)。

两者都很好 - 独立。

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

我已将序列号标记放入并发现问题出在(我认为与 -xivelyclient.put(feed, xivelyKey);

该程序将执行 - 上传 1 个单个数据点然后卡在此处。SMS 将不起作用,也不会上传另一个数据点。奇怪的是,如果省略 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);

    } 
4

2 回答 2

0

很难确切地说出你的问题是什么。您能否也发布您的串行监视器的内容?

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

于 2013-08-27T14:59:50.437 回答
0

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

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

于 2013-08-28T13:52:42.477 回答