Here is my problem...I alredy posted on some athet post... but here is again...
I have a BIG problem. My GSM900 shuts down after approximately 5 days of device operation ... AT328P continues with operation. I've been analyzing the program for a few weeks, but it's not clear to me... The whole day is divided into intervals of 5 minutes and the loop checks if there were any messages and based on the sent message sends a reply. Sending "0" or "1" I receive temperature or humidity value. I set SIM900 in SAFE MODE 2 , due to reduced power consumption: with NO SLEEP MODE whole device drains about 60mA.. in SLEEP MODE2 with command AT+CSCLK=2 it reduces to 16mA. Is it possible that after a while ... as far as I know I can only guess ... the SIM900 shuts down on its own ...? In order to be able to monitor the execution of the program, I set some BLINK sequences on DIGITAL PORT 13 ... everything was executed as I programmed.
The device is made with a minimum number of external components: a crystal, a pair of capacitors and a reset resistor. At the beginning I have an automatic
switch ON sequence ... maybe it somehow comes out of the loop ... WHAT SHOULD NOT HAPPEN THAT ... and it goes to the beginning and through this AUTO ON SEQUENCE turns off GSM900. I shortened the loop to go not from: i=1 to 288 but to 5, and the duration of the same to 60000ms (1 minute)
... BEHAVES THE SAME. I power it with a 4A / 12V switching adapter, and then my Step Down Module LM2596s 3A DC to DC Buck Converter... lowers to 5V.
#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include "DHT.h"
#define DHTPIN 2
#define PIN_TX 7
#define PIN_RX 8
#define BAUDRATE 9600
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
/*code code code code code code code */
#define code "0404"
/*code code code code code code code */
int messageIndex = 0;
#define DHTTYPE DHT22
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
DHT dht(DHTPIN, DHTTYPE);
char string[160];
char smsbuffer[160];
char n[20];
char phone[16];
char telephone[16];
char datetime[24];
int analogInput = A2;
float vout = 0.0;
float vin = 0.0;
int value = 0;
void setup() {
for (int i = 2; i <= 6; i++)
{
pinMode(i, OUTPUT);
}
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(analogInput, INPUT);
Serial.begin(9600);
/*
************************************************
AUTO POWER ON for GSM900
************************************************
*/
digitalWrite(9, LOW);
delay(1000);
digitalWrite(9, HIGH);
delay(2000);
digitalWrite(9, LOW);
delay(3000);
/*
************************************************
Waiting 30 SEK for SIM900 initialization
************************************************
*/
while (!gprsTest.init()) {
delay(30000);
}
/*
*******************************************************
SIM900 is connected, deleting all mesages from MEMORY
*******************************************************
*/
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
/*
*******************************************************
SEND CODE, YOU HAVE 30 SECONNDS
*******************************************************
*/
digitalWrite(LED_BUILTIN, HIGH);
delay(30000);
digitalWrite(LED_BUILTIN, LOW);
/*
**********************************
READ MEMORY FROM SIM900
**********************************
*/
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
messageIndex = gprsTest.isSMSunread();
nocode:
/*
***************************************
SMS in MEMORY, reading parameters
***************************************
*/
if (messageIndex > 0) {
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
/*
********************************************
remember number who send code- MASTER number
********************************************
*/
strcpy(telephone,phone);
/*
********************************************
deleting all mesages from MEMORY
********************************************
*/
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
/*
********************************************
compare code
********************************************
*/
if (strcmp (message, code) == 0) {
delay(1000);
/*
********************************************
CODE IS OK, calling MASTER number
********************************************
*/
gprsTest.callUp(telefon);
delay(20000);
}
/*
****************************************************
CODE is NOT OK, send code again
****************************************************
*/
else {
digitalWrite(LED_BUILTIN, HIGH);
delay(30000);
digitalWrite(LED_BUILTIN, LOW);
goto nocode;
}
}
/*
********************************************************
SMS IS NOT sent, send SMS again
********************************************************
*/
else if (messageIndex <= 0) {
digitalWrite(LED_BUILTIN, HIGH);
delay(30000);
digitalWrite(LED_BUILTIN, LOW);
goto nocode;
}
dht.begin();
scale.set_scale(21950.f);
delay(500);
}
void retlja() {
for (int i = 1; i <= 288; i++) {
messageIndex = gprsTest.isSMSunread();
if (messageIndex > 0) { //At least, there is one UNREAD SMS
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, telefon, datetime);
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
if (strcmp (message, "1") == 0) {
mesage();
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
}
else if (strcmp (message, "0") == 0) {
mesagee();
delay(1000);
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
}
delay(297500);
}
}
void loop() {
retlja();
}
void mesage() {
float t = dht.readTemperature();
int temp = (t);
int temp1 = (t * 100) - (temp * 100);
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
sprintf(string, "Temperature: %d.%d C ", temp, temp1 );
gprsTest.sendSMS(telephone, string);
delay (10000);
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
}
void mesagee() {
float h = dht.readHumidity();
int pos = 0;
int hum = (h);
int hum1 = (h * 100) - (hum * 100);
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
sprintf(string, "Hummidy: %d.%d ", hum, hum1 );
gprsTest.sendSMS(telephone, string);
delay (10000);
gprsTest.deleteSMS(messageIndex);
messageIndex = 0;
}