Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. /*
  2.  *      rfid        node
  3.  *      3.3v        3.3v
  4.  *      rst         d2
  5.  *      gnd         gnd
  6.  *      miso        d6
  7.  *      mosi        d7
  8.  *      sck         d5
  9.  *      sda         d4
  10.  */
  11.  
  12. #include <SPI.h>
  13. #include <MFRC522.h>
  14. #include <ESP8266WiFi.h>
  15. #include <ESP8266HTTPClient.h>
  16.  
  17. #define SS_PIN D4
  18. #define RST_PIN D2
  19.  
  20. MFRC522 mfrc522(SS_PIN, RST_PIN);
  21.  
  22. const char* ssid = "WISP";
  23. const char* password = "17215541";
  24.  
  25. #define ledbuzz 15
  26.  
  27. int count = 0;
  28.  
  29. void setup(){
  30.   Serial.begin(9600);
  31.   SPI.begin();    
  32.   mfrc522.PCD_Init();
  33.   Serial.println("RFID reading UID");
  34.  
  35.   pinMode(ledbuzz,OUTPUT);
  36.   digitalWrite(ledbuzz,HIGH);
  37.  
  38.   WiFi.begin(ssid, password);
  39.   while (WiFi.status() != WL_CONNECTED) {
  40.     delay(1000);
  41.   }
  42.  
  43. }
  44.  
  45. void loop(){
  46.   String tmpValue = "";
  47.  
  48.   if(mfrc522.PICC_IsNewCardPresent()){
  49.     if(mfrc522.PICC_ReadCardSerial()){
  50.       Serial.print("Tag UID:");
  51.       for (byte i = 0; i < mfrc522.uid.size; i++) {
  52.         Serial.print(mfrc522.uid.uidByte[i], HEX);
  53.         tmpValue += String(mfrc522.uid.uidByte[i], HEX);
  54.       }
  55.      
  56.       digitalWrite(ledbuzz,LOW);
  57.       delay(500);
  58.       digitalWrite(ledbuzz,HIGH);
  59.  
  60.       String msg = "";
  61.       msg += tmpValue;
  62.  
  63.       if(WiFi.status() == WL_CONNECTED){
  64.  
  65.         HTTPClient http;
  66.  
  67.         String url = "http://nv.labm2m.com/data.php?";
  68.         url += "rfid=";
  69.         url += msg;
  70.         http.begin(url);  
  71.         int httpCode = http.GET();
  72.          
  73.         if(httpCode > 0){
  74.           String payload = http.getString();  
  75.           Serial.print(" > ");
  76.           Serial.println(payload);        
  77.         }
  78.      
  79.         http.end();  
  80.        
  81.       }
  82.      
  83.       Serial.println();
  84.       mfrc522.PICC_HaltA();
  85.     }
  86.   }
  87.  
  88.   if(WiFi.status() != WL_CONNECTED){
  89.     recon();
  90.   }
  91.  
  92.   delay(50);
  93.  
  94. }
  95.  
  96. void recon(){
  97.   while(WiFi.status() != WL_CONNECTED){
  98.  
  99.     //wifi reload connection
  100.     WiFi.begin(ssid, password);
  101.     delay(1000);
  102.  
  103.   }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement