You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.5 KiB

6 years ago
  1. #include "Arduino.h"
  2. #include "Esp.h"
  3. #include "ESP8266WiFi.h"
  4. const char* ssid = "AirTies_Air5343";
  5. const char* password = "yigit007";
  6. WiFiServer listenServer(31);
  7. WiFiServer broadcastServer(69);
  8. void setup() {
  9. Serial.begin(115200);
  10. pinMode(12,OUTPUT);
  11. delay(1000);
  12. WiFi.begin(ssid, password);
  13. while (WiFi.status() != WL_CONNECTED) {
  14. digitalWrite(12,HIGH);
  15. delay(150);
  16. Serial.println("Connecting..");
  17. digitalWrite(12,LOW);
  18. delay(150);
  19. }
  20. Serial.print("Connected to WiFi. IP:");
  21. Serial.println(WiFi.localIP());
  22. listenServer.begin();
  23. broadcastServer.begin();
  24. digitalWrite(12,HIGH);
  25. }
  26. void loop() {
  27. WiFiClient listener = listenServer.available();
  28. WiFiClient sender = broadcastServer.available();
  29. String message = "";
  30. if (listener) {
  31. while (listener.connected()) {
  32. if(!sender){
  33. Serial.println("Waiting sender");
  34. sender = broadcastServer.available();
  35. }
  36. message = "";
  37. while (listener.available()>0) {
  38. char c = listener.read();
  39. message += c;
  40. }
  41. if(message != ""){
  42. Serial.println(message);
  43. Serial.print("Connected:");
  44. Serial.println(sender.connected());
  45. Serial.print("Available:");
  46. Serial.println(sender.available());
  47. if(sender && sender.connected()){
  48. Serial.println("Bookmark 1");
  49. sender.println(message);
  50. sender.stop();
  51. }
  52. }
  53. delay(10);
  54. }
  55. listener.stop();
  56. }
  57. }