   WiFi.begin(ssid, password);
 
   int timeLimit = 0;
-  while (WiFi.status() != WL_CONNECTED && timeLimit < 6000) {
+  while (WiFi.status() != WL_CONNECTED && timeLimit < 6000) 
+  {
     delay(500);
     timeLimit += 500;
     if (DEBUGMODE) Serial.print(".");
   }
 
-  if (WiFi.status() == WL_CONNECTED){
+  if (WiFi.status() == WL_CONNECTED)
+  {
    if (DEBUGMODE) Serial.println("WiFi connected");
    if (DEBUGMODE) Serial.println("IP address: ");
    if (DEBUGMODE) Serial.println(WiFi.localIP());
   }
 
-  if (WiFi.status() != WL_CONNECTED){
+  if (WiFi.status() != WL_CONNECTED)
+  {
     Serial.println("Wifi connection failed.");
     warnForNoWIFI();
   }

/*
Name:    NFC_ReadCard.ino
Created: 9/27/2016 10:59:24
 
********Version 1.5*********
-更改openDoor()命令位置
增加线上数据库二次验证, 刷卡模式由先开门再上传刷卡数据改为先上传验证数据再开门
对网络要求提高,安全性增加,不过同时可能造成部分时间段网络不稳定无法刷卡开门

********Version 1.6*********
-调整openDoor()命令位置
考虑到用户体验的流畅度, 将在成功读卡后首先判断网络状态,如无法连接网络,先进行开门操作。同时可以防止网络故障后无法开门的情况


********Version 1.7*********
-增加刷卡提示音


********Version 1.8*********
-增加网络故障提示音


********Version 1.9*********
-增加一张超级权限卡用户网络故障后开门
-增加服务器故障提示音
*/

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <MFRC522.h>


#define RST_PIN 0 // RST-PIN for RC522 - RFID - SPI - Module GPIO-0 
#define SS_PIN  15  // SDA-PIN for RC522 - RFID - SPI - Module GPIO-15
#define DEBUGMODE 0

#define DoorRelay D2
#define Buzzer D3

const char* ssid = "XinCheJian";  //the wifi network ssid
const char* password = "imakestuff";  //password to ssid
const char* host = "192.168.1.100";   //server ip address
const int httpPort = 80;  //server access address
int cardState = 0;


MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

void setup() {

  Serial.begin(9600); // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();        // Init SPI bus

  //if (DEBUGMODE) Serial.print(nameBlock);
  //if (DEBUGMODE) Serial.println(F(" ..."));
  status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(nameBlock, staff_name, &size);
  if (status != MFRC522::STATUS_OK) 
  {
    if (DEBUGMODE) Serial.print(F("MIFARE_Read() failed: "));
    if (DEBUGMODE) Serial.println(mfrc522.GetStatusCodeName(status));
    //cannot read name, don't open the door 
