0
votes

Hi Arduino beginner here.

I'm using an Arduino UNO R3 with the official Arduino GSM module. IDE 1.0.5.

I'm trying to upload data to Xively but also be able to recieve an SMS.

I have been able to do both independently ( even creating functions for both ).

Both work great - Independently.

As soon as I try to implement them both at the same time I run into a problem .

I have put serial print number markers in and discovered that the problem lies (i think with the - xivelyclient.put(feed, xivelyKey); point

The program will implentent - upload 1 single data point then get stuck here. SMS will not work nor will it upload another data point. Strange since the EXACT same function will work if the SMS function is left out. I need to do both.

Here is the serial terminal output:

SMS Messages Receiver

Starting Xively client.

GSM initialize

Waiting for messages

Read sensor value 807.00

1

Uploading it to Xively

The problem lies with Xviley code im guessing or something else.

Attached is my code - im stumped - any help would be much appreciated.

#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
Did you ever get this to work? I have the same issue (though I'm not using the Xively library).That Guy

2 Answers

0
votes

It's hard to say exactly what your issue is. Could you maybe post the contents of your Serial monitor as well?

You may be running into a memory issue while trying to do both of these at the same time. The Xively library is quite big, and can often run into memory issues on the Uno. You can try using the MemoryFree library to check and print out how much memory is remaining after each step in the loop. Another thing to try is to run the same code on an Arduino Mega, if you have access to one. The Mega has significantly more SRAM and will not run into these issues.

0
votes

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

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