Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. void setup() {
  2. Serial.begin(9600);
  3. WiFi.mode(WIFI_AP);
  4. WiFi.softAP("myap", "mypass");
  5. WiFi.softAPConfig(IP, IP, mask);
  6. server.begin();
  7. }
  8. void loop() {
  9. WiFiClient client = server.available();
  10. if (!client) {
  11. return;
  12. }
  13. String request = client.readStringUntil('r');
  14. Serial.println("From STA: " + request);
  15. client.println("DATA 1r"); // data 1
  16. client.println("DATA 2r"); // data 2
  17.  
  18.  
  19. client.flush();
  20. client.stop();
  21. }
  22.  
  23. void setup() {
  24. Serial.begin(9600);
  25. WiFi.mode(WIFI_STA);
  26. WiFi.begin(ssid, pass);
  27. while (WiFi.status() != WL_CONNECTED) {
  28. Serial.print(".");
  29. delay(300);
  30. }
  31. }
  32. void loop() {
  33. client.connect(server, 80);
  34. client.print("DATA 3 r");
  35. String answer = client.readStringUntil('r');
  36. Serial.println("From AP: " + answer);
  37. client.flush();
  38. client.stop();
  39. }
  40.  
  41. From STA: DATA 3
  42. From STA: DATA 3
  43. From STA: DATA 3
  44. .
  45. .
  46. .
  47.  
  48. From AP: DATA 1
  49. From AP: DATA 1
  50. From AP: DATA 1
  51. .
  52. .
  53. .
  54.  
  55. 0-> loop start
  56. 1-> Client Connect
  57. 2-> Get Request Client -> (async (not waiting request))
  58. 3-> send client "data 1" -> Send OKAY (async)
  59. 4-> send client "data 2" -> Send Okay (async)
  60. 5-> client disconnect -> (because need new clients connect (1) ) -> max 8 client.
  61. 6-> loop again.
  62.  
  63. 0-> loop start
  64. 1-> server connect (async)
  65. 2-> send server "data 3" -> (async)
  66. 3-> get "data" from server -> only works first data.!! (async)
  67. (This problem.) im need get all data.
  68. 4-> show data in Serial -> (async)
  69. 5-> disconnect from server (because) server-> allows 1 connection at the same time
  70. 6-> loop again
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement