Guest User

Untitled

a guest
May 13th, 2017
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "SoftwareSerial.h"
  2.  
  3. SoftwareSerial esp8266(2, 3); // RX, TX
  4.  
  5. void setup()
  6. {
  7. Serial.begin(9600); // serial port used for debugging
  8. esp8266.begin(115200); // your ESP's baud rate might be different
  9. }
  10.  
  11. void loop()
  12. {
  13. if(esp8266.available()) // check if the ESP is sending a message
  14. {
  15. while(esp8266.available())
  16. {
  17. char c = esp8266.read(); // read the next character.
  18.  
  19. Serial.println(c); // writes data to the serial monitor
  20. }
  21. }
  22.  
  23. if(Serial.available())
  24. {
  25. delay(10); // wait to let all the input command in the serial buffer
  26. // read the input command in a string
  27. String cmd = "";
  28. while(Serial.available())
  29. {
  30. cmd += (char)Serial.read();
  31. }
  32. // send to the esp8266
  33. esp8266.println(cmd);
  34. }
  35. }
RAW Paste Data