Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Connections:
- --------------------------------------------
- RDIF ESP8266
- -------------------
- SDA D4
- SCK D5
- MOSI D7
- MISO D6
- IRQ N/C
- GND G
- RST D2
- 3.3V 3V
- RELAY ESP8266
- -------------------
- DC+ +12V/5V(Breadboard Power Supply)
- DC- GND/GND(Breadboard Power Supply)
- IN D1
- --------------------------------------------
- */
- #define REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD
- #include <ESP8266WiFi.h>
- #include <SPI.h>
- #include <MFRC522.h>
- #include <RemoteXY.h>
- // RemoteXY connection settings
- #define REMOTEXY_WIFI_SSID "network"
- #define REMOTEXY_WIFI_PASSWORD "123456789"
- #define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
- #define REMOTEXY_CLOUD_PORT 6376
- #define REMOTEXY_CLOUD_TOKEN "bc73e0a89829394e756869d36a44b277"
- #define SS_PIN 4
- #define RST_PIN 2
- int lock = D1;
- MFRC522 mfrc522(RST_PIN, SS_PIN);
- int fflag = 0;
- int eflag = 0;
- int jflag = 0;
- // RemoteXY configurate
- #pragma pack(push, 1)
- uint8_t RemoteXY_CONF[] = // 70 bytes
- { 255, 3, 0, 11, 0, 63, 0, 16, 31, 1, 67, 4, 18, 17, 20, 5, 2, 26, 11, 2,
- 0, 18, 30, 22, 11, 2, 26, 31, 31, 79, 78, 0, 79, 70, 70, 0, 2, 0, 18, 44,
- 22, 11, 2, 26, 31, 31, 79, 78, 0, 79, 70, 70, 0, 2, 0, 18, 58, 22, 11, 2,
- 26, 31, 31, 79, 78, 0, 79, 70, 70, 0
- };
- // this structure defines all the variables and events of your control interface
- struct {
- // input variables
- uint8_t switch_1; // =1 if switch ON and =0 if OFF
- uint8_t switch_2; // =1 if switch ON and =0 if OFF
- uint8_t switch_3; // =1 if switch ON and =0 if OFF
- // output variables
- char text_1[11]; // string UTF8 end zero
- // other variable
- uint8_t connect_flag; // =1 if wire connected, else =0
- } RemoteXY;
- #pragma pack(pop)
- /////////////////////////////////////////////
- // END RemoteXY include //
- /////////////////////////////////////////////
- void setup()
- {
- RemoteXY_Init ();
- Serial.begin(9600);
- pinMode(lock, OUTPUT);
- digitalWrite(lock, LOW);
- SPI.begin();
- mfrc522.PCD_Init();
- }
- void loop()
- {
- RemoteXY_Handler ();
- fflag = RemoteXY.switch_1;
- eflag = RemoteXY.switch_2;
- jflag = RemoteXY.switch_3;
- iot_rfid();
- }
- void iot_rfid() {
- if ( ! mfrc522.PICC_IsNewCardPresent()) {
- return;
- }
- if ( ! mfrc522.PICC_ReadCardSerial() ) {
- return;
- }
- String content = "";
- byte letter;
- for (byte i = 0; i < mfrc522.uid.size; i++) {
- Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
- Serial.print(mfrc522.uid.uidByte[i], HEX);
- content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- }
- Serial.println();
- content.toUpperCase();
- //Blue Tag ID : 79 53 FB A2
- //White Card ID : D0 86 B6 32
- if (content.substring(1) == "D0 86 B6 32" && fflag == 1) {
- sendData1();
- }
- else if (content.substring(1) == "79 53 FB A2" && eflag == 1) {
- sendData2();
- }
- else if (content.substring(1) == "B9 48 A2 C1" && jflag == 1) {
- sendData3();
- }
- else {
- Serial.println("Unregistered User");
- strcpy(RemoteXY.text_1, "N/A");
- }
- }
- void sendData1() {
- Serial.println("User01");
- strcpy(RemoteXY.text_1, "User01");
- digitalWrite(lock, HIGH);
- delay(3000);
- digitalWrite(lock, LOW);
- }
- void sendData2() {
- Serial.println("User02");
- strcpy(RemoteXY.text_1, "User02");
- digitalWrite(lock, HIGH);
- delay(3000);
- digitalWrite(lock, LOW);
- }
- void sendData3() {
- Serial.println("User03");
- strcpy(RemoteXY.text_1, "User03");
- digitalWrite(lock, HIGH);
- delay(3000);
- digitalWrite(lock, LOW);
- }
Add Comment
Please, Sign In to add comment