#include #include Minitel m(52,53); //Definition pour le Serial du Minitel void saisieNum(char *num); void saisiePin(char *pin); void saisieTxt(char *txt); void send_AT_cmd(const char *at_cmd, char *at_rep); void send_sms(); void enter_pin(); // CAYE PAS BIEN ET JMEN FOUT ! char rep[50]; char Operator[50]; //char Signal[]; void setup() { /****Init Shield GPRS Hardware0617827300 mode*****/ Serial.begin(19200); Serial1.begin(19200); /****Simulation ON/OFF*****/ // pinMode(8, OUTPUT); // digitalWrite(8, HIGH); char mess_ok[50]; m.clearScreen(); m.textMode(); m.textColor(WHITE); m.bgColor(BLACK); m.text(" Smartphone Minitel V1 ", 1, 1); /**** check du pin *****/ send_AT_cmd("AT+CPIN?\r", rep); Serial.println(rep); if (strstr(rep, "READY") == NULL) { m.text("[ ] Check for pin lock... ", 2, 3); m.text("Enter PIN code : ", 2, 4); enter_pin(); } m.text("[*] PIN code is good ! ", 2, 3); m.text("[ ]", 2, 5); m.blink(); m.text("Waiting for Auth Network .....", 6, 5); send_AT_cmd("AT+COPS?\r", rep); Serial.print(rep); char *token, *endtoken; token = strchr(rep, '\"'); token++; endtoken = strchr(token, '\"'); *endtoken = '\0'; sprintf(mess_ok, "You are connected to %s", token); // strcpy(mess_ok, "You are connected to "); // strcat(mess_ok, token); sprintf(Operator, "Operator : %s", token); m.noBlink(); m.text("[*]", 2, 5); m.text(mess_ok, 5, 5); delay(2000); send_AT_cmd("AT+CGREG?\r\r", rep); Serial.print(rep); delay(1000); } void loop() { m.clearScreen(); m.textMode(); m.textColor(WHITE); m.bgColor(RED); m.text(" Smartphone Minitel V1 ", 1, 1); m.text(Operator, 1, 23); m.bgColor(BLACK); m.text("1 - Send SMS", 4, 5 ); m.text("2 - Read SMS", 4, 6 ); m.text("5 - Adress Book", 4, 8 ); while(1) { if(m.available()>0) { char key = NULL; // Obligation de lire 2 buffer en cas de touche Menu key = m.getKey(); switch(key) { case '1': send_sms(); break; case '2': break; } } } delay(1000); } void enter_pin() { char pin[5]; char at_pin[12]; saisiePin(pin); sprintf(at_pin, "AT+CPIN=%s\r", pin); Serial.print(pin); send_AT_cmd(at_pin, rep); send_AT_cmd(at_pin, rep); Serial.print(rep); return setup(); } void send_sms() { m.clearScreen(); m.textMode(); m.textColor(WHITE); m.bgColor(RED); m.text(" Send SMS ", 4, 1); m.bgColor(BLACK); m.text("Number : +", 1, 4); m.cursor(); m.moveCursorTo(12,4); char num[20]; char txt[160]; // char *cmgs = "AT+CMGS=\"+"; // char *endcmgs = "\""; char cmdcmgs[100]; // strcpy(cmdcmgs, cmgs); // Serial.print(cmdcmgs); // send_AT_cmd("AT+CGATT?\r"); saisieNum(num); saisieTxt(txt); // Serial.print(num); // strcat(cmdcmgs, num); // Serial.print(cmdcmgs); // strcat(cmdcmgs, endcmgs); send_AT_cmd("AT+CMGF=1\r", rep); //Mode texte pour SMS delay(100); sprintf(cmdcmgs, "AT+CMGS=\"+%s\"\r", num); send_AT_cmd(cmdcmgs, rep); send_AT_cmd(txt, rep); delay(1000); return loop(); } void saisieNum(char *num) { int strCount = 0; while(1) { if(m.available()>0) { char key = NULL; // Obligation de lire 2 buffer en cas de touche Menu key = m.getKey(); if(key != NULL) { if (m.isMenuKey() == true) { key = m.getKey(); if (key == '8') { /**** AJOUTER LE CHAR FIN DE COM MANDE AT PUIS PASSER SAISIE MESSAGES ****/ num[strCount]='\0'; return; } } else { m.textChar(key); //print sur minitel // Serial.print(key); //print sur le prompt num[strCount] = key; strCount++; strCount%=19; } } } } } void saisieTxt(char *txt) { int strCount = 0; m.text("Message : ", 1, 6); m.moveCursorTo(1,7); /*** COMMANDE ATM ***/ while(1) { if(m.available()>0) { char key = NULL; // Obligation de lire 2 buffer en cas de touche Menu key = m.getKey(); if(key != NULL) { if (m.isMenuKey() == true) { key = m.getKey(); if (key == '8') { txt[strCount]='\x1a'; txt[strCount+1]='\r'; txt[strCount+2]='\0'; return; } } else { m.textChar(key); txt[strCount] = key; strCount++; strCount%=159; } } } } } void saisiePin(char *pin) { int strCount = 0; while(1) { if(m.available()>0) { char key = NULL; // Obligation de lire 2 buffer en cas de touche Menu key = m.getKey(); if(key != NULL) { if (m.isMenuKey() == true) { key = m.getKey(); if (key == '8') { /**** AJOUTER LE CHAR FIN DE COM MANDE AT PUIS PASSER SAISIE MESSAGES ****/ pin[strCount]='\0'; return; } } else { m.textChar('*'); //print sur minitel // Serial.print(key); //print sur le prompt pin[strCount] = key; strCount++; strCount%=19; } } } } } void send_AT_cmd(const char *at_cmd, char *at_rep) { Serial1.print(at_cmd); int strCount = 0; Serial.println(at_cmd); delay(100); while(Serial1.available()>0) { char reponse = Serial1.read(); at_rep[strCount] = reponse; strCount++; } at_rep[strCount]='\0'; delay(1000); }