reader identity in settings
This commit is contained in:
parent
a29b52463a
commit
76da74aa61
5 changed files with 90 additions and 6 deletions
|
@ -177,9 +177,13 @@ class ACLWebServerClass{
|
||||||
acl.removeUser(cardId);
|
acl.removeUser(cardId);
|
||||||
acl.saveToEEPROM();
|
acl.saveToEEPROM();
|
||||||
request->send(201); // Created
|
request->send(201); // Created
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// deprecated, keeping for backward compatibility
|
// deprecated, keeping for backward compatibility
|
||||||
void loop() {
|
void loop() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ class MainWebServerClass{
|
||||||
return request->requestAuthentication();
|
return request->requestAuthentication();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request->send(200, "application/json", "{\"version\":\"3.1.9\"}");
|
request->send(200, "application/json", "{\"version\":\"3.2.3\"}");
|
||||||
});
|
});
|
||||||
|
|
||||||
_server->onNotFound([&](AsyncWebServerRequest *request){
|
_server->onNotFound([&](AsyncWebServerRequest *request){
|
||||||
|
@ -153,6 +153,45 @@ class MainWebServerClass{
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
_server->on("/settings/get/tinanceCreds", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
||||||
|
if(_authRequired){
|
||||||
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
|
return request->requestAuthentication();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"identifier\":\""+String(settings.getTinance2ReaderIdentifier())+"\", \"key\":\""+String(settings.getTinance2ReaderKey())+"\"}");
|
||||||
|
request->send(response);
|
||||||
|
});
|
||||||
|
|
||||||
|
_server->on("/settings/set/tinanceCreds", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
||||||
|
if(_authRequired){
|
||||||
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
|
return request->requestAuthentication();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(request->hasParam("identifier", true)) {} //This is important, otherwise the sketch will crash if there is no body
|
||||||
|
else {
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"No identifier\"}");
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
String identifier = String(request->arg("identifier"));
|
||||||
|
|
||||||
|
if(request->hasParam("key", true)) {} //This is important, otherwise the sketch will crash if there is no body
|
||||||
|
else {
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"No key\"}");
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
String key = String(request->arg("key"));
|
||||||
|
|
||||||
|
settings.setTinance2ReaderIdentifier(identifier);
|
||||||
|
settings.setTinance2ReaderKey(key);
|
||||||
|
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"Tinance credentials updated\"}");
|
||||||
|
request->send(response);
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// deprecated, keeping for backward compatibility
|
// deprecated, keeping for backward compatibility
|
||||||
|
|
|
@ -14,18 +14,28 @@ class Settings {
|
||||||
private:
|
private:
|
||||||
bool disableDoor;
|
bool disableDoor;
|
||||||
String doorMode;
|
String doorMode;
|
||||||
|
String tinance2ReaderIdentifier;
|
||||||
|
String tinance2ReaderKey;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Settings();
|
Settings();
|
||||||
|
|
||||||
void loadFromEEPROM();
|
void loadFromEEPROM();
|
||||||
void saveToEEPROM();
|
void saveToEEPROM();
|
||||||
|
void saveStringToEEPROM(String string, String value);
|
||||||
|
void saveBoolToEEPROM(String string, String value);
|
||||||
|
|
||||||
void setDisableDoor(bool value);
|
void setDisableDoor(bool value);
|
||||||
bool getDoorDisabled();
|
bool getDoorDisabled();
|
||||||
|
|
||||||
void setDoorMode(String value);
|
void setDoorMode(String value);
|
||||||
String getDoorMode();
|
String getDoorMode();
|
||||||
|
|
||||||
|
void setTinance2ReaderIdentifier(String value);
|
||||||
|
String getTinance2ReaderIdentifier();
|
||||||
|
|
||||||
|
void setTinance2ReaderKey(String value);
|
||||||
|
String getTinance2ReaderKey();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Settings settings;
|
extern Settings settings;
|
||||||
|
|
|
@ -6,17 +6,30 @@ Settings::Settings() : disableDoor(false), doorMode("LATCH") {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::loadFromEEPROM() {
|
void Settings::loadFromEEPROM() {
|
||||||
settings_preferences.begin("settings");
|
settings_preferences.begin("settings", false);
|
||||||
disableDoor = settings_preferences.getBool("disableDoor", false);
|
disableDoor = settings_preferences.getBool("disableDoor", false);
|
||||||
doorMode = settings_preferences.getString("doorMode", "LATCH");
|
doorMode = settings_preferences.getString("doorMode", "LATCH");
|
||||||
settings_preferences.end();
|
settings_preferences.end();
|
||||||
|
|
||||||
|
settings_preferences.begin("t2", false);
|
||||||
|
tinance2ReaderIdentifier = settings_preferences.getString("ri", "default");
|
||||||
|
tinance2ReaderKey = settings_preferences.getString("rk", "default");
|
||||||
|
settings_preferences.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::saveToEEPROM() {
|
void Settings::saveToEEPROM() {
|
||||||
settings_preferences.begin("settings");
|
settings_preferences.begin("settings", false);
|
||||||
settings_preferences.putBool("disableDoor", disableDoor);
|
settings_preferences.putBool("disableDoor", disableDoor);
|
||||||
settings_preferences.putString("doorMode", doorMode);
|
settings_preferences.putString("doorMode", doorMode);
|
||||||
settings_preferences.end();
|
settings_preferences.end();
|
||||||
|
|
||||||
|
settings_preferences.begin("t2", false);
|
||||||
|
settings_preferences.putString("ri", tinance2ReaderIdentifier);
|
||||||
|
settings_preferences.putString("rk", tinance2ReaderKey);
|
||||||
|
settings_preferences.end();
|
||||||
|
|
||||||
|
// Save the settings to EEPROM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::setDisableDoor(bool value) {
|
void Settings::setDisableDoor(bool value) {
|
||||||
|
@ -65,4 +78,22 @@ String Settings::getDoorMode() {
|
||||||
return doorMode;
|
return doorMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Settings::setTinance2ReaderIdentifier(String value) {
|
||||||
|
tinance2ReaderIdentifier = value;
|
||||||
|
saveToEEPROM();
|
||||||
|
|
||||||
|
}
|
||||||
|
String Settings::getTinance2ReaderIdentifier() {
|
||||||
|
return tinance2ReaderIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setTinance2ReaderKey(String value){
|
||||||
|
tinance2ReaderKey = value;
|
||||||
|
saveToEEPROM();
|
||||||
|
|
||||||
|
}
|
||||||
|
String Settings::getTinance2ReaderKey(){
|
||||||
|
return tinance2ReaderKey;
|
||||||
|
}
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
|
@ -17,8 +17,8 @@ HTTPClient tinance2_http;
|
||||||
|
|
||||||
// Set the headers
|
// Set the headers
|
||||||
tinance2_http.addHeader("Content-Type", "application/json");
|
tinance2_http.addHeader("Content-Type", "application/json");
|
||||||
tinance2_http.addHeader("X-Identifier", tinance2_reader_identifer);
|
tinance2_http.addHeader("X-Identifier", settings.getTinance2ReaderIdentifier());
|
||||||
tinance2_http.addHeader("X-Access-Key", tinance2_reader_key);
|
tinance2_http.addHeader("X-Access-Key", settings.getTinance2ReaderKey());
|
||||||
|
|
||||||
// Set the HTTP timeout to 5 seconds
|
// Set the HTTP timeout to 5 seconds
|
||||||
tinance2_http.setTimeout(5000);
|
tinance2_http.setTimeout(5000);
|
||||||
|
|
Loading…
Reference in a new issue