fixed up settings
This commit is contained in:
parent
dae0679e00
commit
ab49a21f85
6 changed files with 80 additions and 80 deletions
|
@ -149,17 +149,23 @@
|
||||||
<td>Controls the GPIO pin</td>
|
<td>Controls the GPIO pin</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: left;">/state/relay1</td>
|
<td style="text-align: left;">/state/relay</td>
|
||||||
<td>GET</td>
|
<td>GET</td>
|
||||||
<td>N/A</td>
|
<td>N/A</td>
|
||||||
<td>Returns the state of relay1</td>
|
<td>Returns the state of relay1</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: left;">/settings/doordisabled</td>
|
<td style="text-align: left;">/settings/relaydisabled</td>
|
||||||
<td>GET, POST</td>
|
<td>GET, POST</td>
|
||||||
<td>value</td>
|
<td>value</td>
|
||||||
<td>Gets or sets the door disabled value</td>
|
<td>Gets or sets the relay disabled value</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: left;">/settings/relaymode</td>
|
||||||
|
<td>GET, POST</td>
|
||||||
|
<td>value</td>
|
||||||
|
<td>Gets or sets the relay mode currently "LATCH" or "TOGGLE"</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: left;">/settings/tinance2creds</td>
|
<td style="text-align: left;">/settings/tinance2creds</td>
|
||||||
<td>GET, POST</td>
|
<td>GET, POST</td>
|
||||||
|
@ -220,6 +226,32 @@
|
||||||
<td>value</td>
|
<td>value</td>
|
||||||
<td>Gets or sets the webhook unlock hook</td>
|
<td>Gets or sets the webhook unlock hook</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: left;">/users/create</td>
|
||||||
|
<td>GET, POST</td>
|
||||||
|
<td>cardid, desc</td>
|
||||||
|
<td>Creates a local / backup user</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: left;">/users/update</td>
|
||||||
|
<td>GET, POST</td>
|
||||||
|
<td>cardid, newCardId, desc</td>
|
||||||
|
<td>updates a local / backup user if cardid is the same set newCardId to same value.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: left;">/users/remove</td>
|
||||||
|
<td>GET, POST</td>
|
||||||
|
<td>cardid</td>
|
||||||
|
<td>removes a local / backup user</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: left;">/users/users</td>
|
||||||
|
<td>GET, POST</td>
|
||||||
|
<td>N/A</td>
|
||||||
|
<td>lists all local / backup user</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -10,9 +10,7 @@
|
||||||
|
|
||||||
#ifdef WIFI
|
#ifdef WIFI
|
||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
#ifdef WEBHOOKS
|
#include "webhooks.h"
|
||||||
#include "webhooks.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LOCAL_ACL
|
#ifdef LOCAL_ACL
|
||||||
|
|
|
@ -46,7 +46,7 @@ class MainWebServerClass{
|
||||||
return request->requestAuthentication();
|
return request->requestAuthentication();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request->send(200, "application/json", "{\"version\":\"3.5.6\"}");
|
request->send(200, "application/json", "{\"version\":\"3.5.7\"}");
|
||||||
});
|
});
|
||||||
|
|
||||||
_server->onNotFound([&](AsyncWebServerRequest *request){
|
_server->onNotFound([&](AsyncWebServerRequest *request){
|
||||||
|
@ -58,48 +58,8 @@ class MainWebServerClass{
|
||||||
request->send(200, "application/json", "{\"msg\":\"The content you are looking for was not found\"}");
|
request->send(200, "application/json", "{\"msg\":\"The content you are looking for was not found\"}");
|
||||||
});
|
});
|
||||||
|
|
||||||
_server->on("/gpio", HTTP_POST, [&] (AsyncWebServerRequest *request) {
|
|
||||||
|
|
||||||
if(_authRequired){
|
|
||||||
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
|
||||||
return request->requestAuthentication();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET input1 value on <ESP_IP>/gpio?output=<paramOutput>&state=<paramState>
|
|
||||||
if (request->hasParam("output", true) && request->hasParam("state", true)) {
|
|
||||||
String paramOutput = String(request->arg("output"));
|
|
||||||
String paramState = String(request->arg("state"));
|
|
||||||
|
|
||||||
#ifdef RELAY1
|
|
||||||
if (paramOutput == "relay1") {
|
|
||||||
if (paramState == String(0)){
|
|
||||||
unlockDoor(false);
|
|
||||||
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"Door Unlocked.\"}");
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
else if (paramState == String(1)) {
|
|
||||||
lockDoor(false);
|
|
||||||
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"Door Locked.\"}");
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"Incorect state provide 0 to unlock and 1 to lock.\"}");
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Error with request, incorrect GPIO pin number.\"}");
|
|
||||||
request->send(response);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
#ifdef RELAY1
|
#ifdef RELAY1
|
||||||
_server->on("/state/relay1", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
_server->on("/state/relay", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
||||||
if(_authRequired){
|
if(_authRequired){
|
||||||
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
return request->requestAuthentication();
|
return request->requestAuthentication();
|
||||||
|
@ -110,7 +70,7 @@ class MainWebServerClass{
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_server->on("/settings/doordisabled", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
_server->on("/settings/relaydisabled", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
||||||
if(_authRequired){
|
if(_authRequired){
|
||||||
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
return request->requestAuthentication();
|
return request->requestAuthentication();
|
||||||
|
@ -120,7 +80,7 @@ class MainWebServerClass{
|
||||||
request->send(response);
|
request->send(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
_server->on("/settings/doordisabled", HTTP_POST, [&] (AsyncWebServerRequest *request) {
|
_server->on("/settings/relaydisabled", HTTP_POST, [&] (AsyncWebServerRequest *request) {
|
||||||
|
|
||||||
if(_authRequired){
|
if(_authRequired){
|
||||||
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
|
@ -152,6 +112,42 @@ class MainWebServerClass{
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_server->on("/settings/relaymode", 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", "{\"value\":\""+settings.getDoorMode()+"\"}");
|
||||||
|
request->send(response);
|
||||||
|
});
|
||||||
|
|
||||||
|
_server->on("/settings/relaymode", HTTP_POST, [&] (AsyncWebServerRequest *request) {
|
||||||
|
|
||||||
|
if(_authRequired){
|
||||||
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
|
return request->requestAuthentication();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (request->hasParam("value", true)) {
|
||||||
|
String value = String(request->arg("value"));
|
||||||
|
|
||||||
|
if (value == "LATCH" || value == "TOGGLE") {
|
||||||
|
settings.setDoorMode(value);
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"msg\":\"value set to "+value+"\"}");
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"value should be LATCH or TOGGLE\"}");
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Missing 'value' param.\"}");
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_server->on("/settings/tinance2creds", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
_server->on("/settings/tinance2creds", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
||||||
if(_authRequired){
|
if(_authRequired){
|
||||||
|
|
|
@ -20,12 +20,4 @@
|
||||||
extern const char* http_password;
|
extern const char* http_password;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WEBHOOKS
|
|
||||||
#ifdef WEBHOOK_UNLOCK
|
|
||||||
extern const char* webhook_unlock_url;
|
|
||||||
#endif
|
|
||||||
#ifdef WEBHOOK_LOCK
|
|
||||||
extern const char* webhook_lock_url;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
|
@ -31,8 +31,6 @@ public:
|
||||||
void loadFromEEPROM();
|
void loadFromEEPROM();
|
||||||
void saveToEEPROM();
|
void saveToEEPROM();
|
||||||
void saveSetting(const String& namespaceStr, const String& key, const String& value, const String& typeStr);
|
void saveSetting(const String& namespaceStr, const String& key, const String& value, const String& typeStr);
|
||||||
void saveStringToEEPROM(String string, String value);
|
|
||||||
void saveBoolToEEPROM(String string, String value);
|
|
||||||
|
|
||||||
void setDisableDoor(bool value);
|
void setDisableDoor(bool value);
|
||||||
bool getDoorDisabled();
|
bool getDoorDisabled();
|
||||||
|
|
|
@ -33,7 +33,7 @@ void Settings::saveSetting(const String& namespaceStr, const String& key, const
|
||||||
|
|
||||||
if (typeStr == "bool") {
|
if (typeStr == "bool") {
|
||||||
bool currentValue = settings_preferences.getBool(key.c_str());
|
bool currentValue = settings_preferences.getBool(key.c_str());
|
||||||
bool newValue = (value == "true");
|
bool newValue = value;
|
||||||
if (currentValue != newValue) {
|
if (currentValue != newValue) {
|
||||||
settings_preferences.begin(namespaceStr.c_str(), false);
|
settings_preferences.begin(namespaceStr.c_str(), false);
|
||||||
settings_preferences.putBool(key.c_str(), newValue);
|
settings_preferences.putBool(key.c_str(), newValue);
|
||||||
|
@ -68,22 +68,6 @@ void Settings::saveSetting(const String& namespaceStr, const String& key, const
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Settings::saveToEEPROM() {
|
|
||||||
settings_preferences.begin("settings", false);
|
|
||||||
settings_preferences.putBool("disableDoor", disableDoor);
|
|
||||||
settings_preferences.putString("doorMode", doorMode);
|
|
||||||
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) {
|
||||||
if (disableDoor != value) {
|
if (disableDoor != value) {
|
||||||
disableDoor = value;
|
disableDoor = value;
|
||||||
|
@ -95,10 +79,10 @@ void Settings::setDisableDoor(bool value) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SERIAL_DEBUG
|
#ifdef SERIAL_DEBUG
|
||||||
Serial.print("Settings::setDisableDoor: ");
|
Serial.print("Settings::setDisableDoor: " + value);
|
||||||
Serial.println(disableDoor);
|
Serial.println(disableDoor);
|
||||||
#endif
|
#endif
|
||||||
saveToEEPROM();
|
saveSetting("settings", "disableDoor", String(disableDoor), "bool");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +105,7 @@ void Settings::setDoorMode(const String mode) {
|
||||||
Serial.print("Settings::setDoorMode: ");
|
Serial.print("Settings::setDoorMode: ");
|
||||||
Serial.println(doorMode);
|
Serial.println(doorMode);
|
||||||
#endif
|
#endif
|
||||||
saveToEEPROM();
|
saveSetting("settings", "doorMode", doorMode, "string");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue