Minitel_SM.ino 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include <SoftwareSerial.h>
  2. #include <Minitel.h>
  3. Minitel m(53,52); //Dfinition pour le Serial du Minitel
  4. void saisieNum(char *num);
  5. void saisieTxt(char *txt);
  6. void send_AT_cmd(const char *at_cmd);
  7. void setup()
  8. {
  9. /****Init Shield GPRS Hardware mode*****/
  10. Serial.begin(19200);
  11. Serial1.begin(19200);
  12. /****Simulation ON/OFF*****/
  13. // pinMode(8, OUTPUT);
  14. // digitalWrite(8, HIGH);
  15. m.clearScreen();
  16. /**** Saisie future du code PIN *****/
  17. m.text("[*] Set pin code ", 2, 1);
  18. send_AT_cmd("AT+CPIN=2507\r");
  19. m.textMode();
  20. m.textColor(WHITE);
  21. m.bgColor(BLACK);
  22. m.text("[ ]", 2, 3);
  23. m.blink();
  24. m.text("Waiting for Auth Network .....", 6, 3);
  25. m.noBlink();
  26. m.text("[*]", 2, 3);
  27. m.text("You are now connected ! ", 6, 3);
  28. send_AT_cmd("AT+CGREG?\r");
  29. send_AT_cmd("AT+CMGF=1\r"); //Mode texte pour SMS
  30. }
  31. void loop()
  32. {
  33. char num[20];
  34. char txt[160];
  35. // char *cmgs = "AT+CMGS=\"+";
  36. // char *endcmgs = "\"";
  37. char cmdcmgs[100];
  38. // strcpy(cmdcmgs, cmgs);
  39. // Serial.print(cmdcmgs);
  40. //send_AT_cmd("AT+CGATT?\r");
  41. saisieNum(num);
  42. saisieTxt(txt);
  43. //Serial.print(num);
  44. // strcat(cmdcmgs, num);
  45. // Serial.print(cmdcmgs);
  46. // strcat(cmdcmgs, endcmgs);
  47. sprintf(cmdcmgs, "AT+CMGS=\"+%s\"%s\n", num, txt);
  48. send_AT_cmd(cmdcmgs);
  49. }
  50. void saisieNum(char *num) {
  51. int strCount = 0;
  52. m.clearScreen();
  53. m.textMode();
  54. m.textColor(WHITE);
  55. m.bgColor(RED);
  56. m.text(" SMS Sender ", 4, 1);
  57. m.bgColor(BLACK);
  58. m.text("Number : +", 1, 4);
  59. m.cursor();
  60. m.moveCursorTo(12,4);
  61. delay(100);
  62. delay(100);
  63. while(1) {
  64. if(m.available()>0) {
  65. char key = NULL;
  66. // Obligation de lire 2 buffer en cas de touche Menu
  67. key = m.getKey();
  68. if(key != NULL) {
  69. if (m.isMenuKey() == true) {
  70. key = m.getKey();
  71. if (key == '8') {
  72. /**** AJOUTER LE CHAR FIN DE COM MANDE AT PUIS PASSER SAISIE MESSAGES ****/
  73. num[strCount]='\0';
  74. return;
  75. }
  76. }
  77. else {
  78. m.textChar(key); //print sur minitel
  79. // Serial.print(key); //print sur le prompt
  80. num[strCount] = key;
  81. strCount++;
  82. strCount%=19;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. void saisieTxt(char *txt) {
  89. int strCount = 0;
  90. m.text("Message : ", 1, 6);
  91. m.moveCursorTo(1,7);
  92. /*** COMMANDE ATM ***/
  93. while(1) {
  94. if(m.available()>0) {
  95. char key = NULL;
  96. // Obligation de lire 2 buffer en cas de touche Menu
  97. key = m.getKey();
  98. if(key != NULL) {
  99. if (m.isMenuKey() == true) {
  100. key = m.getKey();
  101. if (key == '8') {
  102. txt[strCount]='\x1a';
  103. txt[strCount+1]='\0';
  104. return;
  105. }
  106. }
  107. else {
  108. m.textChar(key);
  109. txt[strCount] = key;
  110. strCount++;
  111. strCount%=159;
  112. }
  113. }
  114. }
  115. }
  116. }
  117. void send_AT_cmd(const char *at_cmd)
  118. {
  119. Serial1.println(at_cmd);
  120. Serial.println(at_cmd);
  121. while(Serial1.available()>0) {
  122. char reponse = Serial1.read();
  123. Serial.print(reponse);
  124. }
  125. delay(1000);
  126. }