Minitel_SM.ino 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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, char *at_rep);
  7. void send_sms();
  8. void enter_pin();
  9. // CAYE PAS BIEN ET JMEN FOUT !
  10. char rep[50];
  11. void setup()
  12. {
  13. /****Init Shield GPRS Hardware mode*****/
  14. Serial.begin(19200);
  15. Serial1.begin(19200);
  16. /****Simulation ON/OFF*****/
  17. // pinMode(8, OUTPUT);
  18. // digitalWrite(8, HIGH);
  19. char rep[30];
  20. char mess_ok[50];
  21. m.clearScreen();
  22. m.textMode();
  23. m.textColor(WHITE);
  24. m.bgColor(BLACK);
  25. m.text(" Smartphone Minitel V1 ", 1, 1);
  26. /**** check du pin *****/
  27. send_AT_cmd("AT+CPIN?\r", rep);
  28. Serial.println(rep);
  29. if (strstr(rep, "READY") == NULL) {
  30. m.blink();
  31. m.text("[ ] Check for pin lock... ", 2, 3);
  32. m.text("Enter PIN code : ", 2, 4);
  33. enter_pin();
  34. }
  35. m.noBlink();
  36. m.text("[*] PIN code is good ! ", 2, 3);
  37. m.text("[ ]", 2, 5);
  38. m.blink();
  39. m.text("Waiting for Auth Network .....", 6, 5);
  40. send_AT_cmd("AT+COPS?\r", rep);
  41. Serial.print(rep);
  42. char *token;
  43. token = strtok(rep, " ");
  44. while (token == NULL) {
  45. delay(100);
  46. }
  47. sprintf(mess_ok, "You are connected to %s", token);
  48. m.noBlink();
  49. m.text("[*]", 2, 5);
  50. m.text(mess_ok, 5, 5);
  51. send_AT_cmd("AT+CGREG?\r\r", rep);
  52. Serial.print(rep);
  53. delay(1000);
  54. }
  55. void loop()
  56. {
  57. m.clearScreen();
  58. m.textMode();
  59. m.textColor(WHITE);
  60. m.bgColor(RED);
  61. m.text(" Smartphone Minitel V1 ", 1, 1);
  62. m.text(" Operator : XXXXXX", 1, 23);
  63. m.bgColor(BLACK);
  64. m.text("1 - Send SMS", 4, 5 );
  65. m.text("2 - Read SMS", 4, 6 );
  66. while(1) {
  67. if(m.available()>0) {
  68. char key = NULL;
  69. // Obligation de lire 2 buffer en cas de touche Menu
  70. key = m.getKey();
  71. switch(key) {
  72. case '1':
  73. send_sms();
  74. break;
  75. case '2':
  76. break;
  77. }
  78. }
  79. }
  80. delay(1000);
  81. }
  82. void enter_pin()
  83. {
  84. char pin[5];
  85. char at_pin[12];
  86. saisieNum(pin);
  87. sprintf(at_pin, "AT+CPIN=%s\r", pin);
  88. Serial.print(pin);
  89. send_AT_cmd(at_pin, rep);
  90. Serial.print(rep);
  91. return;
  92. }
  93. void send_sms()
  94. {
  95. m.clearScreen();
  96. m.textMode();
  97. m.textColor(WHITE);
  98. m.bgColor(RED);
  99. m.text(" Send SMS ", 4, 1);
  100. m.bgColor(BLACK);
  101. m.text("Number : +", 1, 4);
  102. m.cursor();
  103. m.moveCursorTo(12,4);
  104. char num[20];
  105. char txt[160];
  106. // char *cmgs = "AT+CMGS=\"+";
  107. // char *endcmgs = "\"";
  108. char cmdcmgs[100];
  109. // strcpy(cmdcmgs, cmgs);
  110. // Serial.print(cmdcmgs);
  111. // send_AT_cmd("AT+CGATT?\r");
  112. saisieNum(num);
  113. saisieTxt(txt);
  114. // Serial.print(num);
  115. // strcat(cmdcmgs, num);
  116. // Serial.print(cmdcmgs);
  117. // strcat(cmdcmgs, endcmgs);
  118. send_AT_cmd("AT+CMGF=1\r", rep); //Mode texte pour SMS
  119. delay(100);
  120. sprintf(cmdcmgs, "AT+CMGS=\"+%s\"\r", num);
  121. send_AT_cmd(cmdcmgs, rep);
  122. send_AT_cmd(txt, rep);
  123. delay(1000);
  124. return loop();
  125. }
  126. void saisieNum(char *num) {
  127. int strCount = 0;
  128. while(1) {
  129. if(m.available()>0) {
  130. char key = NULL;
  131. // Obligation de lire 2 buffer en cas de touche Menu
  132. key = m.getKey();
  133. if(key != NULL) {
  134. if (m.isMenuKey() == true) {
  135. key = m.getKey();
  136. if (key == '8') {
  137. /**** AJOUTER LE CHAR FIN DE COM MANDE AT PUIS PASSER SAISIE MESSAGES ****/
  138. num[strCount]='\0';
  139. return;
  140. }
  141. }
  142. else {
  143. m.textChar(key); //print sur minitel
  144. // Serial.print(key); //print sur le prompt
  145. num[strCount] = key;
  146. strCount++;
  147. strCount%=19;
  148. }
  149. }
  150. }
  151. }
  152. }
  153. void saisieTxt(char *txt) {
  154. int strCount = 0;
  155. m.text("Message : ", 1, 6);
  156. m.moveCursorTo(1,7);
  157. /*** COMMANDE ATM ***/
  158. while(1) {
  159. if(m.available()>0) {
  160. char key = NULL;
  161. // Obligation de lire 2 buffer en cas de touche Menu
  162. key = m.getKey();
  163. if(key != NULL) {
  164. if (m.isMenuKey() == true) {
  165. key = m.getKey();
  166. if (key == '8') {
  167. txt[strCount]='\x1a';
  168. txt[strCount+1]='\r';
  169. txt[strCount+2]='\0';
  170. return;
  171. }
  172. }
  173. else {
  174. m.textChar(key);
  175. txt[strCount] = key;
  176. strCount++;
  177. strCount%=159;
  178. }
  179. }
  180. }
  181. }
  182. }
  183. void send_AT_cmd(const char *at_cmd, char *at_rep)
  184. {
  185. Serial1.print(at_cmd);
  186. int strCount = 0;
  187. Serial.println(at_cmd);
  188. delay(100);
  189. while(Serial1.available()>0) {
  190. char reponse = Serial1.read();
  191. at_rep[strCount] = reponse;
  192. strCount++;
  193. }
  194. at_rep[strCount]='\0';
  195. delay(1000);
  196. }