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());
}
}
Your code block below is supposed to read whatever received from GPRS modem .
Can you show us what you see on your serial monitor?