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.

88 lines
2.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
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. const int pins[2][3] = {{5,4,16},{2,14,0}};
  7. WiFiServer listenServer(31);
  8. WiFiServer broadcastServer(69);
  9. int lights[2] = {0,2};
  10. void setup() {
  11. Serial.begin(115200);
  12. pinMode(12,OUTPUT);
  13. delay(1000);
  14. WiFi.begin(ssid, password);
  15. while (WiFi.status() != WL_CONNECTED) {
  16. digitalWrite(12,HIGH);
  17. delay(150);
  18. Serial.println("Connecting..");
  19. digitalWrite(12,LOW);
  20. delay(150);
  21. }
  22. Serial.print("Connected to WiFi. IP:");
  23. Serial.println(WiFi.localIP());
  24. for(int i = 0; i<2;i++){
  25. for(int j = 0; j<3; j++){
  26. pinMode(pins[i][j],OUTPUT);
  27. }
  28. }
  29. listenServer.begin();
  30. broadcastServer.begin();
  31. digitalWrite(12,HIGH);
  32. }
  33. void loop() {
  34. WiFiClient listener = listenServer.available();
  35. WiFiClient sender = broadcastServer.available();
  36. String message = "";
  37. if (listener) {
  38. while (listener.connected()) {
  39. if(!sender){
  40. Serial.println("Waiting sender");
  41. sender = broadcastServer.available();
  42. }
  43. message = "";
  44. while (listener.available()>0) {
  45. char c = listener.read();
  46. message += c;
  47. }
  48. if(message != ""){
  49. lights[0] =message.charAt(0)-'0';
  50. lights[1] = message.charAt(2)-'0';
  51. Serial.println(lights[0]);
  52. Serial.println(lights[1]);
  53. for(int i = 0; i<2;i++){
  54. for(int j = 0; j<3; j++){
  55. if(j == lights[i]){
  56. digitalWrite(pins[i][j],HIGH);
  57. continue;
  58. }
  59. digitalWrite(pins[i][j],LOW);
  60. }
  61. }
  62. Serial.println(message);
  63. Serial.print("Connected:");
  64. Serial.println(sender.connected());
  65. Serial.print("Available:");
  66. Serial.println(sender.available());
  67. if(sender && sender.connected()){
  68. Serial.println("Bookmark 1");
  69. sender.println(message);
  70. }
  71. }
  72. delay(10);
  73. }
  74. sender.stop();https://www.hackthebox.eu/login
  75. listener.stop();
  76. }
  77. }