Skip to content

Commit

Permalink
v0.1 Release
Browse files Browse the repository at this point in the history
- This is the most basic functionality release.
- I tried the cover all the basics, and make a reliable release.
  • Loading branch information
omersiar committed Jul 12, 2017
1 parent 7a6a454 commit 997606f
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.1] - 2017-07-12 - :hurray: We hit the 0.1!
#### Added
- Relay Module configuration in Settings Page (You need to make sure how the relay module reacts when device is restarting or on power-on, make changes accordingly). I may try to make it more universal, but for now it's up to you.
- Relay Test Button
- Ability to Add known PICC to User List (useful to add new PICC to device when device is already deployed)

## [0.1rc2] - 2017-07-10 - Release Candidate
#### Added
- User List table now automaticly sorted by Name
Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Access Control demonstration using a cheap MFRC522 RFID Hardware and Espressif's

![IP](https://github.com/omersiar/esp-rfid/blob/master/demo/index.png?raw=true)
![SP](https://github.com/omersiar/esp-rfid/blob/master/demo/settings.png?raw=true)
![UP](https://github.com/omersiar/esp-rfid/blob/master/demo/users.png?raw=true)

## Features
* Using WebSocket protocol to exchange data between Hardware and Web Browser
Expand All @@ -13,13 +14,33 @@ Access Control demonstration using a cheap MFRC522 RFID Hardware and Espressif's

## Getting Started
This project still in its development phase. New features (and also bugs) are introduced often and some functions may become deprecated. Please feel free to comment or give feedback.
* Latest version is v0.1rc2
* Latest version is v0.1
* See [Known Issues](https://github.com/omersiar/esp-rfid#known-issues) before starting right away.
* See [ChangeLog](https://github.com/omersiar/esp-rfid/blob/master/CHANGELOG.md)
* See [To Do](https://github.com/omersiar/esp-rfid#to-do) for what to expect in future.

### Steps
* First, flash firmware to your ESP either using Arduino IDE or with your favourite flash tool
* Flash webfiles data to SPIFFS either using ESP8266FS Uploader tool or with your favourite flash tool
* (optional) Fire up your serial monitor to get informed
* Power on your ESP
* Search for Wireless Network "esp-rfid" and connect to it (It should be an open network and does not reqiure password)
* Open your browser and type either "http:https://192.168.4.1" or "http:https://esp-rfid.local" (.local needs Bonjour installed on your computer) on address bar.
* Log on to ESP, password is "admin" (for now, you can only change it from source)
* Go to "Settings" page
* Configure your amazing access control device. Push "Scan" button to join your wireless network, configure RFID hardware, Relay Module.
* Save settings, when rebooted your ESP will try to join your wireless network.
* Check your new IP address from serial monitor and connect to your ESP again. (You can also connect to "http:https://esp-rfid.local")
* Go to "Users" page
* Scan a PICC (RFID Tag) then it should glimpse on your Browser's screen.
* Type "User Name" or "Label" for the PICC you scanned.
* Choose "Allow Access" if you want to
* Click "Add"
* Congratulations, everything went well, if you encounter any issue feel free to ask help on GitHub.

### Using Compiled Binaries
Compiled binaries are available in directory /compiledbin.
Compiled binaries are available in directory /compiledbin. You can use any flashing tool and do the flashing manually. The flashing process itself has been described at numerous places on Internet.


### Building from Source
Please install Arduino IDE if you didn't already, then add ESP8266 Core (Beware! Install Git Version) on top of it. Additional Library download links are listed below:
Expand Down Expand Up @@ -57,6 +78,7 @@ The following table shows the typical pin layout used for connecting MFRC522 har
* Built-in HTML Editor has hard-coded JavaScript that loads from CDN Internet. Text Editor won't work if there is no Internet connection.
* Currently only Git version (2.4.0rc) of ESP8266 Core is supported, due to new function is introduced (WiFi.scanNetworksAsync()).
* Firmware update does not authenticated (until we find a solution).
* When you connect to ESP via mDNS url Browsers make a DNS Query for WebSocket link, it takes long time to resolve.

## Scalability
Since we are limited on both flash and ram size things may get ugly at some point in the future. You can find out some test results below.
Expand Down Expand Up @@ -94,6 +116,8 @@ At least 100 unique User (RFID Tag) can be handled, the test were performed on W
- [ ] Sanity check where needed (min WPA password lenght, return status of commands to WebSocket, etc)
- [ ] Close security holes (there are many, for example WebSocket communication is not Authenticated at all)
- [ ] rBoot for secondary recovery program? to flash main firmware maybe?
- [ ] Find a way to speed up DNS query for WebSocket. Takes a lot of time
- [ ] Switch to Async JSON. This may allow much larger transfers from ESP to Browser
- [X] Polished web pages

## Donations
Expand Down
Binary file modified compiledbin/latest.bin
Binary file not shown.
Binary file modified compiledbin/latestspiffs.bin
Binary file not shown.
Binary file removed compiledbin/v003.bin
Binary file not shown.
Binary file removed compiledbin/v003.spiffs.bin
Binary file not shown.
Binary file added compiledbin/v01.bin
Binary file not shown.
8 changes: 8 additions & 0 deletions data/auth/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function listCONF(obj) {
document.getElementById("gpioss").value = obj.sspin;
document.getElementById("gpiorst").value = obj.rstpin;
document.getElementById("gain").value = obj.rfidgain;
document.getElementById("gpiorly").value = obj.rpin;
document.getElementById("delay").value = obj.rtime;
}

function listSSID(obj) {
Expand Down Expand Up @@ -46,9 +48,15 @@ function saveConf() {
datatosend.sspin = document.getElementById("gpioss").value;
datatosend.rstpin = document.getElementById("gpiorst").value;
datatosend.rfidgain = document.getElementById("gain").value;
datatosend.rpin = document.getElementById("gpiorly").value;
datatosend.rtime = document.getElementById("delay").value;
websock.send(JSON.stringify(datatosend));
}

function testRelay() {
websock.send("{\"command\":\"testrelay\"}");
}

function start() {
websock = new WebSocket("ws:https://" + window.location.hostname + "/ws");
websock.onopen = function(evt) {
Expand Down
37 changes: 32 additions & 5 deletions data/auth/settings.htm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ <h5>Please wait while WebSocket connecting...</h5>
<div class="col-sm-6 col-sm-push-6">
<fieldset>
<legend>Wi-Fi Client Settings</legend>
<p style="font-size:12px;" class="text-muted">Type your Wi-Fi Network's SSID or Scan for nerby Wireless Networks to join.</p>
<h6 class="text-muted">Type your Wi-Fi Network's SSID or Scan for nerby Wireless Networks to join.</h6>
<br>
<div class="row form-group">
<label class="col-xs-3">SSID</label>
<span class="col-xs-9">
Expand All @@ -57,7 +58,8 @@ <h5>Please wait while WebSocket connecting...</h5>
<div class="col-sm-6 col-sm-pull-6">
<fieldset>
<legend>MFRC522 Hardware Settings</legend>
<p style="font-size:12px;" class="text-muted">Please refer the <a href="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/omersiar/esp-rfid#pin-layout">documentation</a> for pin configuration.</p>
<h6 class="text-muted">Please refer the <a href="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/omersiar/esp-rfid#pin-layout">documentation</a> for pin configuration.</h6>
<br>
<div class="row form-group">
<label class="col-xs-3">RST/Reset</label>
<span class="col-xs-9">
Expand Down Expand Up @@ -97,18 +99,42 @@ <h5>Please wait while WebSocket connecting...</h5>
</select>
</span>
</div>
<br>
<div class="row form-group">
<label class="col-xs-3">Relay Pin</label>
<span class="col-xs-9">
<select class="form-control input-sm" style="max-width:185px" id="gpiorly">
<option value="0">GPIO-0</option>
<option value="2">GPIO-2</option>
<option selected="selected" value="4">GPIO-4</option>
<option value="5">GPIO-5</option>
<option value="15">GPIO-15</option>
<option value="16">GPIO-16</option>
</select>
</span>
</div>
<div class="row form-group">
<label class="col-xs-3">Activate Time</label>
<span class="col-xs-9">
<input class="form-control input-sm" placeholder="in Microsecond" style="display:inline;max-width:185px" id="delay" type="text" name="hightime">
</span>
</div>
<button id="testb" type="button" class="btn btn-primary btn-xs" onclick="testRelay()">Test Relay</button><h6 class="text-muted"> Please reboot before test</h6>
</fieldset>
</div>
</div>
<div><button onclick="saveConf()" class="btn btn-primary btn-sm pull-right">Save & Reboot</button>
<hr>
<div>
<button onclick="saveConf()" class="btn btn-primary btn-sm pull-right">Save & Reboot</button>
</div>
<br>
</div>
<div class="jumbotron">
<div class="row">
<fieldset class="col-sm-6">
<legend>Update Firmware</legend>
<p style="font-size:12px;" class="text-muted">Download <a href="https://github.com/omersiar/esp-rfid/raw/master/compiledbin/latest.bin">latest version</a> from GitHub.</p>
<h6 class="text-muted">Download <a href="https://github.com/omersiar/esp-rfid/raw/master/compiledbin/latest.bin">latest version</a> from GitHub.</h6>
<br>
<form class="form-inline" method="POST" action="/auth/update" enctype="multipart/form-data">
<div class="form-group">
<input type="file" name="update">
Expand All @@ -120,7 +146,8 @@ <h5>Please wait while WebSocket connecting...</h5>
<fieldset class="col-sm-6">
<legend>Update SPIFFS</legend>
<div class="alert alert-danger"><strong>Warning!</strong> This will delete all data (including UIDs, Users, Settings).</div>
<p style="font-size:12px;" class="text-muted">Dowload <a href="https://github.com/omersiar/esp-rfid/raw/master/compiledbin/latestspiffs.bin">latest version</a> from GitHub.</p>
<h6 class="text-muted">Dowload <a href="https://github.com/omersiar/esp-rfid/raw/master/compiledbin/latestspiffs.bin">latest version</a> from GitHub.</h6>
<br>
<form class="form-inline" method="POST" action="/auth/spiupdate" enctype="multipart/form-data">
<div class="form-group">
<input type="file" name="update">
Expand Down
46 changes: 24 additions & 22 deletions data/auth/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ function sortTable(n) {
y = rows[i + 1].getElementsByTagName("TD")[n];
/*check if the two rows should switch place,
based on the direction, asc or desc:*/
if (dir == "asc") {
if (dir === "asc") {
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
//if so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
} else if (dir == "desc") {
} else if (dir === "desc") {
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
//if so, mark as a switch and break the loop:
shouldSwitch = true;
Expand All @@ -47,14 +47,32 @@ function sortTable(n) {
} else {
/*If no switching has been done AND the direction is "asc",
set the direction to "desc" and run the while loop again.*/
if (switchcount == 0 && dir == "asc") {
if (switchcount === 0 && dir === "asc") {
dir = "desc";
switching = true;
}
}
}
}

function fadeOutIn(elem, speed) {
if (!elem.style.opacity) {
elem.style.opacity = 1;
} // end if
var outInterval = setInterval(function() {
elem.style.opacity -= 0.02;
if (elem.style.opacity <= 0) {
clearInterval(outInterval);
var inInterval = setInterval(function() {
elem.style.opacity = Number(elem.style.opacity) + 0.02;
if (elem.style.opacity >= 1) {
clearInterval(inInterval);
}
}, speed / 50);
} // end if
}, speed / 50);
}

function addRowHandlers() {
var table = document.getElementById("tablebody");
var rows = table.getElementsByTagName("tr");
Expand All @@ -65,6 +83,7 @@ function addRowHandlers() {
return function() {
document.getElementById("uidinp").value = row.getElementsByTagName("td")[0].innerHTML;
document.getElementById("username").value = row.getElementsByTagName("td")[1].innerHTML;
document.getElementById("typeinp").value = "";
if (row.getElementsByTagName("td")[2].getElementsByTagName("input")[0].checked) {
document.getElementById("access").value = "1";
} else {
Expand Down Expand Up @@ -94,7 +113,7 @@ function listSCAN(obj) {
document.getElementById("access").value = obj.access;
var ref = document.getElementById("button");
ref.style.display = "block";
if (isKnown == 1) {
if (isKnown === 1) {
ref.dep = uid;
ref.className = "btn btn-warning btn-sm";
ref.onclick = function() {
Expand Down Expand Up @@ -139,30 +158,13 @@ function tableupdate(e) {
function update(e) {
var datatosend = {};
datatosend.command = "userfile";
datatosend.uid = e.dep;
datatosend.uid = document.getElementById("uidinp").value.toLowerCase();
datatosend.user = document.getElementById("username").value;
datatosend.haveAcc = document.getElementById("access").value;
websock.send(JSON.stringify(datatosend));
websock.send("{\"command\":\"picclist\"}");
}

function fadeOutIn(elem, speed) {
if (!elem.style.opacity) {
elem.style.opacity = 1;
} // end if
var outInterval = setInterval(function() {
elem.style.opacity -= 0.02;
if (elem.style.opacity <= 0) {
clearInterval(outInterval);
var inInterval = setInterval(function() {
elem.style.opacity = Number(elem.style.opacity) + 0.02;
if (elem.style.opacity >= 1)
clearInterval(inInterval);
}, speed / 50);
} // end if
}, speed / 50);
}

function listknownPICC(obj) {
var table = document.getElementById("knowntable").getElementsByTagName("tbody")[0];
for (var i = 0; i < obj.piccs.length; i++) {
Expand Down
Binary file modified demo/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/users.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 30 additions & 11 deletions esp-rfid.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ String filename = "/P/";
//flag to use from web update to reboot the ESP
bool shouldReboot = false;

bool activateRelay = false;
unsigned long previousMillis = 0;
int relayPin;
int activateTime;

extern "C" uint32_t _SPIFFS_start;
extern "C" uint32_t _SPIFFS_end;

Expand All @@ -72,11 +77,11 @@ void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.println(F("[ INFO ] ESP RFID v0.1rc2"));
Serial.println(F("[ INFO ] ESP RFID v0.1"));

// Start SPIFFS filesystem
SPIFFS.begin();

// Set Hostname.
WiFi.hostname(hstname);

Expand Down Expand Up @@ -140,7 +145,7 @@ void setup() {
}
}
});

// Simple SPIFFs Update Handler
server.on("/auth/spiupdate", HTTP_POST, [](AsyncWebServerRequest * request) {
shouldReboot = !Update.hasError();
Expand Down Expand Up @@ -183,17 +188,21 @@ void loop() {
delay(100);
ESP.restart();
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= activateTime) {
activateRelay = false;
digitalWrite(relayPin, HIGH);
}
if (activateRelay) {
digitalWrite(relayPin, LOW);
}
// Get Time from NTP Server
timeClient.update();

// Another loop for RFID Events, since we are using polling method instead of Interrupt we need to check RFID hardware for events
rfidloop();
}

void grantAccess() {
// do something if scanned PICC is known
}

// RFID Specific Loop
void rfidloop() {
//If a new PICC placed to RFID reader continue
Expand Down Expand Up @@ -253,7 +262,8 @@ void rfidloop() {
Serial.print(username);
// Check if user have an access
if (haveAcc == 1) {
grantAccess(); // Give user Access to Door, Safe, Box whatever you like
activateRelay = true; // Give user Access to Door, Safe, Box whatever you like
previousMillis = millis();
Serial.println(" have access");
}
else {
Expand Down Expand Up @@ -336,8 +346,7 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
// Web Browser sends some commands, check which command is given
const char * command = root["command"];
/*
// Check whatever the command is and act accordingly
if (strcmp(command, "add") == 0) {
if (strcmp(command, "add") == 0) {
const char* uid = root["uid"];
filename = "/P/";
filename += uid;
Expand All @@ -349,7 +358,8 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
ws.textAll("{\"command\":\"status\",\"add\":1}");
}
ws.textAll("{\"command\":\"status\",\"add\":0}");
}*/
}*/
// Check whatever the command is and act accordingly
if (strcmp(command, "remove") == 0) {
const char* uid = root["uid"];
filename = "/P/";
Expand Down Expand Up @@ -378,6 +388,10 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
f.close();
}
}
else if (strcmp(command, "testrelay") == 0) {
activateRelay = true;
previousMillis = millis();
}
else if (strcmp(command, "scan") == 0) {
WiFi.scanNetworksAsync(printScanResult);
}
Expand Down Expand Up @@ -489,6 +503,11 @@ bool loadConfiguration() {
int rfidgain = json["rfidgain"];
setupRFID(rfidss, rfidrst, rfidgain);

activateTime = json["rtime"];
relayPin = json["rpin"];
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);

const char * conssid = json["ssid"];
const char * conpassword = json["pswd"];

Expand Down

0 comments on commit 997606f

Please sign in to comment.