Minitel_SM.ino 5.3 KB

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