Advertisement
Guest User

Untitled

a guest
May 26th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. //www.themonoclecat.de
  2. //26. Nov. 2014
  3. //User interface for ESP8266
  4. //For commands in text block form go to very bottom
  5. int buf;
  6. int timer = 0;
  7. void setup()
  8. {
  9. Serial.begin(9600); //Communication with computer
  10. Serial.setTimeout(1000);
  11. Serial1.begin(9600); //Communication with ESP8266
  12. Serial1.setTimeout(5000); //This is very important for the Serial.find() function
  13. }
  14. void nl() //== newline; you need these at the end of every command
  15. {
  16. Serial1.write(13); //same as pressing ctrl+J in 'screen'
  17. Serial1.write(10); //same as pressing ctrl+M in 'screen'
  18. }
  19. void qu() //== a -> " <- symbol; you need this because sadly the Serial.print() command won't send a "
  20. {
  21. Serial1.write(34);
  22. }
  23. void waitdebug() //Print incoming and wait till over
  24. {
  25. wait();
  26. while (Serial1.available() > 0)
  27. {
  28. delay(10);
  29. Serial.write(Serial1.read());
  30. }
  31. }
  32. void wait()
  33. {
  34. while (Serial1.available() == 0)
  35. {
  36. if (timer >= 10)
  37. {
  38. timer = 0;
  39. Serial.print(".");
  40. }
  41. timer += 1;
  42. delay(100);
  43. }
  44. }
  45. void loop()
  46. {
  47. while (Serial.available() > 0)
  48. {
  49. buf = Serial.read();
  50. switch (buf)
  51. {
  52. case '@': //much information about the ESP8266
  53. Serial.print("Own IP: ");
  54. Serial1.print("AT+CIFSR");
  55. nl();
  56. waitdebug();
  57. Serial.print("Parameters of own AP: ");
  58. Serial1.print("AT+CWSAP?");
  59. nl();
  60. waitdebug();
  61. Serial.print("Connected devices' IP: ");
  62. Serial1.print("AT+CWLIF");
  63. nl();
  64. waitdebug();
  65. Serial.print("The AP the ESP is connected to: ");
  66. Serial1.print("AT+CWJAP?");
  67. nl();
  68. waitdebug();
  69. Serial.print("Connection status: ");
  70. Serial1.print("AT+CIPSTATUS");
  71. nl();
  72. break;
  73.  
  74. case '$': //Connect to Router
  75. Serial1.print("AT+CWMODE=3");
  76. nl();
  77. waitdebug();
  78. Serial1.print("AT+CWJAP=");
  79. qu();
  80. Serial1.print("---enter ssid here--");
  81. qu();
  82. Serial1.print(",");
  83. qu();
  84. Serial1.print("---enter password here---");
  85. qu();
  86. nl();
  87. if (Serial1.find("OK") == true)
  88. {
  89. //Connected to Wifi
  90. Serial.println("--Connected--");
  91. }
  92. else
  93. {
  94. Serial.println("--Not Connected!--");
  95. }
  96. break;
  97.  
  98. case 13:
  99. nl();
  100. break;
  101.  
  102. case '#': //Manual
  103. Serial.println("Own commands: '$'=Connect to Wifi AP '@'=Get lots of info");
  104. Serial.println("Commands (Just copy and paste into screen:");
  105. Serial.println("Baud rate: AT+CIOBAUD? (check) AT+CIOBAUD=57600 (set)");
  106. Serial.println("Wifi mode: AT+CWMODE? AT+CWMODE=3 [1= Sta, 2= AP, 3=both, Sta is the default");
  107. Serial.println(" mode of router, AP is a normal mode for devices]");
  108. Serial.println(" ");
  109. Serial.println("List the APs: AT+CWLAP");
  110. Serial.println("Join AP: AT+CWJAP=<ssid>,<p@$$word>");
  111. Serial.println("Join AP: AT+CWJAP=<ssid>,<p@$$word>");
  112. Serial.println("Current AP: AT+CWJAP?");
  113. Serial.println("Address: AT+CIFSR");
  114. Serial.println(" ");
  115. Serial.println("Set parameters of AP: AT+ CWSAP= <ssid>,<p@$$wordMin8Char>,<chl>, <ecn>");
  116. Serial.println("Current parameters: AT+CWSAP?");
  117. Serial.println(" ");
  118. Serial.println("Check joined devices' IP: AT+CWLIF");
  119. Serial.println(" ");
  120. Serial.println("Set TCP mutiple connection: AT+CIPMUX=<mode> AT+ CIPMUX? [0 for single connection 1 for multiple connection]");
  121. Serial.println("Set as TCP server: AT+ CIPSERVER= <mode>[,<port] [mode 0 to close server mode, mode 1 to open; port = port;");
  122. Serial.println(" ---type IP:Port into browser to connect--- eg. turn on as a TCP server: AT+CIPSERVER=1,8888,");
  123. Serial.println(" check the self server IP address: AT+CIFSR=? ]");
  124. break;
  125.  
  126. default:
  127. Serial1.write(buf);
  128. break;
  129. }
  130. }
  131.  
  132. while (Serial1.available() > 0)
  133. {
  134. Serial.write(Serial1.read());
  135. }
  136. }
  137. /* screen /dev/tty.usbmodem453811
  138. Commands (Just copy and paste into screen):
  139.  
  140. Baud rate: AT+CIOBAUD? (check) AT+CIOBAUD=9600 (set)
  141. Wifi mode: AT+CWMODE? AT+CWMODE=3 [1= Sta, 2= AP, 3=both, Sta is the default
  142. mode of router, AP is a normal mode for devices]
  143. List the APs: AT+CWLAP
  144. Join AP: AT+CWJAP=<ssid>,<p@$$word>
  145. Current AP: AT+CWJAP?
  146. Address: AT+CIFSR
  147. Set parameters of AP: AT+CWSAP=<ssid>,<p@$$wordMin8Char>,<chl>,<ecn> ---- Current: AT+CWSAP="ESP8266 Wifi SoC","teensyyy",7,3
  148. Current parameters: AT+CWSAP?
  149. Check joined devices' IP: AT+CWLIF
  150. TCP:
  151. Set mutiple connection: AT+CIPMUX=<mode> AT+ CIPMUX? [0 for single connection 1 for multiple connection]
  152. Set as server: AT+ CIPSERVER= <mode>[,<port] [mode 0 to close server mode, mode 1 to open; port = port;
  153. ---type IP:Port into browser to connect--- eg. turn on as a TCP server: AT+CIPSERVER=1,8888,
  154. check the self server IP address: AT+CIFSR=? ]
  155. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement