A few months ago, for about 2 months, I tried everything to figure out why my sim900 wasnt sending sms.
First I thought it was the library, but it wasn't. I ruled that out after seeing sms with AT commands.
Then I thought it was a power issue but ruled that out when I powered my sim900 from a lipo pack capable of delivering 3A.
Finally someone mentioned the sim900 was 2g only. I tried getting a 2g chip buy neither of the carriers in Honduras has 2g only Sims anymore.
But I decided to buy the other carrier's sim anyway. I did and for about 5 days I plugged the sim (via an pl2032 adapter) to my usb and it registered almost immediately, every time.
So I thought it might have been a carrier issue all along. So I uploaded the code to my nano and set up the sim900 with its lipo powersupply. I let it run for 2 hours and it send the sms (1 every hour) just fine both times. I unplugged it because I was leaving.
Today I plugged it back in and it failed to register and thus send the sms. This leads me to believe something might be happening to the module or sim after sending the sms via at commands in the sketch which causes it to fail registration next time around.
Any ideas?
Ok, this is weird! Now I plugged the SIM900 back into the pl2032 and it registered immediately.
Here is the sketch:
#include <Time.h>
#include <TimeLib.h>
#include <SoftwareSerial.h>
#include <TimeAlarms.h>
#include <dht.h>
dht DHT;
#define DHT11_PIN 5
char number[]="+mynumber";
boolean started=false;
SoftwareSerial sim900(9,10);
void setup(){
Serial.begin(9600);
delay(10000); //Allow time for the SIM to register
Alarm.timerRepeat(3600, MainAlarm); //21600s/60s/m=360m
} //3600 = 1hr
void loop(){
Alarm.delay(10); // wait one second between clock display
}
void MainAlarm(){
Serial.println("Main Alarm...");
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
double temp = DHT.temperature;
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
double hum = DHT.humidity;
Serial.println(DHT.humidity);
sendData(temp,hum);
}
void sendData(double temp, double hum){
sim900.begin(9600); //Default serial port setting for the GPRS modem is 19200bps 8-N-1
static char outTempStr[15];
static char outHumStr[15];
String tempString = dtostrf(temp,5,2,outTempStr);
String humString = dtostrf(hum,5,2,outHumStr);
delay(5000);
sim900.print("\r");
delay(1000);
sim900.print("AT+CMGF=1\r"); //text mode
delay(1000);
sim900.print("AT+CMGS=\"+50494505578\"\r");
delay(1000);
sim900.print("Temp=" + tempString + "Hum=" + humString + "\r"); //The text for the message
Serial.println("sent!");
delay(1000);
sim900.write(0x1a); //Equivalent to sending Ctrl+Z
sim900.println(char(26));
Serial.println("done!!");
}