Seeeduino GPRS module and Seeeduino Stalker v2.3

Hi, I’m looking for a little guidance on a project I’m working on with a Seeeduino Stalker and the Seeeduino GPRS shield v1.4. I’ve been through a few changes with the project as a whole based on what I’ve been learning here and it’s taking shape. I still have issues with SD card formatting and access, but that’s the least of my worries at this point.

What I’d like help with is this: I don’t seem to be able to access the GPRS shield using PuTTy in order to test the AT commands. When I do access it, or try to I get gibberish back. I’ve tried all available baud rates from 2400 and up, I’ve been over the settings in PuTTy and tested it on another serial device as well as made sure that there’s an implicit carriage return with each line break, but so far, nothing.

The other question is about libraries. So I actually ‘need’ the SIM900.h and sms.h libraries? Or can I; as the example code I keep finding suggests, just use SoftwareSerial.h? What is the best practice? And what creates less of a footprint so my app is as small as it might be?

Any suggestions on re-writing for optimal code are welcome as well. I admit here that I’m a windows/web c# developer and the minimalism of the arduino environment is taking some getting used to.

My thanks in advance for your time and consideration.

#include <Wire.h>
#include <SD.h>
#include "DS3231.h"
#include "DS1307RTC.h"
#include "Time.h"
#include "SIM900.h"
#include "sms.h"
#include "SoftwareSerial.h"

SMSGSM sms;
SoftwareSerial GPRS(7, 8);

struct MyRec {
  char date[11];
  char time[9];
  char temp[3];
} 
myrec;

char bigstring[64];

const int chipSelect = 10;
int switchPin = 2; // choose the switch pin
long lastDebounce = 0;
long debounceDelay = 500;
DS3231 RTC2; //Create the DS3231(RTC) object
int32_t temp;
char* evtdate;
char* pho = {
  "+14152221212};
char* logf = {
  "datalog.txt"};
tmElements_t te;

void setup(){
  GPRS.begin(19200);
  Serial.begin(19200);
  Wire.begin();
  setTime(12,39,45,21,4,13);
  pinMode(switchPin, INPUT);
  attachInterrupt(0, trigger0, FALLING);
  //SD.begin();
  //SD.remove(logf);
  //setupsdcard();
  //initializelogfile();
  delay(500);
}

void loop()
{
  temp = RTC2.getTemperature();
}

void trigger0(){
  if((int)(millis() - lastDebounce) > (int)debounceDelay){
    //File myFile = SD.open(logf, FILE_WRITE);
    //if (myFile) {
    time_t t = now();
    breakTime(now(),te);
    char tmp = temp;

    sprintf(myrec.date, "%2d-%02d-%02d", te.Year+1970, te.Month, te.Day);
    sprintf(myrec.time, "%02d:%02d:%02d", te.Hour, te.Minute, te.Second);
    sprintf(myrec.temp, "%02d", tmp);
    //myFile.println((String)evtdate);
    delay(500);  
    sendMessage(join3Strings(myrec.date, myrec.time, myrec.temp));
    //myFile.close();
    delay(500); 
    //}
    lastDebounce = millis();
  }
}

char* join3Strings(char* string1, char* string2, char* string3) {
  bigstring[0] = 0;          // start with a null string:
  strcat(bigstring, string1);  // add first string
  strcat(bigstring, ":");
  strcat (bigstring, string2);
  strcat(bigstring, ":");
  strcat (bigstring, string3);
  strcat(bigstring, "'c");

  return bigstring;
}

void sendMessage(char* msgs){
    Serial.println(msgs);
    //sms.SendSMS(pho, msgs);
}

void initializelogfile(){
  if(!SD.exists(logf)){
    Serial.println("Creating new datalog.txt...");
    File NewdataFile = SD.open(logf, FILE_WRITE);
    NewdataFile.close();
  }
}

void setupsdcard(){
  pinMode(10, OUTPUT);
  if (!SD.begin(chipSelect)) {
    return;
  }
}

You don't seem to grasp the simple concept that an ISR is to be fast. There are things you can, and things that you can't, do in an ISR. You can set a flag. You can't delay(). You can't Serial.print() or anything else that requires interrupts, like getting the time from the clock.

What is generating the interrupt?

Actually I do grasp the concept of speed. The delays are all based on the myriad example code I’ve been reviewing and testing. When I develop in c# I never use anything like a delay, ever, so when I started seeing delays in example code for the arduino I was a little surprised but seeing how bloody common it was I put it off to some practice required by the platform.

The interrupt is from a reed switch, part of a rain gauge actually. The idea is to send an SMS message each time the 5cc gauge goes high, which in an average setting for this application is about once every hour; roughly.

The interrupt works fine, I get the data based on the timestamp I create along with the temperature at the time, this much works fine. It’s the GPRS shield and firstly getting the communications between the base board and the shield working, thus far despite using example code provided in various forums and from Seeed Studio themselves it has amounted to naught.

With regards to the use of Serial.print() etc. and delay(), have a look at the example code from here:

http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0

Then tell me that the use of delay() is a ‘can’t do’ behaviour, because it seems pretty much one of the most common function calls in the code from Seeed Studio below.

/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and 
  send a http request to the website, upload data to pachube.com by TCP connection,
 
  The microcontrollers Digital Pin 7 and hence allow unhindered
  communication with GPRS Shield using SoftSerial Library. 
  IDE: Arduino 1.0 or later
  Replace the following items in the code:
  1.Phone number, don't forget add the country code
  2.Replace the Access Point Name
  3. Replace the Pachube API Key with your personal ones assigned
  to your account at cosm.com
  */
 
 
#include <SoftwareSerial.h>
#include <String.h>
 
SoftwareSerial mySerial(7, 8);
 
void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);    // the GPRS baud rate 
  delay(500);
}
 
void loop()
{
  //after start up the program, you can using terminal to connect the serial of gprs shield,
  //if you input 't' in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
  //if input 'd' in the terminal, it will execute DialVoiceCall(), etc.
 
  if (Serial.available())
    switch(Serial.read())
   {
     case 't':
       SendTextMessage();
       break;
     case 'd':
       DialVoiceCall();
       break;
     case 'h':
       SubmitHttpRequest();
       break;
     case 's':
       Send2Pachube();
       break;
   } 
  if (mySerial.available())
    Serial.write(mySerial.read());
}
 
///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+86138xxxxx615\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  mySerial.println("A test message!");//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}
 
///DialVoiceCall
///this function is to dial a voice call
void DialVoiceCall()
{
  mySerial.println("ATD + +86138xxxxx615;");//dial the number
  delay(100);
  mySerial.println();
}
 
///SubmitHttpRequest()
///this function is submit a http request
///attention:the time of delay is very important, it must be set enough 
void SubmitHttpRequest()
{
  mySerial.println("AT+CSQ");
  delay(100);
 
  ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.
 
  mySerial.println("AT+CGATT?");
  delay(100);
 
  ShowSerialData();
 
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
  delay(1000);
 
  ShowSerialData();
 
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"CMNET\"");//setting the APN, the second need you fill in your local apn server
  delay(4000);
 
  ShowSerialData();
 
  mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
  delay(2000);
 
  ShowSerialData();
 
  mySerial.println("AT+HTTPINIT"); //init the HTTP request
 
  delay(2000); 
  ShowSerialData();
 
  mySerial.println("AT+HTTPPARA=\"URL\",\"www.google.com.hk\"");// setting the httppara, the second parameter is the website you want to access
  delay(1000);
 
  ShowSerialData();
 
  mySerial.println("AT+HTTPACTION=0");//submit the request 
  delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
  //while(!mySerial.available());
 
  ShowSerialData();
 
  mySerial.println("AT+HTTPREAD");// read the data from the website you access
  delay(300);
 
  ShowSerialData();
 
  mySerial.println("");
  delay(100);
}
 
///send2Pachube()///
///this function is to send the sensor data to the pachube, you can see the new value in the pachube after execute this function///
void Send2Pachube()
{
  mySerial.println("AT+CGATT?");
  delay(1000);
 
  ShowSerialData();
 
  mySerial.println("AT+CSTT=\"CMNET\"");//start task and setting the APN,
  delay(1000);
 
  ShowSerialData();
 
  mySerial.println("AT+CIICR");//bring up wireless connection
  delay(3000);
 
  ShowSerialData();
 
  mySerial.println("AT+CIFSR");//get local IP adress
  delay(2000);
 
  ShowSerialData();
 
  mySerial.println("AT+CIPSPRT=0");
  delay(3000);
 
  ShowSerialData();
 
  mySerial.println("AT+CIPSTART=\"tcp\",\"api.cosm.com\",\"8081\"");//start up the connection
  delay(2000);
 
  ShowSerialData();
 
  mySerial.println("AT+CIPSEND");//begin send data to remote server
  delay(4000);
  ShowSerialData();
  String humidity = "1031";//these 4 line code are imitate the real sensor data, because the demo did't add other sensor, so using 4 string variable to replace.
  String moisture = "1242";//you can replace these four variable to the real sensor data in your project
  String temperature = "30";//
  String barometer = "60.56";//
  mySerial.print("{\"method\": \"put\",\"resource\": \"/feeds/42742/\",\"params\"");//here is the feed you apply from pachube
  delay(500);
  ShowSerialData();
  mySerial.print(": {},\"headers\": {\"X-PachubeApiKey\":");//in here, you should replace your pachubeapikey
  delay(500);
  ShowSerialData();
  mySerial.print(" \"_cXwr5LE8qW4a296O-cDwOUvfddFer5pGmaRigPsiO0");//pachubeapikey
  delay(500);
  ShowSerialData();
  mySerial.print("jEB9OjK-W6vej56j9ItaSlIac-hgbQjxExuveD95yc8BttXc");//pachubeapikey
  delay(500);
  ShowSerialData();
  mySerial.print("Z7_seZqLVjeCOmNbEXUva45t6FL8AxOcuNSsQS\"},\"body\":");
  delay(500);
  ShowSerialData();
  mySerial.print(" {\"version\": \"1.0.0\",\"datastreams\": ");
  delay(500);
  ShowSerialData();
  mySerial.println("[{\"id\": \"01\",\"current_value\": \"" + barometer + "\"},");
  delay(500);
  ShowSerialData();
  mySerial.println("{\"id\": \"02\",\"current_value\": \"" + humidity + "\"},");
  delay(500);
  ShowSerialData();
  mySerial.println("{\"id\": \"03\",\"current_value\": \"" + moisture + "\"},");
  delay(500);
  ShowSerialData();
  mySerial.println("{\"id\": \"04\",\"current_value\": \"" + temperature + "\"}]},\"token\": \"lee\"}");
 
 
  delay(500);
  ShowSerialData();
 
  mySerial.println((char)26);//sending
  delay(5000);//waitting for reply, important! the time is base on the condition of internet 
  mySerial.println();
 
  ShowSerialData();
 
  mySerial.println("AT+CIPCLOSE");//close the connection
  delay(100);
  ShowSerialData();
}
 
void ShowSerialData()
{
  while(mySerial.available()!=0)
    Serial.write(mySerial.read());
}

The idea is to send an SMS message each time the 5cc gauge goes high, which in an average setting for this application is about once every hour; roughly.

The idea is to notice that the interrupt occurred, and then, at some time on the not too distant future, send the SMS. The interrupt should do nothing more than set a flag indicating that the interrupt occurred. Then, loop() should notice that the flag is set and send the SMS. You do NOT send the SMS in the ISR.

With regards to the use of Serial.print() etc. and delay(), have a look at the example code from here:

I did. That code doesn't use interrupts, and does not print() or delay() in an ISR.

Then tell me that the use of delay() is a 'can't do' behaviour, because it seems pretty much one of the most common function calls in the code from Seeed Studio below.

Again, not an ISR in sight in that code.

Do the rest of us a favor and if you’re not going to actually answer a question in a helpful way just shut up will you.

I am working with gprs shield to send values of different sensor readings to a mobile phone as a text message. My problem is I am failing on passing values from the sensor to a sendmessage(); so that they can be sent to a mobile phone. the sensors involved are temperature, pulse, emg and gsr.

any one with the working code it will be helpfull.