-1

I am using arduino mega 2650, sim 900 GSM/GPRS module and 2 xbee (version 2) modules. Temperature sensor sends data between the 2 xbees wireless, then upload this data to a web page using the sim900 but for a reason I cannot get the code working correctly.

#include <SoftwareSerial.h>

SoftwareSerial gprsSerial(7, 8);

int temp;

void setup(){
  gprsSerial.begin(19200);
  Serial.begin(9600);
  Serial1.begin(19200);

  Serial1.println("Config SIM900...");
  delay(2000);
  Serial1.println("Done!...");
  gprsSerial.flush();
  Serial1.flush();

  // attach or detach from GPRS service 
  gprsSerial.println("AT+CGATT?");
  delay(100);
  toSerial();


  // bearer settings
  gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  toSerial();

  // bearer settings
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"Umniah Internet\"");
  delay(2000);
  toSerial();

  // bearer settings
  gprsSerial.println("AT+SAPBR=1,1");
  delay(2000);
  toSerial();
};

void loop(){
  if (Serial.available() >= 21) {
    if (Serial.read() == 0x7E) {
      for (int i = 1; i < 19; i++) {
        byte discardByte = Serial.read();
      }
      int analogMSB = Serial.read();
      int analogLSB = Serial.read();
      int analogReading = analogLSB + (analogMSB * 256);
      temp = analogReading / 1023.0 * 1.23;
      temp = temp - 0.5;
      temp = temp / 0.01;
      Serial.print(temp);
      Serial.println(" degrees c");
       // initialize http service
   gprsSerial.println("AT+HTTPINIT");
   delay(2000); 
   toSerial();

   // set http param value
   gprsSerial.println("AT+HTTPPARA= \"URL\" ,\"http://ar.ahu.edu.jo/sensor.aspx?Sens1=10&Sens2=0&Sens3=0\"");
   delay(2000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD"); 
   delay(1000);
   toSerial();

   gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(10000);
    }
  }
}

void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial1.write(gprsSerial.read());
  }
}
GreenAsJade
  • 14,459
  • 11
  • 63
  • 98
  • Can you please let us know where are you having the problem? share what are the replies from sim900 to each command sent – dmSherazi Nov 27 '14 at 17:27
  • i have no replies at all just rubbish for 19200 and 0 degree C for 9600. if you please could help me i am totally new at this big field and this is a part of my graduation project i am running out of time. – Eng Yousef Fararjeh Nov 27 '14 at 18:50
  • Yousef The first thing you must do is make sure you are communicating with your modem as required. Can you switch on your modem and make a call from it? – dmSherazi Nov 27 '14 at 21:18
  • ok i will surely do that but in that while can you please check the code if there is something wrong i think that i have done something that is not at the appropriate way it should be done. thanks for caring. – Eng Yousef Fararjeh Nov 28 '14 at 12:45
  • its seems to be OK.. once you provide the replies from sim900 for each command I can be help you . – dmSherazi Nov 28 '14 at 15:51
  • can you please tell me how to get these replies. should i add any command to my code to show them in the serial watcher? – Eng Yousef Fararjeh Nov 28 '14 at 19:16

2 Answers2

0

Your code block below is supposed to read whatever received from GPRS modem .

void toSerial()
{
    while(gprsSerial.available()!=0)
    {
        Serial1.write(gprsSerial.read());
    }
}

Can you show us what you see on your serial monitor?

dmSherazi
  • 3,743
  • 5
  • 37
  • 62
  • yes sure. about that i told you that the serial monitor shows rubbish for 19200 baud rate and always 0 degree C for 9600 baud rate. the rubbish is something like this ($#%^%$^@). – Eng Yousef Fararjeh Nov 29 '14 at 02:34
0

I am very new, but probably the mistake is on the ports election. Ports 7 and 8 are only available for Arduino UNO.

In this case you should work with ports 10 and 11:

SoftwareSerial gprsSerial(10, 11);

Timothy G.
  • 6,335
  • 7
  • 30
  • 46