improved rfid scan api->timeout
This commit is contained in:
parent
e81509a295
commit
d27a42c7e8
@ -21,7 +21,7 @@ bool WebConsole::init(userdb::UserDb *userdb)
|
|||||||
_server->on("/api/auth", HTTPMethod::HTTP_POST, std::bind(&WebConsole::_auth, this));
|
_server->on("/api/auth", HTTPMethod::HTTP_POST, std::bind(&WebConsole::_auth, this));
|
||||||
_server->on("/api/userdb", HTTPMethod::HTTP_DELETE, std::bind(&WebConsole::_dropUserDb, this));
|
_server->on("/api/userdb", HTTPMethod::HTTP_DELETE, std::bind(&WebConsole::_dropUserDb, this));
|
||||||
_server->on("/api/userdb", HTTPMethod::HTTP_GET, std::bind(&WebConsole::_getUserDb, this));
|
_server->on("/api/userdb", HTTPMethod::HTTP_GET, std::bind(&WebConsole::_getUserDb, this));
|
||||||
_server->on("/api/rfid", std::bind(&WebConsole::_catchRFID, this));
|
_server->on("/api/rfid", HTTPMethod::HTTP_GET, std::bind(&WebConsole::_catchRFID, this));
|
||||||
_server->on("/api/debug/printfile", std::bind(&WebConsole::_print_db_raw, this));
|
_server->on("/api/debug/printfile", std::bind(&WebConsole::_print_db_raw, this));
|
||||||
_server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_DELETE, std::bind(&WebConsole::_deleteUser, this));
|
_server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_DELETE, std::bind(&WebConsole::_deleteUser, this));
|
||||||
_server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_GET, std::bind(&WebConsole::_getUser, this));
|
_server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_GET, std::bind(&WebConsole::_getUser, this));
|
||||||
@ -39,16 +39,26 @@ void WebConsole::attachRfid(Rfid *rfid)
|
|||||||
}
|
}
|
||||||
void WebConsole::serve()
|
void WebConsole::serve()
|
||||||
{
|
{
|
||||||
if (catch_rfid && rfid != nullptr && rfid->available())
|
if (catch_rfid)
|
||||||
|
{
|
||||||
|
if (millis() - catch_rfid_millis > 2000){
|
||||||
|
catch_rfid = 0;
|
||||||
|
}
|
||||||
|
else if (catch_rfid > 1 && rfid != nullptr && rfid->available())
|
||||||
{
|
{
|
||||||
rfid_buffer = rfid->getID();
|
rfid_buffer = rfid->getID();
|
||||||
catch_rfid_updated = true;
|
catch_rfid = 1;
|
||||||
catch_rfid = false;
|
}
|
||||||
}
|
}
|
||||||
_server->handleClient();
|
_server->handleClient();
|
||||||
}
|
}
|
||||||
bool WebConsole::isInterceptingRfid()
|
uint8_t WebConsole::isInterceptingRfid()
|
||||||
{
|
{
|
||||||
|
if(catch_rfid==3){
|
||||||
|
catch_rfid=2;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
return catch_rfid;
|
return catch_rfid;
|
||||||
}
|
}
|
||||||
bool WebConsole::_isAuth()
|
bool WebConsole::_isAuth()
|
||||||
@ -78,7 +88,7 @@ void WebConsole::_auth()
|
|||||||
{
|
{
|
||||||
char *token = auth.login(_server->arg("username"), _server->arg("password"));
|
char *token = auth.login(_server->arg("username"), _server->arg("password"));
|
||||||
if (token == nullptr)
|
if (token == nullptr)
|
||||||
_server->send(401, "text/plain", "failed!");
|
_server->send(401, "text/plain", "login_failed");
|
||||||
else
|
else
|
||||||
_server->send(200, "text/plain", token);
|
_server->send(200, "text/plain", token);
|
||||||
}
|
}
|
||||||
@ -94,7 +104,6 @@ void WebConsole::_auth()
|
|||||||
// return;
|
// return;
|
||||||
bool res = auth.setAuth(_server->arg("username"), _server->arg("password"));
|
bool res = auth.setAuth(_server->arg("username"), _server->arg("password"));
|
||||||
_server->send(200, "text/plain", res ? "success" : "failed");
|
_server->send(200, "text/plain", res ? "success" : "failed");
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_server->send(404, "text/plain", "unknown action");
|
_server->send(404, "text/plain", "unknown action");
|
||||||
@ -228,7 +237,7 @@ void WebConsole::_updateUser()
|
|||||||
updated.user_pin = doc["user_pin"].as<String>();
|
updated.user_pin = doc["user_pin"].as<String>();
|
||||||
if (doc.containsKey("enabled"))
|
if (doc.containsKey("enabled"))
|
||||||
updated.enabled = doc["enabled"].as<bool>();
|
updated.enabled = doc["enabled"].as<bool>();
|
||||||
bool res = userdb->update_user(&updated);
|
userdb->update_user(&updated);
|
||||||
_server->send(200, "text/json", updated.toJSONString().c_str());
|
_server->send(200, "text/json", updated.toJSONString().c_str());
|
||||||
}
|
}
|
||||||
void WebConsole::_createUser()
|
void WebConsole::_createUser()
|
||||||
@ -285,23 +294,20 @@ void WebConsole::_catchRFID()
|
|||||||
return;
|
return;
|
||||||
if (rfid == nullptr)
|
if (rfid == nullptr)
|
||||||
{
|
{
|
||||||
_server->send(500, "text/json", "{\"error\":\"RFID not attached.\"}");
|
_server->send(500, "text/json", "{\"error\":\"RFID not attached.\",\"state\":\"" + String(catch_rfid) + "\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (catch_rfid_updated)
|
if (catch_rfid == 1)
|
||||||
{
|
{
|
||||||
String response = "{\"rfid_uid\":\"" + rfid_buffer + "\"}";
|
String response = "{\"rfid_uid\":\"" + rfid_buffer + "\",\"state\":\"" + String(catch_rfid) + "\"}";
|
||||||
_server->send(500, "text/json", response);
|
_server->send(200, "text/json", response);
|
||||||
catch_rfid_updated = false;
|
catch_rfid = 0;
|
||||||
}
|
|
||||||
else if (catch_rfid)
|
|
||||||
{
|
|
||||||
_server->send(500, "text/json", "{\"ok\":\"already activated\"}");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
catch_rfid = true;
|
catch_rfid = 3; // 3 - Start listening
|
||||||
_server->send(500, "text/json", "{\"ok\":\"now activated\"}");
|
catch_rfid_millis = millis();
|
||||||
|
_server->send(200, "text/json", "{\"ok\":\"listening\",\"state\":\"" + String(catch_rfid) + "\"}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void WebConsole::_updateAdmin()
|
void WebConsole::_updateAdmin()
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "UserDb.h"
|
#include "UserDb.h"
|
||||||
#include "Rfid.h"
|
#include "Rfid.h"
|
||||||
#include "AdminAuth.h"
|
#include "AdminAuth.h"
|
||||||
|
#include "Interface.h"
|
||||||
namespace webconsole
|
namespace webconsole
|
||||||
{
|
{
|
||||||
static const char path_prefix[] PROGMEM = "/s";
|
static const char path_prefix[] PROGMEM = "/s";
|
||||||
@ -21,7 +22,7 @@ namespace webconsole
|
|||||||
bool init(userdb::UserDb *userdb);
|
bool init(userdb::UserDb *userdb);
|
||||||
void attachRfid(Rfid *rfid);
|
void attachRfid(Rfid *rfid);
|
||||||
void serve();
|
void serve();
|
||||||
bool isInterceptingRfid();
|
uint8_t isInterceptingRfid();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _sendCORS();
|
void _sendCORS();
|
||||||
@ -48,10 +49,12 @@ namespace webconsole
|
|||||||
}
|
}
|
||||||
ESP8266WebServer *_server;
|
ESP8266WebServer *_server;
|
||||||
userdb::UserDb *userdb = nullptr;
|
userdb::UserDb *userdb = nullptr;
|
||||||
bool catch_rfid = false;
|
unsigned long catch_rfid_millis = 0;
|
||||||
|
uint8_t catch_rfid = 0;
|
||||||
bool catch_rfid_updated = false;
|
bool catch_rfid_updated = false;
|
||||||
String rfid_buffer;
|
String rfid_buffer;
|
||||||
Rfid *rfid = nullptr;
|
Rfid *rfid = nullptr;
|
||||||
|
Interface *iface = nullptr;
|
||||||
AdminAuth auth;
|
AdminAuth auth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -62,9 +62,10 @@ void loop()
|
|||||||
web.serve();
|
web.serve();
|
||||||
keyboard.scanAsync();
|
keyboard.scanAsync();
|
||||||
userdb::User login_user;
|
userdb::User login_user;
|
||||||
if(web.isInterceptingRfid()&&iface.getState()==0){
|
if (web.isInterceptingRfid() ==3)
|
||||||
iface.showMessage("WebUI connected", "Awaiting RFID", 3000);
|
iface.showMessage("WebUI connected", "Awaiting RFID", 2000);
|
||||||
}
|
else if (web.isInterceptingRfid() == 1)
|
||||||
|
iface.showMessage("WebUI connected", "RFID Found", 1000);
|
||||||
else if (iface.pinAvailable() && iface.getState() != Interface::GREET)
|
else if (iface.pinAvailable() && iface.getState() != Interface::GREET)
|
||||||
{
|
{
|
||||||
unsigned long delta = millis();
|
unsigned long delta = millis();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user