Skip to content

Commit

Permalink
please see ChangeLog.md
Browse files Browse the repository at this point in the history
  • Loading branch information
omersiar committed Aug 6, 2018
1 parent a7fa3ed commit 9e2f2d3
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ src/websrc/js/required.js
src/websrc/fonts
src/websrc/gzipped

bin/generic.bin
bin/forV2Board.bin

# node js

# Logs
Expand Down
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ install:

script:
- pio --version
- pio run -e deploy
- pio run -e deploy -e relayboard

before_deploy:
- cd ..
- tar -zcf ${TRAVIS_BUILD_DIR}${REPO}-${BUILD_ENV}-${TRAVIS_TAG}.tar.gz ${REPO}/bin

deploy:
provider: releases
api_key:
secure: DVtDvBE9D2FiTxNkACdJoYrQ0ApV+3HwTMUyLOqZu9uJUtbDX1eqlcfaSoIEyTEyKlzDkWpIbkBN9YeHBQ69jAIxvvmnnwJ9iqc9S80BrGaPzGJ7lMPnHm+88OxXHrv7SDVZf9+0Lv59NNyl1vS9euBV2oBHBM7gMb3wz65thWkePsXT4HlksxMjd7F24dYeZ82nVAhUMYuV0vfOu6ySnQlRq5T9ZxLQcXcSLNg80MZOZI6L3Ptd1L7BYizJrV+yoqq2xpTrKiRLJM7YGIWRXIvohuwrIMpCd5GA/m2KySWEU8slXedlRWy5xSkdpWlGKLdIwCxRCaWWWCZDy6Eze4o+O0WVfNsgvXtg6dYOtwsneQrIuTOiZSuWCdjg7v03nKaiX/DkrdiPgyPHCK9dU9yynb4wKQ9kmXgiG/IDvxSltGLTQ2Y9kJtICY2Xqt+vBizr9HZ97es0dPXpopbaCds+zArxcfVu0oMr9e9c1Twwy3K5d941x5ncQ9hzK0JAkN/lbFvNs+uW88Oq//Xaz+FXamkkfydtBJ8LFCW64JVb4iZwWEXc44ihK3iTG1wubsGWma48DvirijtJrltZLyVzVr3fXF+moAw6kBMrHaQOLYKeR2Qbecx+FV4Alh/FY+zpiZ6FTW3ufZExolmLuGsUsGBWqMTNYOlT3hMsgnk=
file_glob: true
file: bin/firmware.bin
file: ${TRAVIS_BUILD_DIR}${REPO}-${BUILD_ENV}-${TRAVIS_TAG}.tar.gz
skip_cleanup: true
on:
repo: omersiar/esp-rfid
all_branches: true
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Change Log
All notable changes to this project will be documented in this file.

## [Unreleased]
## [Unreleased 0.8.0]
#### Added
- [build] Optimize code for official board

#### Fixed
- [firmware] #128 Do not retain MQTT publishes

#### Changed
- [webui] Default wifi type to AP,
- [firmware] MQTT Messages are now plain JSON encoded texts
- [build] flash.bat file now asks which firmware to flash

## [0.7.6] - 2018-07-13
#### Fixed
Expand Down
4 changes: 0 additions & 4 deletions bin/erase.bat

This file was deleted.

Binary file removed bin/firmware.bin
Binary file not shown.
32 changes: 29 additions & 3 deletions bin/flash.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
echo off
@ECHO OFF
cls
set /p com=Enter which COM Port your ESP is connected eg. COM1 COM2 COM7:
esptool.exe -vv -cd nodemcu -cb 921600 -cp %com% -ca 0x00000 -cf firmware.bin

echo - [1] Flash Generic Firmware
echo - [2] Flash Firmware for Official Hardware (v2)
echo - [3] Erase the Firmware on ESP8266 by flashing empty file

set /p opt=Please choose an option eg. 1:

2>NUL CALL :%opt%
IF ERRORLEVEL 1 CALL :DEFAULT_CASE

:1
set /p com=Enter which COM Port your ESP is connected eg. COM1 COM2 COM7:
esptool.exe -vv -cd nodemcu -cb 921600 -cp %com% -ca 0x00000 -cf generic.bin
:2
set /p com=Enter which COM Port your ESP is connected eg. COM1 COM2 COM7:
esptool.exe -vv -cd nodemcu -cb 921600 -cp %com% -ca 0x00000 -cf forV2Board.bin
:3
set /p com=Enter which COM Port your ESP is connected eg. COM1 COM2 COM7:
esptool.exe -vv -cd nodemcu -cb 921600 -cp %com% -ca 0x00000 -cf blank4mb.bin
:DEFAULT_CASE
ECHO Unknown option "%opt%"
GOTO END_CASE
:END_CASE
VER > NUL # reset ERRORLEVEL
GOTO :EOF # return from CALL



24 changes: 19 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[platformio]
env_default = nodemcu
env_default = generic

[common]
platform = https://github.com/platformio/platform-espressif8266.git#feature/stage
Expand All @@ -9,12 +9,13 @@ lib_deps =
ESPAsyncUDP
ESP Async WebServer
AsyncMqttClient
Time
63
MFRC522
EspSoftwareSerial
https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino.git
Time

; boards which GPIO0 and RESET controlled using two NPN transistors as nodemcu devkit (includes wemos d1 mini)
[env:nodemcu]
[env:generic]
lib_ldf_mode = deep+
board_build.f_cpu = 160000000L
platform = ${common.platform}
Expand All @@ -23,7 +24,20 @@ board = esp12e
upload_resetmethod = nodemcu
lib_deps = ${common.lib_deps}
build_flags = -Wl,-Teagle.flash.4m2m.ld
extra_scripts = scripts/pio_script.py
extra_scripts = scripts/GENdeploy.py
upload_speed = 921600
monitor_speed = 115200

[env:relayboard]
lib_ldf_mode = deep+
board_build.f_cpu = 160000000L
platform = ${common.platform}
framework = arduino
board = esp12e
lib_deps = ${common.lib_deps}
build_flags = -Wl,-Teagle.flash.4m.ld
-DOFFICIALBOARD
extra_scripts = scripts/OBdeploy.py
upload_speed = 921600
monitor_speed = 115200

Expand Down
4 changes: 2 additions & 2 deletions scripts/pio_script.py → scripts/GENdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import os
#
# Dump build environment (for debug)
#print env.Dump()
# print env.Dump()
#

#
# Upload actions
#

def after_build(source, target, env):
shutil.copy(firmware_source, 'bin/firmware.bin')
shutil.copy(firmware_source, 'bin/generic.bin')

env.AddPostAction("buildprog", after_build)

Expand Down
18 changes: 18 additions & 0 deletions scripts/OBdeploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Import("env")
import shutil
import os
#
# Dump build environment (for debug)
# print env.Dump()
#

#
# Upload actions
#

def after_build(source, target, env):
shutil.copy(firmware_source, 'bin/forV2Board.bin')

env.AddPostAction("buildprog", after_build)

firmware_source = os.path.join(env.subst("$BUILD_DIR"), "firmware.bin")
3 changes: 2 additions & 1 deletion src/PN532.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef OFFICIALBOARD
/**************************************************************************
@file PN532.cpp
@author Adafruit Industries, Elmü
Expand Down Expand Up @@ -1019,4 +1020,4 @@ byte PN532::SpiRead(void)
#endif
}


#endif
72 changes: 54 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,32 @@
*/

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <ESP8266mDNS.h>
#include <MFRC522.h>
#include <Wiegand.h>
#include <ArduinoJson.h>
#include <FS.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <TimeLib.h>
// #include <TimeLib.h>
#include <Ticker.h>

#include <Ntp.h>
#include <PN532.h>
#include <AsyncMqttClient.h>
#include <SoftwareSerial.h>

// RFID Hardware Libraries

#ifdef OFFICIALBOARD
#include <Wiegand.h>
#endif

#ifndef OFFICIALBOARD
#include <MFRC522.h>
#include <PN532.h>
#include <Wiegand.h>
#endif



// these are from vendors
#include "webh/glyphicons-halflings-regular.woff.gz.h"
Expand All @@ -50,19 +60,22 @@ extern "C" {

// #define DEBUG

#ifdef OFFICIALBOARD
// Create instance for Wiegand reade
WIEGAND wg;
#endif

#ifndef OFFICIALBOARD
// Create MFRC522 RFID instance
MFRC522 mfrc522 = MFRC522();

PN532 pn532;

NtpClient NTP;
WIEGAND wg;
#endif

NtpClient NTP;
AsyncMqttClient mqttClient;

Ticker mqttReconnectTimer;

WiFiEventHandler wifiDisconnectHandler;

// Create AsyncWebServer instance on port "80"
Expand All @@ -71,7 +84,6 @@ AsyncWebServer server(80);
AsyncWebSocket ws("/ws");



// Variables for whole scope
const char * http_username = "admin";
char *http_pass = NULL;
Expand Down Expand Up @@ -464,6 +476,7 @@ void ICACHE_FLASH_ATTR rfidloop() {

String uid = "";
String type = "";
#ifndef OFFICIALBOARD

// This way of constantly checking the reader type is simply not how it should be.. but leave it for now
if (readerType == 0) {
Expand Down Expand Up @@ -495,7 +508,8 @@ void ICACHE_FLASH_ATTR rfidloop() {
Serial.print(" " + type);


} else if (readerType == 1) {
}
else if (readerType == 1) {
if (wg.available()) {
Serial.print(F("[ INFO ] PICC's UID: "));
Serial.println(wg.getCode());
Expand All @@ -505,7 +519,8 @@ void ICACHE_FLASH_ATTR rfidloop() {
} else {
return;
}
} else if (readerType == 2) {
}
else if (readerType == 2) {
bool found = false;
byte pnuid[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
eCardType e_CardType;
Expand All @@ -530,9 +545,21 @@ void ICACHE_FLASH_ATTR rfidloop() {
delay(50);
return;
}
#endif
#ifdef OFFICIALBOARD
if (wg.available()) {
Serial.print(F("[ INFO ] PICC's UID: "));
Serial.println(wg.getCode());
uid = String(wg.getCode(), HEX);
type = String(wg.getWiegandType(), HEX);
cooldown = millis() + 2000;
} else {
return;
}
#endif
if (mqttenabled == 1) {
const char * topic = mqttTopic;
mqttClient.publish(topic, 0, true, uid.c_str());
mqttClient.publish(topic, 0, false, uid.c_str());
}

// We are going to use filesystem to store known UIDs.
Expand Down Expand Up @@ -594,7 +621,7 @@ void ICACHE_FLASH_ATTR rfidloop() {
}
if (mqttenabled == 1) {
const char * topic = mqttTopic;
mqttClient.publish(topic, 0, true, username.c_str());
mqttClient.publish(topic, 0, false, username.c_str());
}
writeLatest(uid, username, AccType);
// Also inform Administrator Portal
Expand Down Expand Up @@ -651,6 +678,7 @@ void ICACHE_FLASH_ATTR rfidloop() {
// So far got we got UID of Scanned RFID Tag, checked it if it's on the database and access status, informed Administrator Portal
}

#ifndef OFFICIALBOARD
#ifdef DEBUG
void ICACHE_FLASH_ATTR ShowMFRC522ReaderDetails() {
// Get the MFRC522 software version
Expand All @@ -673,11 +701,14 @@ void ICACHE_FLASH_ATTR ShowMFRC522ReaderDetails() {
}
}
#endif
#endif


void ICACHE_FLASH_ATTR setupWiegandReader(int d0, int d1) {
wg.begin(d0, d1);
}

#ifndef OFFICIALBOARD
// Configure RFID Hardware
void ICACHE_FLASH_ATTR setupMFRC522Reader(int rfidss, int rfidgain) {
SPI.begin(); // MFRC522 Hardware uses SPI protocol
Expand All @@ -693,8 +724,9 @@ void ICACHE_FLASH_ATTR setupMFRC522Reader(int rfidss, int rfidgain) {
ShowMFRC522ReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
#endif
}
#endif


#ifndef OFFICIALBOARD
void ICACHE_FLASH_ATTR setupPN532Reader(int rfidss) {
// init controller
pn532.InitSoftwareSPI(14, 12, 13, rfidss, 0);
Expand Down Expand Up @@ -728,6 +760,7 @@ void ICACHE_FLASH_ATTR setupPN532Reader(int rfidss) {
}
while (false);
}
#endif



Expand Down Expand Up @@ -894,7 +927,7 @@ void onMqttPublish(uint16_t packetId) {

void onMqttConnect(bool sessionPresent) {
Serial.println("MQTT Connected session");
uint16_t packetIdPub1 = mqttClient.publish("test/lol", 1, true, "test 2");
uint16_t packetIdPub1 = mqttClient.publish("test/lol", 1, false, "test 2");
if (sessionPresent == true) {
Serial.println("MQTT Connected session");
writeEvent("INFO", "mqtt", "Connected to MQTT Server", "Session Present");
Expand Down Expand Up @@ -935,6 +968,8 @@ bool ICACHE_FLASH_ATTR loadConfiguration() {
#ifdef DEBUG
Serial.print(F("[ INFO ] Trying to setup RFID Hardware :"));
#endif

#ifndef OFFICIALBOARD
readerType = hardware["readerType"];

if ( readerType == 1 ) {
Expand All @@ -952,7 +987,8 @@ bool ICACHE_FLASH_ATTR loadConfiguration() {
rfidss = hardware["sspin"];
setupPN532Reader(rfidss);
}

#endif

autoRestartIntervalSeconds = general["restart"];
wifiTimeout = network["offtime"];

Expand Down
Loading

0 comments on commit 9e2f2d3

Please sign in to comment.