Skip to content

Commit

Permalink
Merge pull request #88 from omersiar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
omersiar committed Mar 23, 2018
2 parents 702e713 + 3854d11 commit 4707674
Show file tree
Hide file tree
Showing 20 changed files with 2,108 additions and 293 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# Change Log
All notable changes to this project will be documented in this file.

## [Unreleased]
#### Added
- [firmware] !!! BREAKING CHANGE !!! 2 MB Flash 2 MB SPIFFS size for future proof firmware updates plase make sure you made a backup before updating to this version. You need to format SPIFFS.
- [firmware] Experimental PN532 RFID Reader Support
- [webui] Try to connect button upon inprogress complete.
- [webui] Restart without saving changes.
- [firmware] Staging framework for platformio

#### Changed
- [webui] Sign in panel now integrated into index.html
- [firmware] Reduced serial outputs.
- [firmware] Switched to Async MQTT Library, needs testing.

#### Fixed
- [firmware] Logs causing Exception 9 because we are delaying async function with NTP sync by WiFi.hostbyname
- [webui] wrong version is shown #80.
- [webui] whole html was shifted with previous css change.

#### Removed
- [firmware] Factory reset via pin

## [0.6.1] - 2018-03-14
#### Added
- [firmware] ICACHE_FLASH_ATTR and ICACHE_RAM_ATTR decorators (did not feel any difference in terms of speed, keeping it anyway).
Expand Down
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ESP RFID - Access Control with ESP8266, RC522
# ESP RFID - Access Control with ESP8266, RC522 PN532 Wiegand

[![Chat at https://gitter.im/esp-rfid/Lobby](https://badges.gitter.im/esp-rfid.svg)](https://gitter.im/esp-rfid/Lobby) [![Build Status](https://travis-ci.org/omersiar/esp-rfid.svg?branch=stable)](https://travis-ci.org/omersiar/esp-rfid) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/fc424f75d12644da8b6fe248a5e95157)](https://www.codacy.com/app/omersiar/esp-rfid?utm_source=github.com&utm_medium=referral&utm_content=omersiar/esp-rfid&utm_campaign=Badge_Grade) [![Bountysource](https://api.bountysource.com/badge/team?team_id=242217)](https://salt.bountysource.com/checkout/amount?team=esp-rfid)

Access Control system using a cheap MFRC522 RFID Hardware or Wiegand RFID readers and Espressif's ESP8266 Microcontroller.
Access Control system using a cheap MFRC522, PN532 RFID readers or Wiegand RFID readers and Espressif's ESP8266 Microcontroller.

[See Demo Here](https://bitadvise.com/esp-rfid/)

Expand Down Expand Up @@ -35,7 +35,7 @@ This project still in its development phase. New features (and also bugs) are in
### What You Will Need
### Hardware
* An ESP8266 module or a development board like **WeMos D1 mini** or **NodeMcu 1.0** with at least **32Mbit Flash (equals to 4MBytes)** (ESP32 does not supported for now)
* A MFRC522 RFID PCD Module or Wiegand based RFID reader
* A MFRC522 RFID PCD Module or PN532 NFC Reader Module or Wiegand based RFID reader
* A Relay Module (or you can build your own circuit)
* n quantity of Mifare Classic 1KB (recommended due to available code base) PICCs (RFID Tags) equivalent to User Number

Expand Down Expand Up @@ -69,13 +69,13 @@ The resulting (built) image(s) can be found in the directory ```/bin``` created

The following table shows the typical pin layout used for connecting MFRC522 hardware to ESP:

| Signal | MFRC522 | WeMos D1 mini | NodeMcu | Generic |
|---------------|:-------------:|:--------------:| :------:|:------------:|
| RST/Reset | RST | N/C [1] | N/C [1] | N/C [1] |
| SPI SS | SDA [3] | D8 [2] | D8 [2] | GPIO-15 [2] |
| SPI MOSI | MOSI | D7 | D7 | GPIO-13 |
| SPI MISO | MISO | D6 | D6 | GPIO-12 |
| SPI SCK | SCK | D5 | D5 | GPIO-14 |
| Signal | PN532 | MFRC522 | WeMos D1 mini | NodeMcu | Generic |
|---------------|:-------------:|:-------------:|:--------------:|:-------:|:------------:|
| RST/Reset | RST | RST | N/C [1] | N/C [1] | N/C [1] |
| SPI SS | SS | SDA [3] | D8 [2] | D8 [2] | GPIO-15 [2] |
| SPI MOSI | MOSI | MOSI | D7 | D7 | GPIO-13 |
| SPI MISO | MISO | MISO | D6 | D6 | GPIO-12 |
| SPI SCK | SCK | SCK | D5 | D5 | GPIO-14 |

1. Not Connected. Hard-reset no longer needed.
2. Configurable via settings page.
Expand Down Expand Up @@ -111,9 +111,9 @@ This will require you to do syncing manually. ESP can store and hold time for yo
So you have to login to settings page and sync it in a timely fashion.

## **Security**
We assume **ESP-RFID** project -as a whole- does not ready for actual day-to-day usage in the means of security. [Crypto 1](http://www.cs.virginia.edu/~kn5f/Mifare.Cryptanalysis.htm) cipher is cracked which is used to secure Mifare Classic RFID PICCs (tags). There are PICCs available that their UID (Unique Identification Numbers) can be set manually (Currently esp-rfid relies only UID to identify it's users). Also there may be a bug in the code that result free access to your belongings. And also, like every other network connected device esp-rfid is vulnerable to many attacks including Man-in-the-middle, Brute-force, etc.
We assume **ESP-RFID** project -as a whole- does not offer strong security. There are PICCs available that their UID (Unique Identification Numbers) can be set manually (Currently esp-rfid relies only UID to identify it's users). Also there may be a bug in the code that may result free access to your belongings. And also, like every other network connected device esp-rfid is vulnerable to many attacks including Man-in-the-middle, Brute-force, etc.

These sound devastating security problems for a simple project, but we can not be held liable any damages done because of this software.
This is a simple, hobby grade project, do not use it where strong security is needed.

What can be done to increase security? (by you and by us)

Expand Down Expand Up @@ -164,11 +164,10 @@ See [ChangeLog](https://github.com/omersiar/esp-rfid/blob/dev/CHANGELOG.md)
## Donations
If this project helps you in a way, you can buy us a beer. You can make a donation to the ESP-RFID community with [Bountysource](https://salt.bountysource.com/teams/esp-rfid)

#### Donators
* 2017-10-03 [steinar-t](https://github.com/steinar-t)
* 2017-12-10 [saschaludwig](https://github.com/saschaludwig)

Thank you for your contributions.
Nothing says better thank you than a donation.

## License
UNLICENSE
Binary file modified bin/firmware.bin
Binary file not shown.
17 changes: 9 additions & 8 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
env_default = nodemcu

[common]
version = -DBUILD_TAG=0.6.0
platform = espressif8266
platform = https://github.com/platformio/platform-espressif8266.git#feature/stage
lib_deps =
ArduinoJson
PubSubClient
ESPAsyncTCP
ESPAsyncUDP
ESP Async WebServer
AsyncMqttClient
Time
MFRC522
ESPAsyncUDP
63
https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino.git

; boards which GPIO0 and RESET controlled using two NPN transistors as nodemcu devkit (includes wemos d1 mini)
Expand All @@ -20,9 +19,10 @@ board_f_cpu = 160000000L
platform = ${common.platform}
framework = arduino
board = esp12e
board_flash_mode = qio
upload_resetmethod = nodemcu
lib_deps = ${common.lib_deps}
build_flags = -Wl,-Teagle.flash.4m.ld
build_flags = -Wl,-Teagle.flash.4m2m.ld
extra_scripts = scripts/pio_script.py
upload_speed = 921600
; Serial Monitor options
Expand All @@ -33,9 +33,10 @@ board_f_cpu = 160000000L
platform = ${common.platform}
framework = arduino
board = esp12e
board_flash_mode = qio
lib_deps = ${common.lib_deps}
extra_scripts = scripts/pio_script.py
build_flags = -Wl,-Teagle.flash.4m.ld
build_flags = -Wl,-Teagle.flash.4m2m.ld
src_build_flags = !echo "-DBUILD_TAG="$TRAVIS_TAG

[env:dout]
Expand All @@ -46,7 +47,7 @@ board = esp12e
board_flash_mode = dout
upload_resetmethod = ck
lib_deps = ${common.lib_deps}
build_flags = -Wl,-Teagle.flash.4m.ld
build_flags = -Wl,-Teagle.flash.4m2m.ld
extra_scripts = scripts/pio_script.py
upload_speed = 921600
; Serial Monitor options
Expand Down
76 changes: 39 additions & 37 deletions src/Ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Ntp.h"
#include <ESPAsyncUDP.h>


char * NtpClient::TimeServerName;
int8_t NtpClient::timezone;
time_t NtpClient::syncInterval;
Expand All @@ -18,9 +19,10 @@ AsyncUDP NtpClient::udpListener;
byte NtpClient::NTPpacket[NTP_PACKET_SIZE];

void ICACHE_FLASH_ATTR NtpClient::Ntp(const char * server, int8_t tz, time_t syncSecs) {
TimeServerName = strdup(server);
TimeServerName = strdup(server);
timezone = tz;
syncInterval = syncSecs;
WiFi.hostByName(TimeServerName, timeServer);
setSyncProvider(getNtpTime);
setSyncInterval(syncInterval);
}
Expand All @@ -32,30 +34,29 @@ ICACHE_FLASH_ATTR NtpClient::~NtpClient() {

// send an NTP request to the time server at the given address
time_t ICACHE_FLASH_ATTR NtpClient::getNtpTime() {
memset(NTPpacket, 0, sizeof(NTPpacket));
NTPpacket[0]=0b11100011;
NTPpacket[1]=0;
NTPpacket[2]=6;
NTPpacket[3]=0xEC;
NTPpacket[12]=49;
NTPpacket[13]=0x4E;
NTPpacket[14]=49;
NTPpacket[15]=52;
WiFi.hostByName(TimeServerName,timeServer);
if(udpListener.connect(timeServer, 123)) {
udpListener.onPacket([](AsyncUDPPacket packet) {
unsigned long highWord = word(packet.data()[40], packet.data()[41]);
unsigned long lowWord = word(packet.data()[42], packet.data()[43]);
time_t UnixUTCtime = (highWord << 16 | lowWord)-2208988800UL;
setTime(UnixUTCtime);
});
}
else {

}
udpListener.write(NTPpacket, sizeof(NTPpacket));
// ugly
return 0;
memset(NTPpacket, 0, sizeof(NTPpacket));
NTPpacket[0] = 0b11100011;
NTPpacket[1] = 0;
NTPpacket[2] = 6;
NTPpacket[3] = 0xEC;
NTPpacket[12] = 49;
NTPpacket[13] = 0x4E;
NTPpacket[14] = 49;
NTPpacket[15] = 52;
if (udpListener.connect(timeServer, 123)) {
udpListener.onPacket([](AsyncUDPPacket packet) {
unsigned long highWord = word(packet.data()[40], packet.data()[41]);
unsigned long lowWord = word(packet.data()[42], packet.data()[43]);
time_t UnixUTCtime = (highWord << 16 | lowWord) - 2208988800UL;
setTime(UnixUTCtime);
});
}
else {

}
udpListener.write(NTPpacket, sizeof(NTPpacket));
// ugly
return 0;
}

bool ICACHE_FLASH_ATTR NtpClient::processTime() {
Expand All @@ -64,11 +65,12 @@ bool ICACHE_FLASH_ATTR NtpClient::processTime() {

switch (ts) {
case timeNeedsSync:
return false;
break;
case timeSet:
return true;
break;
default:
//sync
now();
return false;
}
}
Expand All @@ -87,17 +89,17 @@ String ICACHE_FLASH_ATTR NtpClient::iso8601DateTime() {
String colon = ":";

return String(year()) + hyphen +
zeroPaddedIntVal(month()) + hyphen +
zeroPaddedIntVal(day()) + "T" +
zeroPaddedIntVal(hour()) + colon +
zeroPaddedIntVal(minute()) + colon +
zeroPaddedIntVal(second()) +
(timezone == 0 ? "Z" : String(timezone));
zeroPaddedIntVal(month()) + hyphen +
zeroPaddedIntVal(day()) + "T" +
zeroPaddedIntVal(hour()) + colon +
zeroPaddedIntVal(minute()) + colon +
zeroPaddedIntVal(second()) +
(timezone == 0 ? "Z" : String(timezone));
}

time_t NtpClient::getUptimeSec() {
_uptimesec = _uptimesec + (millis () - _uptimesec);
return _uptimesec / 1000;
return _uptimesec / 1000;
}

deviceUptime ICACHE_FLASH_ATTR NtpClient::getDeviceUptime() {
Expand All @@ -119,9 +121,9 @@ String ICACHE_FLASH_ATTR NtpClient::getDeviceUptimeString() {
deviceUptime uptime = getDeviceUptime();

return String(uptime.days) + " days, " +
String(uptime.hours) + " hours, " +
String(uptime.mins) + " mins, " +
String(uptime.secs) + " secs";
String(uptime.hours) + " hours, " +
String(uptime.mins) + " mins, " +
String(uptime.secs) + " secs";

}

Expand Down

0 comments on commit 4707674

Please sign in to comment.