schneider françois
/
0-sim800l-F746ZG-6obj
Exemple SIM 800L avec SMS lib
main.cpp@6:f0530b05daa3, 2022-04-30 (annotated)
- Committer:
- schnf30
- Date:
- Sat Apr 30 20:07:31 2022 +0000
- Revision:
- 6:f0530b05daa3
- Parent:
- 4:0ddc4eb09bee
VERS 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
schnf30 | 0:bdd51c67f2e6 | 1 | #include "mbed.h" |
schnf30 | 0:bdd51c67f2e6 | 2 | #include "platform/mbed_thread.h" |
schnf30 | 0:bdd51c67f2e6 | 3 | #include "sim800l.h" |
schnf30 | 0:bdd51c67f2e6 | 4 | |
schnf30 | 0:bdd51c67f2e6 | 5 | // Blinking rate in milliseconds |
schnf30 | 0:bdd51c67f2e6 | 6 | #define BLINKING_RATE_MS 500 |
schnf30 | 0:bdd51c67f2e6 | 7 | RawSerial pc(USBTX,USBRX); |
schnf30 | 1:c4962c9ddccf | 8 | Ticker T1s; |
schnf30 | 1:c4962c9ddccf | 9 | bool EnvoiSms30s; |
schnf30 | 1:c4962c9ddccf | 10 | int heure=0, minute=0, seconde=0; |
schnf30 | 1:c4962c9ddccf | 11 | char Phrase[1000]; // pour convertir en phrase avant envoi |
schnf30 | 1:c4962c9ddccf | 12 | void Ft1s() |
schnf30 | 0:bdd51c67f2e6 | 13 | { |
schnf30 | 1:c4962c9ddccf | 14 | if (seconde >= 59) { |
schnf30 | 1:c4962c9ddccf | 15 | seconde = 0; |
schnf30 | 1:c4962c9ddccf | 16 | if (minute >= 59) { |
schnf30 | 1:c4962c9ddccf | 17 | minute = 0; |
schnf30 | 1:c4962c9ddccf | 18 | if (heure >= 23) heure = 0; |
schnf30 | 1:c4962c9ddccf | 19 | else heure++; |
schnf30 | 1:c4962c9ddccf | 20 | } else minute++; |
schnf30 | 1:c4962c9ddccf | 21 | } else seconde ++; |
schnf30 | 1:c4962c9ddccf | 22 | if ((seconde == 0)||(seconde == 30)) EnvoiSms30s = true; |
schnf30 | 0:bdd51c67f2e6 | 23 | } |
schnf30 | 1:c4962c9ddccf | 24 | Sim800l Sim800L(PC_10,PC_11,PC_12,115200); |
schnf30 | 0:bdd51c67f2e6 | 25 | |
schnf30 | 0:bdd51c67f2e6 | 26 | int main() |
schnf30 | 0:bdd51c67f2e6 | 27 | { |
schnf30 | 1:c4962c9ddccf | 28 | EnvoiSms30s = false; |
schnf30 | 0:bdd51c67f2e6 | 29 | pc.baud(921600); |
schnf30 | 0:bdd51c67f2e6 | 30 | pc.printf("Bonjour\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 31 | pc.printf("Patientez init sim800l : "); |
schnf30 | 0:bdd51c67f2e6 | 32 | if (Sim800L.init()) pc.printf("ok.\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 33 | else pc.printf("Erreur.\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 34 | pc.printf("Efface all SMS : "); |
schnf30 | 0:bdd51c67f2e6 | 35 | if (Sim800L.smsclearall()) pc.printf("ok.\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 36 | else pc.printf("Erreur.\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 37 | pc.printf("Envoi Sms : "); |
schnf30 | 3:99aff292a6c6 | 38 | if (Sim800L.sendsms("+33xxxxxxxxx","Bonjour 22-04-2022")) pc.printf("ok.\r\n"); |
schnf30 | 1:c4962c9ddccf | 39 | else pc.printf("erreur.\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 40 | // Initialise the digital pin LED1 as an output |
schnf30 | 0:bdd51c67f2e6 | 41 | DigitalOut led(LED1); |
schnf30 | 6:f0530b05daa3 | 42 | T1s.attach(callback(&Ft1s),1); |
schnf30 | 0:bdd51c67f2e6 | 43 | while (true) { |
schnf30 | 0:bdd51c67f2e6 | 44 | // led = !led; |
schnf30 | 0:bdd51c67f2e6 | 45 | // thread_sleep_for(BLINKING_RATE_MS); |
schnf30 | 1:c4962c9ddccf | 46 | if (EnvoiSms30s) { |
schnf30 | 0:bdd51c67f2e6 | 47 | pc.printf("Envoi sms 30s : "); |
schnf30 | 1:c4962c9ddccf | 48 | sprintf(Phrase,"time %d:%d:%d\r\n",heure,minute,seconde); |
schnf30 | 3:99aff292a6c6 | 49 | if (Sim800L.sendsms("+33xxxxxxxxx",Phrase)) pc.printf("ok.\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 50 | else pc.printf("erreur.\r\n"); |
schnf30 | 1:c4962c9ddccf | 51 | EnvoiSms30s = false; |
schnf30 | 0:bdd51c67f2e6 | 52 | } |
schnf30 | 0:bdd51c67f2e6 | 53 | if (Sim800L.smsready()) { |
schnf30 | 0:bdd51c67f2e6 | 54 | led = 1; |
schnf30 | 0:bdd51c67f2e6 | 55 | pc.printf("Recois SMS, index : %d\r\n",Sim800L.IndexSmsRecu()); |
schnf30 | 0:bdd51c67f2e6 | 56 | Sim800L.readsms(Sim800L.IndexSmsRecu()); |
schnf30 | 0:bdd51c67f2e6 | 57 | pc.printf("Texte sms recu --- \r\n%s\r\n",Sim800L.readtextesms()); |
schnf30 | 0:bdd51c67f2e6 | 58 | pc.printf("Reponse SMS : "); |
schnf30 | 4:0ddc4eb09bee | 59 | if (Sim800L.sendsms("+33xxxxxxxxx",Sim800L.readtextesms())) pc.printf("ok.\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 60 | else pc.printf("erreur.\r\n"); |
schnf30 | 0:bdd51c67f2e6 | 61 | led = 0; |
schnf30 | 0:bdd51c67f2e6 | 62 | } |
schnf30 | 0:bdd51c67f2e6 | 63 | } |
schnf30 | 0:bdd51c67f2e6 | 64 | } |