Compare commits
7 Commits
0b216e2e83
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 1bcbd3b8e3 | |||
| c6ad3f2259 | |||
| 156e095d4d | |||
| 8caffd50b2 | |||
| dc995d6e7e | |||
| 6d57da3402 | |||
| a21706f328 |
@@ -30,8 +30,20 @@
|
|||||||
+ Settings pos
|
+ Settings pos
|
||||||
+ WifiSSID - terminator 0x00 - Pos.: 0-31 (00 - 1F)
|
+ WifiSSID - terminator 0x00 - Pos.: 0-31 (00 - 1F)
|
||||||
+ WifiPassword - terminator 0x00 - Pos.: 32-63 (20 - 3F)
|
+ WifiPassword - terminator 0x00 - Pos.: 32-63 (20 - 3F)
|
||||||
+ Device IP - 40-43
|
+ Device IP - 40-43 uint32
|
||||||
+ Subnet 44 - 47
|
+ Subnet 44 - 47
|
||||||
+ Gateway 48 - 4B
|
+ Gateway 48 - 4B
|
||||||
+ Flags:
|
+ Mode 0 - station; 1 - client 4C uint8
|
||||||
+ Mode 0 - station; 1 - client 4C
|
+ AuthError Timeout (secs) 4D
|
||||||
|
+ OpenLock hold (secs) 4E
|
||||||
|
### 20.03.2022
|
||||||
|
+ settings API implemented and tested
|
||||||
|
+ TODO: factory reset
|
||||||
|
|
||||||
|
### 10.04.2022
|
||||||
|
+ Toni:
|
||||||
|
+ Reed Contact -> Door closed?
|
||||||
|
+ Tracking in->out
|
||||||
|
+ Stats
|
||||||
|
+ Sensors
|
||||||
|
|
||||||
@@ -5,9 +5,14 @@ Adress 0x21
|
|||||||
### 1.1 Wiring
|
### 1.1 Wiring
|
||||||
* Red: 3.3V
|
* Red: 3.3V
|
||||||
* Black GND
|
* Black GND
|
||||||
* Green SDA -> D3
|
* Green SDA -> D2
|
||||||
* Grey SCL -> D4
|
* Grey SCL -> D1
|
||||||
|
|
||||||
## 2.0 LCD
|
## 2.0 LCD
|
||||||
The LCD display is driven on the same i2c bus as the keypad.
|
The LCD display is driven on the same i2c bus as the keypad.
|
||||||
|
|
||||||
|
nterface Definition
|
||||||
|
BYTE BIT
|
||||||
|
7 (MSB) 6 5 4 3 2 1 0 (LSB)
|
||||||
|
I2C slave address L H L L A2 A1 A0 R/W
|
||||||
|
I/O data bus P7 P6 P5 P4 P3 P2 P1 P0
|
||||||
|
|||||||
BIN
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
@@ -1 +1 @@
|
|||||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>doorlock_pwa</title><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-capable" content="yes"><link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#673ab8"><style>*{box-sizing:border-box}html{font-family:Helvetica,sans-serif;font-size:16px}body,html{height:100%}body{background-color:#fff;margin:0;padding:0;width:100%}</style><link href="/bundle.45d14.css" rel="stylesheet" media="only x" onload="this.media='all'"><noscript><link rel="stylesheet" href="/bundle.45d14.css"></noscript></head><body><script defer="defer" src="/bundle.357e7.js"></script><script nomodule="" src="/polyfills.058fb.js"></script></body></html>
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>doorlock_pwa</title><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-capable" content="yes"><link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#673ab8"><style>*{box-sizing:border-box}html{font-family:Helvetica,sans-serif;font-size:16px}body,html{height:100%}body{background-color:#fff;margin:0;padding:0;width:100%}</style><link href="/bundle.3bf6c.css" rel="stylesheet" media="only x" onload="this.media='all'"><noscript><link rel="stylesheet" href="/bundle.3bf6c.css"></noscript></head><body><script defer="defer" src="/bundle.4bdf3.js"></script><script nomodule="" src="/polyfills.914a6.js"></script></body></html>
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
+45
-45
@@ -1,6 +1,6 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#define CONFIG_SIZE 0x4C
|
|
||||||
Config::Config()
|
Config::Config(const char* filepath): _filepath(filepath)
|
||||||
{
|
{
|
||||||
if (!LittleFS.begin())
|
if (!LittleFS.begin())
|
||||||
{
|
{
|
||||||
@@ -12,23 +12,20 @@ Config::~Config()
|
|||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
bool Config::setFilePath(const char* filepath){
|
||||||
|
this->_filepath = filepath;
|
||||||
|
return loadBin();
|
||||||
|
}
|
||||||
bool Config::loadBin()
|
bool Config::loadBin()
|
||||||
{
|
{
|
||||||
File config_file = LittleFS.open("/settings", "r");
|
File config_file = LittleFS.open(_filepath, "r");
|
||||||
if(buffer==nullptr)
|
//if (buffer == nullptr) // Allocate only once
|
||||||
buffer = (uint8_t*) malloc(CONFIG_SIZE);
|
// buffer = (uint8_t *)malloc(CONFIG_SIZE);
|
||||||
if (config_file.available())
|
if (config_file.available())
|
||||||
{
|
{
|
||||||
config_file.read(buffer, CONFIG_SIZE);
|
config_file.read(buffer, CONFIG_SIZE);
|
||||||
SSID = (char*) buffer;
|
buffer[OFFSET_SSID + 0x1F] = 0x00; // ensure ssid and password are terminated with a null character
|
||||||
buffer[0x1F] = 0x00;
|
buffer[OFFSET_PASS + 0x1F] = 0x00;
|
||||||
buffer[0x3F] = 0x00;
|
|
||||||
PASS = (char*)(buffer + 0x20);
|
|
||||||
ip = (uint32_t *)(buffer + 0x40);
|
|
||||||
subnet = (uint32_t *)(buffer + 0x44);
|
|
||||||
gw = (uint32_t *)(buffer + 0x48);
|
|
||||||
mode = (uint8_t *)(buffer + 0x4C);
|
|
||||||
}
|
}
|
||||||
config_file.close();
|
config_file.close();
|
||||||
return true;
|
return true;
|
||||||
@@ -36,40 +33,46 @@ bool Config::loadBin()
|
|||||||
|
|
||||||
bool Config::saveBin()
|
bool Config::saveBin()
|
||||||
{
|
{
|
||||||
File config_file = LittleFS.open("/settings", "w");
|
File config_file = LittleFS.open(_filepath, "w");
|
||||||
config_file.write(buffer,CONFIG_SIZE);
|
config_file.write(buffer, CONFIG_SIZE);
|
||||||
delay(100);
|
delay(100);
|
||||||
config_file.close();
|
config_file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Config::setSSID(const char *ssid){
|
bool Config::setSSID(const char *ssid)
|
||||||
|
{
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
bool copy = true;
|
bool copy = true;
|
||||||
for(int i=0; i<31;i++){
|
for (int i = 0; i < 31; i++)
|
||||||
if(ssid[i]==0x00)
|
{
|
||||||
|
if (ssid[i] == 0x00)
|
||||||
copy = false;
|
copy = false;
|
||||||
buffer[offset+i] = copy?ssid[i]:0x00;
|
buffer[offset + i] = copy ? ssid[i] : 0x00;
|
||||||
}
|
}
|
||||||
buffer[offset+31] = '\n';
|
buffer[offset + 31] = '\n';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Config::setPASS(const char *pass){
|
bool Config::setPASS(const char *pass)
|
||||||
|
{
|
||||||
size_t offset = 0x20;
|
size_t offset = 0x20;
|
||||||
bool copy = true;
|
bool copy = true;
|
||||||
for(int i=0; i<31;i++){
|
for (int i = 0; i < 31; i++)
|
||||||
if(pass[i]==0x00)
|
{
|
||||||
|
if (pass[i] == 0x00)
|
||||||
copy = false;
|
copy = false;
|
||||||
buffer[offset+i] = copy?pass[i]:0x00;
|
buffer[offset + i] = copy ? pass[i] : 0x00;
|
||||||
}
|
}
|
||||||
buffer[offset+31] = '\n';
|
buffer[offset + 31] = '\n';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void Config::print(){
|
void Config::print()
|
||||||
|
{
|
||||||
Serial.print("BufferHEX ");
|
Serial.print("BufferHEX ");
|
||||||
for(int i=0; i<CONFIG_SIZE;i++){
|
for (int i = 0; i < CONFIG_SIZE; i++)
|
||||||
Serial.print(i,HEX);
|
{
|
||||||
|
Serial.print(i, HEX);
|
||||||
Serial.print(">");
|
Serial.print(">");
|
||||||
Serial.print(buffer[i],HEX);
|
Serial.print(buffer[i], HEX);
|
||||||
Serial.print("|");
|
Serial.print("|");
|
||||||
}
|
}
|
||||||
Serial.print("SSID: ");
|
Serial.print("SSID: ");
|
||||||
@@ -77,30 +80,27 @@ void Config::print(){
|
|||||||
Serial.print("PASS: ");
|
Serial.print("PASS: ");
|
||||||
Serial.println(PASS);
|
Serial.println(PASS);
|
||||||
Serial.print("IP");
|
Serial.print("IP");
|
||||||
Serial.print((uint8_t) *ip, DEC);
|
Serial.print(*((uint8_t *)&ip), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print((uint8_t)*((uint8_t*)ip+1), DEC);
|
Serial.print(* (((uint8_t *)&ip + 1)), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print((uint8_t) *((uint8_t*)ip+2), DEC);
|
Serial.print(* ((uint8_t *)&ip + 2), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.println((uint8_t) *((uint8_t*)ip+3), DEC);
|
Serial.println( * ((uint8_t *)&ip + 3), DEC);
|
||||||
Serial.print("GW");
|
Serial.print("GW");
|
||||||
Serial.print((uint8_t) *((uint8_t*)gw), DEC);
|
Serial.print( * ((uint8_t *)&gw), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print((uint8_t) *((uint8_t*)gw+1), DEC);
|
Serial.print( * ((uint8_t *)&gw + 1), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print((uint8_t) *((uint8_t*)gw+2), DEC);
|
Serial.print( * ((uint8_t *)&gw + 2), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.println((uint8_t) *((uint8_t*)gw+3), DEC);
|
Serial.println( * ((uint8_t *)&gw + 3), DEC);
|
||||||
Serial.print("SUBNET");
|
Serial.print("SUBNET");
|
||||||
Serial.print((uint8_t)*((uint8_t*)subnet), DEC);
|
Serial.print( * ((uint8_t *)&subnet), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print((uint8_t)*((uint8_t*)subnet+1), DEC);
|
Serial.print( * ((uint8_t *)&subnet + 1), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print((uint8_t)*((uint8_t*)subnet+2), DEC);
|
Serial.print( * ((uint8_t *)&subnet + 2), DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.println((uint8_t)*((uint8_t*)subnet+3), DEC);
|
Serial.println( * ((uint8_t *)&subnet + 3), DEC);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+21
-8
@@ -1,20 +1,33 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "LittleFS.h"
|
#include "LittleFS.h"
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
|
#define OFFSET_SSID 0x00
|
||||||
|
#define OFFSET_PASS 0x20
|
||||||
|
#define OFFSET_IP 0x40
|
||||||
|
#define OFFSET_SUBNET 0x44
|
||||||
|
#define OFFSET_GW 0x48
|
||||||
|
#define OFFSET_MODE 0x4C
|
||||||
|
#define OFFSET_FAIL_TIMEOUT 0x4D
|
||||||
|
#define OFFSET_HOLD_TIME 0x4E
|
||||||
|
#define CONFIG_SIZE 0x4F
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint8_t *buffer = nullptr;
|
uint8_t *buffer = (uint8_t *)malloc(CONFIG_SIZE);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config();
|
Config(const char* filepath);
|
||||||
~Config();
|
~Config();
|
||||||
const char *SSID;
|
const char *SSID = (char *)(buffer + OFFSET_SSID);
|
||||||
const char *PASS;
|
const char *PASS = (char *)(buffer + OFFSET_PASS);
|
||||||
uint8_t *mode;
|
uint32_t &ip = *((uint32_t*)(buffer+OFFSET_IP));
|
||||||
uint32_t *ip;
|
uint32_t &subnet = *((uint32_t*)(buffer+OFFSET_SUBNET));
|
||||||
uint32_t *subnet;
|
uint32_t &gw = *((uint32_t*)(buffer+OFFSET_GW));
|
||||||
uint32_t *gw;
|
uint8_t &mode = *(buffer + OFFSET_MODE);
|
||||||
|
uint8_t &fail_timeout = *(buffer+OFFSET_FAIL_TIMEOUT);
|
||||||
|
uint8_t &hold_time = *(buffer+OFFSET_HOLD_TIME);
|
||||||
|
const char* _filepath;
|
||||||
|
bool setFilePath(const char* filepath);
|
||||||
bool loadConfig();
|
bool loadConfig();
|
||||||
bool loadBin();
|
bool loadBin();
|
||||||
bool saveBin();
|
bool saveBin();
|
||||||
|
|||||||
+2
-4
@@ -1,8 +1,6 @@
|
|||||||
#include "Keyboard.h"
|
#include "Keyboard.h"
|
||||||
|
|
||||||
//#define DEBUG
|
|
||||||
#define PIN_WIRE_SDA D3
|
|
||||||
#define PIN_WIRE_SCL D4
|
|
||||||
Keyboard::Keyboard(uint8_t _debounce)
|
Keyboard::Keyboard(uint8_t _debounce)
|
||||||
{
|
{
|
||||||
this->keybind.insert({
|
this->keybind.insert({
|
||||||
@@ -23,7 +21,7 @@ Keyboard::Keyboard(uint8_t _debounce)
|
|||||||
}
|
}
|
||||||
void Keyboard::begin(TwoWire *databus)
|
void Keyboard::begin(TwoWire *databus)
|
||||||
{
|
{
|
||||||
pcf8574 = new PCF8574(databus, 0x21, PIN_WIRE_SDA, PIN_WIRE_SCL);
|
pcf8574 = new PCF8574(databus, 0x21);
|
||||||
pcf8574->pinMode(0, OUTPUT);
|
pcf8574->pinMode(0, OUTPUT);
|
||||||
for (int i = 1; i < 8; i++)
|
for (int i = 1; i < 8; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include "Relais.h"
|
||||||
|
|
||||||
|
Relais::Relais(uint8_t pin)
|
||||||
|
{
|
||||||
|
pinMode(pin, OUTPUT);
|
||||||
|
digitalWrite(_pin, 1);
|
||||||
|
_pin = pin;
|
||||||
|
}
|
||||||
|
void Relais::cylce()
|
||||||
|
{
|
||||||
|
if (!_state)
|
||||||
|
return;
|
||||||
|
if (millis() > _call_time)
|
||||||
|
{
|
||||||
|
digitalWrite(_pin, 1);
|
||||||
|
_state = false;
|
||||||
|
Serial.println("Relay released.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Relais::activate(uint8_t seconds)
|
||||||
|
{
|
||||||
|
Serial.println("Relay activated for "+String(seconds)+" Seconds.");
|
||||||
|
digitalWrite(_pin, 0);
|
||||||
|
_state = true;
|
||||||
|
_call_time = millis() + seconds * 1000;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
class Relais
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Relais(uint8_t pin);
|
||||||
|
void cylce();
|
||||||
|
void activate(uint8_t seconds);
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long _call_time = 0;
|
||||||
|
bool _state = false;
|
||||||
|
uint8_t _pin;
|
||||||
|
};
|
||||||
+4
-3
@@ -1,8 +1,8 @@
|
|||||||
#include "Rfid.h"
|
#include "Rfid.h"
|
||||||
#define SS_PIN D8
|
#define SS_PIN D8
|
||||||
#define RST_PIN D1
|
#define RST_PIN D0
|
||||||
#define RFID_TIMEOUT 3000
|
#define RFID_TIMEOUT 3000
|
||||||
Rfid::Rfid(/* args */) : _mfrc522(SS_PIN)
|
Rfid::Rfid(/* args */) : _mfrc522(SS_PIN, RST_PIN)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,11 +33,12 @@ void Rfid::scan()
|
|||||||
{
|
{
|
||||||
_status = 1;
|
_status = 1;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.print(this->_rfid);
|
_mfrc522.PICC_DumpToSerial(&(_mfrc522.uid));
|
||||||
#endif
|
#endif
|
||||||
this->_lastRfid = this->_rfid;
|
this->_lastRfid = this->_rfid;
|
||||||
this->_lastRfidScan = millis();
|
this->_lastRfidScan = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+143
-7
@@ -10,10 +10,28 @@ WebConsole::~WebConsole()
|
|||||||
_server->close();
|
_server->close();
|
||||||
delete (_server);
|
delete (_server);
|
||||||
}
|
}
|
||||||
bool WebConsole::init(userdb::UserDb *userdb)
|
bool WebConsole::init(Config *config, userdb::UserDb *userdb)
|
||||||
{
|
{
|
||||||
_server = new ESP8266WebServer(80);
|
|
||||||
this->userdb = userdb;
|
this->userdb = userdb;
|
||||||
|
this->_config = config;
|
||||||
|
this->userdb = userdb;
|
||||||
|
// Wifi Setup
|
||||||
|
this->_dnsServer = new DNSServer;
|
||||||
|
WiFi.mode(WIFI_AP);
|
||||||
|
Serial.print("\t1. Network config... ");
|
||||||
|
Serial.println(WiFi.softAPConfig(_config->ip, _config->gw, _config->subnet) ? "Ready" : "Failed!");
|
||||||
|
Serial.print("\t2. DNS config... ");
|
||||||
|
Serial.println(_dnsServer->start(53, "*", _config->ip) ? "Ready" : "Failed!");
|
||||||
|
Serial.print("\t3 AP setup SSID:\"" + String(_config->SSID) + "\"... ");
|
||||||
|
if (strlen(_config->PASS) > 0)
|
||||||
|
Serial.println(WiFi.softAP(_config->SSID, _config->PASS) ? "Ready" : "Failed!");
|
||||||
|
else
|
||||||
|
Serial.println(WiFi.softAP(_config->SSID) ? "Ready" : "Failed!");
|
||||||
|
WiFi.hostname("Doorlock");
|
||||||
|
Serial.println("Please connect via http://" + WiFi.softAPIP().toString() + "/");
|
||||||
|
|
||||||
|
// Webserver Setup
|
||||||
|
this->_server = new ESP8266WebServer(80);
|
||||||
const char *headerkeys[] = {"Authentification"};
|
const char *headerkeys[] = {"Authentification"};
|
||||||
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *);
|
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *);
|
||||||
_server->collectHeaders(headerkeys, headerkeyssize);
|
_server->collectHeaders(headerkeys, headerkeyssize);
|
||||||
@@ -27,8 +45,7 @@ bool WebConsole::init(userdb::UserDb *userdb)
|
|||||||
_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));
|
||||||
_server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_PUT, std::bind(&WebConsole::_createUser, this));
|
_server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_PUT, std::bind(&WebConsole::_createUser, this));
|
||||||
_server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_POST, std::bind(&WebConsole::_updateUser, this));
|
_server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_POST, std::bind(&WebConsole::_updateUser, this));
|
||||||
_server->on(UriBraces("/api/config/{}"), std::bind(&WebConsole::_deleteUser, this));
|
_server->on(UriBraces("/api/config"), HTTPMethod::HTTP_POST, std::bind(&WebConsole::_settings, this));
|
||||||
//_server->on("/bypin",std::bind(&WebConsole::_findPin,this));
|
|
||||||
_server->serveStatic("/", LittleFS, "/s/");
|
_server->serveStatic("/", LittleFS, "/s/");
|
||||||
_server->onNotFound(std::bind(&WebConsole::_handleUnknown, this));
|
_server->onNotFound(std::bind(&WebConsole::_handleUnknown, this));
|
||||||
return true;
|
return true;
|
||||||
@@ -39,9 +56,11 @@ void WebConsole::attachRfid(Rfid *rfid)
|
|||||||
}
|
}
|
||||||
void WebConsole::serve()
|
void WebConsole::serve()
|
||||||
{
|
{
|
||||||
|
_dnsServer->processNextRequest();
|
||||||
if (catch_rfid)
|
if (catch_rfid)
|
||||||
{
|
{
|
||||||
if (millis() - catch_rfid_millis > 2000){
|
if (millis() - catch_rfid_millis > 2000)
|
||||||
|
{
|
||||||
catch_rfid = 0;
|
catch_rfid = 0;
|
||||||
}
|
}
|
||||||
else if (catch_rfid > 1 && rfid != nullptr && rfid->available())
|
else if (catch_rfid > 1 && rfid != nullptr && rfid->available())
|
||||||
@@ -54,8 +73,9 @@ void WebConsole::serve()
|
|||||||
}
|
}
|
||||||
uint8_t WebConsole::isInterceptingRfid()
|
uint8_t WebConsole::isInterceptingRfid()
|
||||||
{
|
{
|
||||||
if(catch_rfid==3){
|
if (catch_rfid == 3)
|
||||||
catch_rfid=2;
|
{
|
||||||
|
catch_rfid = 2;
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +83,11 @@ uint8_t WebConsole::isInterceptingRfid()
|
|||||||
}
|
}
|
||||||
bool WebConsole::_isAuth()
|
bool WebConsole::_isAuth()
|
||||||
{
|
{
|
||||||
|
if (_server->method() == HTTPMethod::HTTP_OPTIONS)
|
||||||
|
{
|
||||||
|
_server->send(204);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!_server->hasHeader("Authentification"))
|
if (!_server->hasHeader("Authentification"))
|
||||||
{
|
{
|
||||||
_server->send(401, "text/plain", "Error 401: Unauthorized (missing auth token)");
|
_server->send(401, "text/plain", "Error 401: Unauthorized (missing auth token)");
|
||||||
@@ -108,6 +133,117 @@ void WebConsole::_auth()
|
|||||||
else
|
else
|
||||||
_server->send(404, "text/plain", "unknown action");
|
_server->send(404, "text/plain", "unknown action");
|
||||||
}
|
}
|
||||||
|
void WebConsole::_settings()
|
||||||
|
{
|
||||||
|
_sendCORS();
|
||||||
|
if (!_isAuth())
|
||||||
|
return;
|
||||||
|
String action = _server->arg("action");
|
||||||
|
if (action.equals("update"))
|
||||||
|
{
|
||||||
|
uint8_t error = 0b00000000;
|
||||||
|
uint8_t sucess = 0b00000000;
|
||||||
|
if (_server->hasArg("SSID"))
|
||||||
|
{
|
||||||
|
_config->setSSID(_server->arg("SSID").c_str());
|
||||||
|
int length = strlen(_config->SSID);
|
||||||
|
if (length == 0 || length > 31)
|
||||||
|
error |= 0b00000001;
|
||||||
|
else
|
||||||
|
sucess |= 0b00000001;
|
||||||
|
}
|
||||||
|
if (_server->hasArg("PASS"))
|
||||||
|
{
|
||||||
|
_config->setSSID(_server->arg("PASS").c_str());
|
||||||
|
int length = strlen(_config->SSID);
|
||||||
|
if (length == 0 || length > 31)
|
||||||
|
error |= 0b00000010;
|
||||||
|
else
|
||||||
|
sucess |= 0b00000010;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_server->hasArg("ip"))
|
||||||
|
{
|
||||||
|
IPAddress temp;
|
||||||
|
if (temp.fromString(_server->arg("ip")))
|
||||||
|
{
|
||||||
|
_config->ip = temp.v4();
|
||||||
|
sucess |= 0b00000100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
error |= 0b00000100;
|
||||||
|
}
|
||||||
|
if (_server->hasArg("subnet"))
|
||||||
|
{
|
||||||
|
IPAddress temp;
|
||||||
|
if (temp.fromString(_server->arg("subnet")))
|
||||||
|
{
|
||||||
|
_config->subnet = temp.v4();
|
||||||
|
sucess |= 0b00001000;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
error |= 0b00001000;
|
||||||
|
}
|
||||||
|
if (_server->hasArg("gw"))
|
||||||
|
{
|
||||||
|
IPAddress temp;
|
||||||
|
if (temp.fromString(_server->arg("gw")))
|
||||||
|
{
|
||||||
|
_config->gw = temp.v4();
|
||||||
|
sucess |= 0b00010000;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
error |= 0b00010000;
|
||||||
|
}
|
||||||
|
if (_server->hasArg("mode"))
|
||||||
|
{
|
||||||
|
_config->mode = _server->arg("mode").toInt();
|
||||||
|
if (_config->mode >= 0 && _config->mode <= 1)
|
||||||
|
sucess |= 0b00100000;
|
||||||
|
else
|
||||||
|
error |= 0b00100000;
|
||||||
|
}
|
||||||
|
if (_server->hasArg("fail_timeout"))
|
||||||
|
{
|
||||||
|
_config->fail_timeout = _server->arg("fail_timeout").toInt();
|
||||||
|
if (_config->fail_timeout >= 0 && _config->fail_timeout <= 250)
|
||||||
|
sucess |= 0b01000000;
|
||||||
|
else
|
||||||
|
error |= 0b01000000;
|
||||||
|
}
|
||||||
|
if (_server->hasArg("hold_time"))
|
||||||
|
{
|
||||||
|
_config->hold_time = _server->arg("hold_time").toInt();
|
||||||
|
if (_config->hold_time > 0 && _config->hold_time <= 250)
|
||||||
|
sucess |= 0b10000000;
|
||||||
|
else
|
||||||
|
error |= 0b10000000;
|
||||||
|
}
|
||||||
|
if (error == 0 && sucess > 0)
|
||||||
|
{ // Save
|
||||||
|
_config->saveBin();
|
||||||
|
_server->send(200, "text/json", "{\"status\":\"ok\", \"sucess\":\"" + String(sucess) + "\"}");
|
||||||
|
}
|
||||||
|
else if (error > 0)
|
||||||
|
{ // Rollback
|
||||||
|
_config->loadBin();
|
||||||
|
_server->send(200, "text/json", "{\"status\":\"failed\", \"sucess\":\"" + String(sucess) + "\", \"error\":\"" + String(error) + "\"}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_server->send(200, "text/json", "{\"status\":\"noting_todo\"}");
|
||||||
|
}
|
||||||
|
else if (action.equals("get"))
|
||||||
|
{
|
||||||
|
_server->send(200, "text/json", "{\"SSID\":\"" + String(_config->SSID) + "\", \"PASS\":\"" + String(_config->PASS) + "\", \"ip\":\"" + IPAddress(_config->ip).toString() + "\", \"subnet\":\"" + IPAddress(_config->subnet).toString() + "\", \"gw\":\"" + IPAddress(_config->gw).toString() + "\", \"mode\":\"" + String(_config->mode) + "\", \"fail_timeout\":\"" + String(_config->fail_timeout) + "\", \"hold_time\":\"" + String(_config->hold_time) + "\"}");
|
||||||
|
}
|
||||||
|
else if (action.equals("apply"))
|
||||||
|
{
|
||||||
|
_server->send(200, "text/json", "{\"status\":\"restarting\"}");
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_server->send(404, "text/plain", "unknown action");
|
||||||
|
}
|
||||||
void WebConsole::_sendCORS()
|
void WebConsole::_sendCORS()
|
||||||
{
|
{
|
||||||
_server->sendHeader("Access-Control-Allow-Origin", "*");
|
_server->sendHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
+7
-1
@@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
|
#include <DNSServer.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <uri/UriBraces.h>
|
#include <uri/UriBraces.h>
|
||||||
@@ -7,6 +9,7 @@
|
|||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "UserDb.h"
|
#include "UserDb.h"
|
||||||
#include "Rfid.h"
|
#include "Rfid.h"
|
||||||
|
#include "Config.h"
|
||||||
#include "AdminAuth.h"
|
#include "AdminAuth.h"
|
||||||
#include "Interface.h"
|
#include "Interface.h"
|
||||||
namespace webconsole
|
namespace webconsole
|
||||||
@@ -19,13 +22,14 @@ namespace webconsole
|
|||||||
WebConsole();
|
WebConsole();
|
||||||
~WebConsole();
|
~WebConsole();
|
||||||
|
|
||||||
bool init(userdb::UserDb *userdb);
|
bool init(Config *config, userdb::UserDb *userdb);
|
||||||
void attachRfid(Rfid *rfid);
|
void attachRfid(Rfid *rfid);
|
||||||
void serve();
|
void serve();
|
||||||
uint8_t isInterceptingRfid();
|
uint8_t isInterceptingRfid();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _sendCORS();
|
void _sendCORS();
|
||||||
|
void _settings();
|
||||||
void _auth();
|
void _auth();
|
||||||
bool _isAuth();
|
bool _isAuth();
|
||||||
void _handleUnknown();
|
void _handleUnknown();
|
||||||
@@ -47,6 +51,8 @@ namespace webconsole
|
|||||||
_server->send(200, "text/plain", "printed to serial");
|
_server->send(200, "text/plain", "printed to serial");
|
||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
|
Config *_config;
|
||||||
|
DNSServer *_dnsServer;
|
||||||
ESP8266WebServer *_server;
|
ESP8266WebServer *_server;
|
||||||
userdb::UserDb *userdb = nullptr;
|
userdb::UserDb *userdb = nullptr;
|
||||||
unsigned long catch_rfid_millis = 0;
|
unsigned long catch_rfid_millis = 0;
|
||||||
|
|||||||
+13
-30
@@ -8,48 +8,29 @@
|
|||||||
#include "WebConsole.h"
|
#include "WebConsole.h"
|
||||||
#include "UserDb.h"
|
#include "UserDb.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include <ESP8266mDNS.h>
|
#include "Relais.h"
|
||||||
#include <DNSServer.h>
|
|
||||||
// File config
|
// File config
|
||||||
Config config;
|
Config config("/settings");
|
||||||
userdb::UserDb userdatabase("userdb.csv");
|
userdb::UserDb userdatabase("/userdb.csv");
|
||||||
webconsole::WebConsole web;
|
webconsole::WebConsole web;
|
||||||
// Rfid
|
// Rfid
|
||||||
Rfid rfid;
|
Rfid rfid;
|
||||||
// i2C Bus
|
// i2C Bus
|
||||||
#define PIN_WIRE_SDA D3
|
#define PIN_WIRE_SDA D1
|
||||||
#define PIN_WIRE_SCL D4
|
#define PIN_WIRE_SCL D2
|
||||||
|
Relais relay(D4);
|
||||||
Keyboard keyboard(200);
|
Keyboard keyboard(200);
|
||||||
|
|
||||||
Interface iface;
|
Interface iface;
|
||||||
// Wifi control
|
|
||||||
IPAddress local_IP(192, 168, 4, 22);
|
|
||||||
IPAddress gateway(0, 0, 0, 0);
|
|
||||||
IPAddress subnet(255, 255, 255, 0);
|
|
||||||
IPAddress dns(192, 168, 178, 1);
|
|
||||||
DNSServer dnsServer;
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
//config.loadConfig();
|
|
||||||
config.loadBin();
|
config.loadBin();
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Starting System");
|
Serial.println("Starting System...");
|
||||||
Serial.print("\t1. Network config ->");
|
|
||||||
WiFi.mode(WIFI_AP);
|
|
||||||
Serial.println(WiFi.softAPConfig(*config.ip, *config.gw, *config.subnet) ? "Ready" : "Failed!");
|
|
||||||
Serial.print("\t2 AP setup " + String(config.SSID) + " -> ");
|
|
||||||
if (strlen(config.PASS) > 0)
|
|
||||||
Serial.println(WiFi.softAP(config.SSID, config.PASS) ? "Ready" : "Failed!");
|
|
||||||
else
|
|
||||||
Serial.println(WiFi.softAP(config.SSID) ? "Ready" : "Failed!");
|
|
||||||
WiFi.hostname("Doorlock");
|
|
||||||
dnsServer.start(53, "*", local_IP); // DNS spoofing (Only HTTP)
|
|
||||||
delay(150);
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
userdatabase.print_to_serial();
|
userdatabase.print_to_serial();
|
||||||
#endif
|
#endif
|
||||||
web.init(&userdatabase);
|
web.init(&config, &userdatabase);
|
||||||
keyboard.begin(&Wire);
|
keyboard.begin(&Wire);
|
||||||
rfid.begin();
|
rfid.begin();
|
||||||
web.attachRfid(&rfid);
|
web.attachRfid(&rfid);
|
||||||
@@ -58,17 +39,18 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
dnsServer.processNextRequest();
|
relay.cylce();
|
||||||
rfid.scan();
|
rfid.scan();
|
||||||
web.serve();
|
web.serve();
|
||||||
keyboard.scanAsync();
|
keyboard.scanAsync();
|
||||||
userdb::User login_user;
|
userdb::User login_user;
|
||||||
if (web.isInterceptingRfid() ==3)
|
if (web.isInterceptingRfid() == 3)
|
||||||
iface.showMessage("WebUI connected", "Awaiting RFID", 2000);
|
iface.showMessage("WebUI connected", "Awaiting RFID", 2000);
|
||||||
else if (web.isInterceptingRfid() == 1)
|
else if (web.isInterceptingRfid() == 1)
|
||||||
iface.showMessage("WebUI connected", "RFID Found", 1000);
|
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();
|
||||||
login_user = userdatabase.user_by_pin(iface.getPin());
|
login_user = userdatabase.user_by_pin(iface.getPin());
|
||||||
Serial.println("Query duration: " + String(millis() - delta));
|
Serial.println("Query duration: " + String(millis() - delta));
|
||||||
@@ -94,6 +76,7 @@ void loop()
|
|||||||
{
|
{
|
||||||
iface.greetUser(login_user.first_name + " " + login_user.last_name);
|
iface.greetUser(login_user.first_name + " " + login_user.last_name);
|
||||||
Serial.println("Logon from User " + login_user.toString());
|
Serial.println("Logon from User " + login_user.toString());
|
||||||
|
relay.activate(config.hold_time);
|
||||||
}
|
}
|
||||||
iface.render();
|
iface.render();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user