Programme GSM M95 v2.0

Dependencies:   mbed

Fork of mbed_m95 by TeamLegrand

Files at this revision

API Documentation at this revision

Comitter:
Quentin19
Date:
Fri Mar 16 07:55:36 2018 +0000
Parent:
2:f3d64c53f369
Commit message:
Programme d'envoi de sms pour module GSM M95

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f3d64c53f369 -r 41229ebb1467 main.cpp
--- a/main.cpp	Sun Mar 11 21:33:47 2018 +0000
+++ b/main.cpp	Fri Mar 16 07:55:36 2018 +0000
@@ -9,6 +9,7 @@
  void init_gsm();   // to init gsm modem
  void data_gsm();    //to receive a reply from gsm
  void reset_buffer();   // to reset rx buffer
+ void power_off(); // Pour eteindre le module gsm
   
  DigitalOut led1(LED1);
  DigitalOut led2(LED2);
@@ -23,9 +24,9 @@
 Serial pc(USBTX, USBRX); // creation objet -> stream serial USB
 Serial gsm(p9,p10); // creation objet -> stream serial uart p9 et p10
 
-char numero_destinataire[20]={"xxxxxxxxxx"};;
-char message_transmis[100]={"Hello world ! Lycee Cabanis Brive SN2 !"};
-char code_pin[5]={"0000"};
+
+char message_transmis[100]={"Module GSM "};
+char code_pin[5]={"1234"};
 char reponse_gsm[256];
 int element=0;  //indice pour tableau
 int octet=0;
@@ -45,17 +46,18 @@
     init_gsm();
     pc.printf("Appuyez sur ''bp enter'' pour envoi SMS");
     pc.printf("\n\r>");
+    
       
     while (1) {          
         
         if(bp_fire==1){
             // envoi message SMS au N° pré-saisi           
-            gsm.printf("AT+CMGS=%s\r",numero_destinataire);
+            gsm.printf("AT+CMGS=\"0618981390\" \r");
             gsm.printf("%s",message_transmis);
             gsm.putc(0x1A); // envoi ctrl+Z
             //wait(30);   // l'envoi du message SMS prends en 120 s maximum
             
-            pc.printf("AT+CMGS=%s\r",numero_destinataire);
+            pc.printf("AT+CMGS=\"0618981390\" \r");
             pc.printf("\n\r>");
             pc.printf("%s",message_transmis);
             pc.putc(0x1A); // envoi ctrl+Z
@@ -70,7 +72,10 @@
             pc.printf("\n\r>");
             }
     }
+        
 }
+
+
        
 // to turn on_off le modem gsm m95
 void power_on(){
@@ -85,12 +90,13 @@
     }
     
 void power_off(){
-    pwrkey=1;   // création impulsion turn on sur ligne pwrkey
-    wait(0.8);
-    pwrkey=0;
-    while(status==1);
-    led1=0; 
-    }
+    while(bp_fire==1){
+        gsm.printf("AT+QPOWD=1\r");
+        wait(0.3);
+        pc.printf("Arret en cours...\r\n");
+        data_gsm();
+    } 
+}
     
 // to turn on_off le modem gsm m95
 void reset(){
@@ -154,85 +160,69 @@
     //wait(5);
     power_on(); // modem on
     
-    wait(10);
+    wait(5); //10 ok
     //reply_gsm(5);  // réponse du gsm;
     //reply_gsm(11);  // réponse du gsm;
     
     gsm.printf("AT\r"); // report erreur gsm
     data_gsm();
-    wait(1);
-    pc.printf("AT\r");
+    pc.printf("AT\r\n");
+    
+    gsm.printf("AT+CPIN=1234\r",code_pin);
+    //gsm.printf("AT+CPIN?");
+    wait(5);
+    pc.printf("AT+CPIN=1234\r");
+    data_gsm();
     
-    gsm.printf("AT?\r");
-    pc.printf("AT?\r");
-    data_gsm();   
     gsm.printf("ATE0\r"); // pas d'echo vers le DTE pour les l'envoi des commandes
-    wait(1);
-    gsm.printf("ATE0?\r"); // 
-    pc.printf("ATE0?\r"); // 
+    wait(2);
+    //gsm.printf("ATE0?\r"); //
+    pc.printf("ATE0\r\n"); // 
+    data_gsm();
+    
+                                                                               
+    gsm.printf("AT+CSQ\r"); // Query the signal strength of current network
+    wait(2);
+    gsm.printf("AT+CSQ?\r"); // 
+    pc.printf("AT+CSQ?\r\n"); // 
     data_gsm();
     
     gsm.printf("AT+COPS=?\r"); // pour voir la Operator Selection
-    wait(10);   // 75s max. déterminé par le réseau
-    pc.printf("AT+COPS?\r"); // 
-    data_gsm();
-    
-         
-    
-    gsm.printf("AT+CSQ\r"); // Query the signal strength of current network
-    wait(1);
-    gsm.printf("AT+CSQ?\r"); // 
-    pc.printf("AT+CSQ?\r"); // 
+    gsm.printf("AT+COPS?\r\n");
+    wait(25);   // 75s max. déterminé par le réseau
+    pc.printf("AT+COPS?\r\n"); //
     data_gsm();
     
     
     gsm.printf("AT+CREG?\r"); // enregistrement du réseau
-    wait(1);
-    pc.printf("AT+CGREG?\r"); // 
+    wait(0.3);
+    pc.printf("AT+CREG?\r\n"); // 
+    data_gsm(); 
+   
+    
+    gsm.printf("AT+CMEE=2\r"); // report erreur gsm
+    wait(0.3);
+    pc.printf("AT+CMEE=2\r\n"); // report erreur gsm
     data_gsm();
     
-    gsm.printf("AT+COPS?\r"); // enregistrement du réseau
-    wait(1);
-    pc.printf("AT+COPS?\r"); // 
-    data_gsm();
-           
-    gsm.printf("AT+IPR=9600\r"); // vitesse transmission fixée (recommandé)
-    wait(1);
-    gsm.printf("AT+IPR?\r"); // vitesse transmission fixée (recommandé)
-    pc.printf("AT+IPR?\r"); // vitesse transmission fixée (recommandé)
-    data_gsm();
-       
-    gsm.printf("AT&W\r"); // stokage vitesse
-    wait(1);
-    gsm.printf("AT&W?\r"); // stokage vitesse
-    pc.printf("AT&W?\r"); // stokage vitesse
+    gsm.printf("AT+CMEE?\r"); // report erreur gsm
+    wait(0.3);
+    pc.printf("AT+CMEE?\r"); // report erreur gsm
     data_gsm();
     
-    gsm.printf("AT+CMGF=1\r"); // sélection du format du message SMS
-    wait(2);
-    gsm.printf("AT+CMGF?"); // sélection du format du message SMS
-    pc.printf("AT+CMGF?"); // sélection du format du message SMS
-    data_gsm();
-    
-    gsm.printf("AT+CMEE=2\r"); // report erreur gsm
-    wait(1);
-    gsm.printf("AT+CMEE?"); // report erreur gsm
-    pc.printf("AT+CMEE?"); // report erreur gsm
-    data_gsm();
-       
-    gsm.printf("AT+CPIN=%s\r",code_pin); // stockage du PIN
-    wait(6);
-    gsm.printf("AT+CPIN?"); // stockage du PIN
-    pc.printf("AT+CPIN?"); // stockage du PIN
-    data_gsm();
-    
-    
     
     gsm.printf("AT+CMGF=1\r"); // sélection du format du message SMS
     wait(2);
-    gsm.printf("AT+CMGF?"); // sélection du format du message SMS
-    pc.printf("AT+CMGF?"); // sélection du format du message SMS
+    //gsm.printf("AT+CMGF?"); // sélection du format du message SMS
+    pc.printf("AT+CMGF=1\r\n"); // sélection du format du message SMS
     data_gsm();
     
+    gsm.printf("AT+CMGF?\r"); // sélection du format du message SMS
+    wait(2);
+    //gsm.printf("AT+CMGF?"); // sélection du format du message SMS
+    pc.printf("AT+CMGF?\r\n"); // sélection du format du message SMS
+    data_gsm();
+  }  
     
-    } 
+    
+