Advertisement
rarespreda

Untitled

Nov 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. //Wifi stuff
  2. #include <ESP8266WiFi.h>
  3. #include <ESP8266HTTPClient.h>
  4. const char *ssid = "Android hspot";
  5. const char *pass = "yodamaster";
  6.  
  7. int SendReqFlag = 0;
  8.  
  9. #include <SPI.h>
  10. #include <MFRC522.h>
  11. #define RST_PIN         5          // Configurable, see typical pin layout above
  12. #define SS_PIN          4         // Configurable, see typical pin layout above
  13.  
  14. MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
  15. unsigned long card_uid;
  16. void setup() {
  17.     Serial.begin(115200);       // Initialize serial communications with the PC
  18.     while (!Serial);        // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  19.     SPI.begin();            // Init SPI bus
  20.     mfrc522.PCD_Init();     // Init MFRC522
  21.     mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
  22.     Serial.println(F("RFID inited!"));
  23.   WiFi.begin(ssid, pass);
  24.   while (WiFi.status() != WL_CONNECTED) {
  25.     delay(1000);
  26.     Serial.println("Connecting..");
  27.   }
  28.   Serial.println("WIFI inited");
  29.   Serial.println(WiFi.localIP());
  30. }
  31.  
  32. void wifi_loop(unsigned long UID)
  33. {
  34.   /*if (WiFi.status() == WL_CONNECTED)
  35.   {
  36.     if (SendReqFlag)
  37.     {
  38.       SendReqFlag = 0;
  39.       HTTPClient http;  //Declare an object of class HTTPClient
  40.       http.begin("127.0.0.1/kappa/>??????<");  //Specify request destination
  41.       int httpCode = http.GET();                                                                  //Send the request
  42.  
  43.       if (httpCode > 0)
  44.       { //Check the returning code
  45.         String payload = http.getString();
  46.         Serial.println(payload);//send it further
  47.       }
  48.       http.end();
  49.     }
  50.   }*/
  51. }
  52.  
  53. void loop() {
  54.     // Look for new cards
  55.     if ( ! mfrc522.PICC_IsNewCardPresent()) {
  56.         return;
  57.     }
  58.  
  59.     // Select one of the cards
  60.     if ( ! mfrc522.PICC_ReadCardSerial()) {
  61.         return;
  62.     }
  63.   card_uid =  mfrc522.uid.uidByte[0] << 24;
  64.   card_uid += mfrc522.uid.uidByte[1] << 16;
  65.   card_uid += mfrc522.uid.uidByte[2] <<  8;
  66.   card_uid += mfrc522.uid.uidByte[3];
  67.   Serial.println(card_uid, HEX);
  68.   wifi_loop(card_uid);
  69.   //SendReqFlag = 1;
  70.   mfrc522.PICC_HaltA();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement