Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <WiFiServer.h>
  4. #include <WiFiUdp.h>
  5.  
  6. WiFiServer server(80);
  7.  
  8. char serialString[10];
  9.  
  10. void setup() {
  11.  
  12. pinMode(14,OUTPUT);
  13. Serial.begin(9600);
  14. Serial.end();
  15. Serial.begin(9600);
  16. Serial.println("Starting up");
  17. WiFi.begin("Fane Home", "fararestante");
  18. Serial.print("Connecting...");
  19. while (WiFi.status() != WL_CONNECTED) {
  20. delay(500);
  21. Serial.print(".");
  22. }
  23. Serial.print("Connected ");
  24. Serial.print(WiFi.localIP());
  25. server.begin();
  26.  
  27. }
  28.  
  29. void loop() {
  30. WiFiClient client = server.available();
  31.  
  32. if(client){
  33. String req = client.readStringUntil('\r');
  34. client.flush();
  35. Serial1.println(req);
  36. if (req.indexOf("/bpm/") != -1) {
  37. strcpy(serialString,"bpm");
  38. String bpmString = req.substring(req.indexOf("/bpm/")+5,req.indexOf("/bpm/")+8);
  39. char bpmChar[10] = "";
  40. bpmString.toCharArray(bpmChar,10);
  41. strcat(serialString,bpmChar);
  42. Serial.write(serialString,10);
  43. }
  44. else if (req.indexOf("/brg/") != -1) {
  45. strcpy(serialString,"brg");
  46. String brgString = req.substring(req.indexOf("/brg/")+5,req.indexOf("/brg/")+8);
  47. char brgChar[10] = "";
  48. brgString.toCharArray(brgChar,10);
  49. strcat(serialString,brgChar);
  50. Serial.write(serialString,10);
  51. }
  52. else if (req.indexOf("/muz/1") != -1) {
  53. strcpy(serialString,"muz1");
  54. Serial.write(serialString,4);
  55. }
  56. else if (req.indexOf("/muz/2") != -1) {
  57. strcpy(serialString,"muz2");
  58. Serial.write(serialString,4);
  59. }
  60. else if (req.indexOf("/eco/") != -1){
  61. strcpy(serialString,"eco");
  62. Serial.write(serialString,4);
  63. }
  64. else if (req.indexOf("/clr/") != -1){
  65. strcpy(serialString,"clr");
  66. Serial.write(serialString,4);
  67. }
  68. else if (req.indexOf("/col/") != -1){
  69. strcpy(serialString,"col");
  70. String colString = req.substring(req.indexOf("/clr/")+5,req.indexOf("/clr/")+7);
  71. char colChar[10] = "";
  72. colString.toCharArray(colChar,10);
  73. strcat(serialString,colChar);
  74. Serial.write(serialString);
  75. }
  76. else if (req.indexOf("/bth/") != -1){
  77. strcpy(serialString,"bth");
  78. String bthString = req.substring(req.indexOf("/bth/")+5,req.indexOf("/bth/")+8);
  79. char bthChar[10] = "";
  80. bthString.toCharArray(bthChar,10);
  81. strcat(serialString,bthChar);
  82. Serial.write(serialString);
  83. }
  84. else if (req.indexOf("/bhh/") != -1){
  85. strcpy(serialString,"bth");
  86. String bthString = req.substring(req.indexOf("/bhh/")+5,req.indexOf("/bhh/")+8);
  87. int bhhInt = bthString.toInt();
  88. bhhInt = 2400/bhhInt;
  89. char bthChar[10] = "";
  90. itoa(bhhInt, bthChar, 10);
  91. strcat(serialString,bthChar);
  92. Serial.write(serialString);
  93. }
  94. }
  95.  
  96. delay(500);
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement