Hello,
First of all, English is not my mother tongue; please excuse any errors on my part.
I’m an internship for my studies in a Electronic/Programming business, and i’m a noob in Arduin so i may need your help if it’s possible. I went to the french forum but i got no answer at all, so now i’m here.
I’m using an Arduino UNO with a SIM900 module from Epalsite ( SIM900 Quad-Band GPRS shield with Micro SD card slot - Epalsite Wiki )
I want to store the time that i get from the AT+CCLK command in some variables.
I succeded to connect the my SIM to the network, sent sms and see the time i get on the serial, but here i’m stuck. I’m completely unable to write decent data time on the variables.
This doesn’t seem very complicated to do (theoretically speaking), so i guess i’m missing something, somewhere.
I tried many codes, some of mine, some that i found on the web, some mix of both…but again, i get no satisfying results, and I am starting to despair of this…
This is the last code i used :
#define DEBUG // Mode debogage
#include <SoftwareSerial.h>
SoftwareSerial SIM900(2,3);
int i=0;
#define CCLK_MSG_LEN 28 // le nombre total de caractère dans le message CCLK
#define TIME_STR_LEN 18 // le nombre actuel de caractère
char timeStr[TIME_STR_LEN];
char timePreamble[] = "CCLK: \"" ;
int dateToDecimal(char * date){
int value = ((date[0] - '0') * 10) + (date[1] - '0');
return value;
}
boolean getTime(){
// Check for available bytes
if(SIM900.available() < CCLK_MSG_LEN )
return false; // Pas assez de caractère pour un message complet
if(SIM900.read() != '+')
return false; // Pas encore synchronisé
for(int i=0; i < strlen(timePreamble); i++) {
if(SIM900.read() != timePreamble[i] )
return false; // Fin si les données reçues ne remplissent pas le preamble
}
// Preamble checked. Début des données temporelles
for(int i=0; i < TIME_STR_LEN; i++)
timeStr[i] = SIM900.read();
return true; // timeString rempli avec des données valables
}
void GetSIM900()
{
delay(2000);
if(SIM900.available())
{
Serial.print("\n");
delay(3000);
while(SIM900.available())
{
Serial.print((char)SIM900.read()); // On vide la mémoire tampon du SIM900
}
Serial.print("\n");
}
}
void setup()
{
SIM900.begin(9600);
Serial.begin(9600);
Serial.println("configuration par defaut");
SIM900.println("ATZ"); // Pour remettre les configuration par defaut
GetSIM900();
Serial.println("affichage du numero des erreurs");
SIM900.println("AT+CMEE=1"); // Pour afficher le numero de l'erreur
GetSIM900();
/*
Serial.println("Code PIN");
SIM900.println("AT+CPIN=1379"); // Code PIN
GetSIM900();
*/
delay(5000); // Connexion au réseau
#ifdef DEBUG
Serial.println("Operateur");
SIM900.println("AT+COPS?"); // Opérateur
GetSIM900();
delay(5000);
//SET center number server needed for free provider
Serial.println("envoi de la commande: AT+CSCA=\"+33689004000\"");
SIM900.print("AT+CSCA=\"+33689004000\"\r");
GetSIM900();
delay(5000); // Connexion au réseau
Serial.println("Etat de la connexion au reseau :");
Serial.println("La connexion est etablie si +CREG: 0,1");
SIM900.println("AT+CREG?"); // Connexion au réseau
GetSIM900();
#endif
Serial.println("Tentative de récupération de l'heure");
//SIM900.println("AT+CLTS=1"); // Il semblerait que cette ligne soit optionnelle
// GetSIM900();
delay(1000);
SIM900.println("AT+CCLK?");
GetSIM900();
}
/*
Serial.println("Activation du mode SMS");
SIM900.println("AT+CMGF=1"); // Activation du mode SMS
GetSIM900();
Serial.println("Envoi du numero de telephone");
SIM900.println("AT+CMGS=\"+33782764416\""); // Envoi du numéro de téléphone
GetSIM900();
Serial.println("Corps du message");
SIM900.println("Bonjour"); // Corps du message
Serial.println("CTR+Z");
SIM900.write(0x1A); // CTR+Z
GetSIM900();
}
*/
void loop()
{
int years, months, dates, hours, minutes, seconds;
if (SIM900.available())
SIM900.println( "AT+CCLK?" );
if(getTime() == true){
delay(120000); //2 minutes
years = dateToDecimal(&timeStr[0]) ;
months = dateToDecimal(&timeStr[3]) ;
dates = dateToDecimal(&timeStr[6]) ;
hours = dateToDecimal(&timeStr[9]) ;
minutes = dateToDecimal(&timeStr[12]) ;
seconds = dateToDecimal(&timeStr[15]) ;}
//else Serial.println("Ada yang salah");
Serial.print("YY/MM/DD HH:MM = ");
Serial.print(years,DEC);
Serial.print("/");
Serial.print(months,DEC);
Serial.print("/");
Serial.print(dates,DEC);
Serial.print(" ");
Serial.print(hours,DEC);
Serial.print(":");
Serial.println(minutes,DEC);
delay(2500);
}
I think my function getTime never get a true response, but i don’t know how to make it works. So at the end of the program, i get non-sense value on the serial port.
Any help would be really appreciated.