ESP32 RFID员工考勤系统闲置数小时后无法读取标签问题求助
ESP32 RFID员工考勤系统闲置数小时后无法读取标签问题求助
我最近在给员工做一套打卡系统,用ESP32搭配RFID模块实现上下班打卡功能——设备连上WiFi后,刷员工的RFID标签就能把当前时间上传到我的线上数据库。
测试阶段我时不时刷一下标签,系统运行得特别顺畅,完全没出过问题。但只要把设备闲置几个小时,再去刷标签就一点反应都没有了,感觉设备像是冻住了一样。
我的代码逻辑很简单:先连接WiFi,检测到新的RFID标签后发起HTTP请求上传数据,同时触发蜂鸣器提示打卡成功。下面是我移除敏感信息后的代码:
#include <WiFi.h> #include <WiFiClientSecure.h> #include <HTTPClient.h> #include <SPI.h> #include <MFRC522.h> // WiFi credentials and server details const char* ssid = "-BV"; const char* password = ""; const char* serverName = ""; String apiKeyValue = "tPmAT5Ab3j7F9"; String sensorName = "RFID"; String sensorLocation = "Office"; // RFID reader pins #define SS_PIN 5 // ESP32 pin GPIO5 for RFID-RC522 #define RST_PIN 27 // ESP32 pin GPIO27 for RFID-RC522 MFRC522 rfid(SS_PIN, RST_PIN); // Create MFRC522 instance const int biepPin = 25; int count = 0; WiFiClientSecure client; // Create a global WiFiClientSecure instance void setup() { Serial.begin(9600); WiFi.begin(ssid, password); while(WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected to WiFi network with IP Address: "); Serial.println(WiFi.localIP()); SPI.begin(); // Init SPI bus rfid.PCD_Init(); // Init MFRC522 Serial.println("RFID reader initialized"); pinMode(biepPin, OUTPUT); } void loop() { if(WiFi.status() == WL_CONNECTED){ if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) { Serial.println("RFID tag detected"); String uidString = ""; for (byte i = 0; i < rfid.uid.size; i++) { uidString += String(rfid.uid.uidByte[i] < 0x10 ? "0" : "") + String(rfid.uid.uidByte[i], HEX); } uidString.toUpperCase(); client.setInsecure(); // Set the client as insecure HTTPClient https; https.begin(client, serverName); https.addHeader("Content-Type", "application/x-www-form-urlencoded"); String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName + "&location=" + sensorLocation + "&value1=" + uidString; Serial.println("Sending HTTP request"); int httpResponseCode = https.POST(httpRequestData); tone(biepPin, 1000); delay(100); noTone(biepPin); delay(50); // Second tone (lower frequency) tone(biepPin, 800); delay(100); noTone(biepPin); if (httpResponseCode > 0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } https.end(); rfid.PICC_HaltA(); // Halt PICC rfid.PCD_StopCrypto1(); // Stop encryption on PCD } } else { Serial.println("WiFi Disconnected"); } count = count++; Serial.println(count); }
有没有大佬能帮我分析下,为什么闲置几小时后设备就无法读取标签了?可能是哪里的问题呢?
备注:内容来源于stack exchange,提问作者kucb
相关产品推荐
相关产品推荐

