safwan092

Untitled

Apr 15th, 2022 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. /*
  2. Connections:
  3. --------------------------------------------
  4. RDIF ESP8266
  5. -------------------
  6. SDA D4
  7. SCK D5
  8. MOSI D7
  9. MISO D6
  10. IRQ N/C
  11. GND G
  12. RST D2
  13. 3.3V 3V
  14.  
  15. RELAY ESP8266
  16. -------------------
  17. DC+ +12V/5V(Breadboard Power Supply)
  18. DC- GND/GND(Breadboard Power Supply)
  19. IN D1
  20. --------------------------------------------
  21. */
  22. #define REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD
  23. #include <ESP8266WiFi.h>
  24. #include <SPI.h>
  25. #include <MFRC522.h>
  26. #include <RemoteXY.h>
  27.  
  28. // RemoteXY connection settings
  29. #define REMOTEXY_WIFI_SSID "network"
  30. #define REMOTEXY_WIFI_PASSWORD "123456789"
  31. #define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
  32. #define REMOTEXY_CLOUD_PORT 6376
  33. #define REMOTEXY_CLOUD_TOKEN "bc73e0a89829394e756869d36a44b277"
  34.  
  35. #define SS_PIN 4
  36. #define RST_PIN 2
  37. int lock = D1;
  38.  
  39. MFRC522 mfrc522(RST_PIN, SS_PIN);
  40.  
  41. int fflag = 0;
  42. int eflag = 0;
  43. int jflag = 0;
  44.  
  45. // RemoteXY configurate
  46. #pragma pack(push, 1)
  47. uint8_t RemoteXY_CONF[] = // 70 bytes
  48. { 255, 3, 0, 11, 0, 63, 0, 16, 31, 1, 67, 4, 18, 17, 20, 5, 2, 26, 11, 2,
  49. 0, 18, 30, 22, 11, 2, 26, 31, 31, 79, 78, 0, 79, 70, 70, 0, 2, 0, 18, 44,
  50. 22, 11, 2, 26, 31, 31, 79, 78, 0, 79, 70, 70, 0, 2, 0, 18, 58, 22, 11, 2,
  51. 26, 31, 31, 79, 78, 0, 79, 70, 70, 0
  52. };
  53.  
  54. // this structure defines all the variables and events of your control interface
  55. struct {
  56.  
  57. // input variables
  58. uint8_t switch_1; // =1 if switch ON and =0 if OFF
  59. uint8_t switch_2; // =1 if switch ON and =0 if OFF
  60. uint8_t switch_3; // =1 if switch ON and =0 if OFF
  61.  
  62. // output variables
  63. char text_1[11]; // string UTF8 end zero
  64.  
  65. // other variable
  66. uint8_t connect_flag; // =1 if wire connected, else =0
  67.  
  68. } RemoteXY;
  69. #pragma pack(pop)
  70.  
  71. /////////////////////////////////////////////
  72. // END RemoteXY include //
  73. /////////////////////////////////////////////
  74.  
  75.  
  76.  
  77. void setup()
  78. {
  79. RemoteXY_Init ();
  80. Serial.begin(9600);
  81. pinMode(lock, OUTPUT);
  82. digitalWrite(lock, LOW);
  83. SPI.begin();
  84. mfrc522.PCD_Init();
  85.  
  86. }
  87.  
  88. void loop()
  89. {
  90. RemoteXY_Handler ();
  91. fflag = RemoteXY.switch_1;
  92. eflag = RemoteXY.switch_2;
  93. jflag = RemoteXY.switch_3;
  94. iot_rfid();
  95. }
  96.  
  97. void iot_rfid() {
  98. if ( ! mfrc522.PICC_IsNewCardPresent()) {
  99. return;
  100. }
  101.  
  102. if ( ! mfrc522.PICC_ReadCardSerial() ) {
  103. return;
  104. }
  105. String content = "";
  106. byte letter;
  107. for (byte i = 0; i < mfrc522.uid.size; i++) {
  108. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  109. Serial.print(mfrc522.uid.uidByte[i], HEX);
  110. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  111. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  112. }
  113. Serial.println();
  114. content.toUpperCase();
  115. //Blue Tag ID : 79 53 FB A2
  116. //White Card ID : D0 86 B6 32
  117.  
  118. if (content.substring(1) == "D0 86 B6 32" && fflag == 1) {
  119. sendData1();
  120. }
  121. else if (content.substring(1) == "79 53 FB A2" && eflag == 1) {
  122. sendData2();
  123. }
  124. else if (content.substring(1) == "B9 48 A2 C1" && jflag == 1) {
  125. sendData3();
  126. }
  127. else {
  128. Serial.println("Unregistered User");
  129. strcpy(RemoteXY.text_1, "N/A");
  130. }
  131. }
  132.  
  133.  
  134. void sendData1() {
  135. Serial.println("User01");
  136. strcpy(RemoteXY.text_1, "User01");
  137. digitalWrite(lock, HIGH);
  138. delay(3000);
  139. digitalWrite(lock, LOW);
  140. }
  141.  
  142. void sendData2() {
  143. Serial.println("User02");
  144. strcpy(RemoteXY.text_1, "User02");
  145. digitalWrite(lock, HIGH);
  146. delay(3000);
  147. digitalWrite(lock, LOW);
  148. }
  149.  
  150. void sendData3() {
  151. Serial.println("User03");
  152. strcpy(RemoteXY.text_1, "User03");
  153. digitalWrite(lock, HIGH);
  154. delay(3000);
  155. digitalWrite(lock, LOW);
  156. }
Add Comment
Please, Sign In to add comment