RFID Access control / door lock actuator

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: RFID Access control / door lock actuator

#31 Post by tozett » 28 Apr 2017, 11:44

from wiegand 26 to 34 should not be a really big problem,
but i think its up to the coder/developer to expand the existing code.

martinus was very quick in the past to do such things,
dont know if the actual developer can help you.

as i am no coder, i regret i cannot help, but if i could code perfectly enough i would have done this.
maybe you can lookup the code-enhancement yourself?

sm0k0
Normal user
Posts: 16
Joined: 24 Sep 2016, 10:41

Re: RFID Access control / door lock actuator

#32 Post by sm0k0 » 29 Apr 2017, 08:56

Thanks tozett.

In the meatime i have checked the devel branch, recompiled the FW but same result. I stepped back to the signal itself and it looks like the problem is not the Software but the falling edge is "too small" to get recognized by ESP.
Image2.png
Image2.png (3.88 KiB) Viewed 34656 times
Once i have connected the Reader via the level shifter, no falling edge is seen at all. :(

As longer i think about this as more i get the impression that it cannot work that way. The ESPEasy RFID implementation (_P008_RFID.ino) says INPUT_PULLUP on GPIO`s where D0/D1 is connected and FALLING for detecting the interrupt. That results in both pins are at 3.3v in "idle" operations.

So, from my little, screwed german brain : Both datapins are hooked up with 3.3v and as an Input i have another 3.3v coming in idle state from the Reader. Now, the reader pulls down voltage for initiating sequence and sending data by pulling up/down voltage. :geek:
But what about the hooked up ESP Pins ? They are still equipped with 3.3v (even if they are defined as INPUT) so treated as HIGH and therefore there is no change and falling edge and they stay logical 1 whatever you're doing at the readers side ... HäH ?? :shock:

I searched around the Web and did not find any real working solution for Wiegand@ESP so next steps would be to dig into making the signal "visible" to the ESP. Will try to make a "real" level shifter which is pulling ESP D0/D1 to ground in case of a falling edge. Will come back for report afterwards.

Have a good weekend & regards
sm0k0

sm0k0
Normal user
Posts: 16
Joined: 24 Sep 2016, 10:41

Re: RFID Access control / door lock actuator

#33 Post by sm0k0 » 29 Apr 2017, 13:06

Hi again,

a appropriate LVL shifter and changing #define PLUGIN_008_WGSIZE to "34" does the trick

this is working like a charm. :mrgreen:
wiegand_2_EPS8266_LVL_Shifter.png
wiegand_2_EPS8266_LVL_Shifter.png (7.7 KiB) Viewed 34642 times
wemos-wiegand34 (Small).jpg
wemos-wiegand34 (Small).jpg (113.15 KiB) Viewed 34642 times
wiegand_2_EPS8266_LVL_Software.png
wiegand_2_EPS8266_LVL_Software.png (18.5 KiB) Viewed 34642 times
best regards
sm0k0

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: RFID Access control / door lock actuator

#34 Post by tozett » 30 Apr 2017, 13:45

I use my reader without a level shifter, esp can handle 5v,
I documentated this here in the forum somewhere

May you try this also to simplify electronics...

sm0k0
Normal user
Posts: 16
Joined: 24 Sep 2016, 10:41

Re: RFID Access control / door lock actuator

#35 Post by sm0k0 » 30 Apr 2017, 16:19

thanks tozett.

:shock:

what i have seen on that device, there is a lot of noise on it in general so a LVL shifter is not a bad idea.
From what is telling Espressif, ESP8266 is not 5v tolerant, on some china bombers it might work, on some it doesn't. Depends on the delivering circuit, the current, breakdown of the voltage and what your pull ups are eating. So youre lucky that you might have a "dirty" board and your device is still operating. :mrgreen:

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: RFID Access control / door lock actuator

#36 Post by tozett » 01 May 2017, 08:08

your level shifter looks good (mine was confusing to use),
does the oszi show a better signal after shifting? do you made a screenshot?

esp is 5v tolerant as i found here: https://www.letscontrolit.com/forum/vie ... evel#p8713
so your shifter is more to straighten the signal for your reader than to shift.

gratulations, everthings looks proper and is working perfect! ;)

(and thanks for the images, wonderful to see something!)

sm0k0
Normal user
Posts: 16
Joined: 24 Sep 2016, 10:41

Re: RFID Access control / door lock actuator

#37 Post by sm0k0 » 01 May 2017, 09:05

Hi tozett,

scale has been changed of course but signal looks ok, noisy but ok.
Image1.png
Image1.png (3.34 KiB) Viewed 34577 times

CCameron
New user
Posts: 7
Joined: 03 May 2017, 22:32

Re: RFID Access control / door lock actuator

#38 Post by CCameron » 08 Nov 2017, 23:59

Does anyone know if I would be able to use arduino on anything on this list: https://unitedlocksmith.net/blog/8-best ... door-locks

Trying to anticipate mods before I buy.

mghaff007
New user
Posts: 4
Joined: 22 Dec 2017, 02:21

Re: RFID Access control / door lock actuator

#39 Post by mghaff007 » 22 Dec 2017, 02:45

I am new to posting my problems on-line, I usually like to figure them out my self.... but i don't have a great deal of experience with coding so i have been learning ALOT. so any help is greatly appreciated!!! :D I am trying to get this code to compile in order to upload it to my esp8266. and i keep getting compiler errors. Seems to be with the PubSubClient. HELP PLEASE.



Arduino: 1.8.4 (Linux), Board: "WeMos D1 R2 & mini, 80 MHz, 921600, 4M (3M SPIFFS)"

ESPEasyRFID:140: error: no matching function for call to 'PubSubClient::PubSubClient(const char [1])'
PubSubClient MQTTclient("");
^
/home/mark/Downloads/ESPEasyRFID/ESPEasyRFID.ino:140:27: note: candidates are:
In file included from /home/mark/Downloads/ESPEasyRFID/ESPEasyRFID.ino:135:0:
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:116:4: note: PubSubClient::PubSubClient(const char*, uint16_t, std::function<void(char*, unsigned char*, unsigned int)>, Client&, Stream&)
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:116:4: note: candidate expects 5 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:115:4: note: PubSubClient::PubSubClient(const char*, uint16_t, std::function<void(char*, unsigned char*, unsigned int)>, Client&)
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:115:4: note: candidate expects 4 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:114:4: note: PubSubClient::PubSubClient(const char*, uint16_t, Client&, Stream&)
PubSubClient(const char*, uint16_t, Client& client, Stream&);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:114:4: note: candidate expects 4 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:113:4: note: PubSubClient::PubSubClient(const char*, uint16_t, Client&)
PubSubClient(const char*, uint16_t, Client& client);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:113:4: note: candidate expects 3 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:112:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, std::function<void(char*, unsigned char*, unsigned int)>, Client&, Stream&)
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:112:4: note: candidate expects 5 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:111:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, std::function<void(char*, unsigned char*, unsigned int)>, Client&)
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:111:4: note: candidate expects 4 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:110:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, Client&, Stream&)
PubSubClient(uint8_t *, uint16_t, Client& client, Stream&);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:110:4: note: candidate expects 4 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:109:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, Client&)
PubSubClient(uint8_t *, uint16_t, Client& client);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:109:4: note: candidate expects 3 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:108:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, std::function<void(char*, unsigned char*, unsigned int)>, Client&, Stream&)
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:108:4: note: candidate expects 5 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:107:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, std::function<void(char*, unsigned char*, unsigned int)>, Client&)
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:107:4: note: candidate expects 4 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:106:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, Client&, Stream&)
PubSubClient(IPAddress, uint16_t, Client& client, Stream&);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:106:4: note: candidate expects 4 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:105:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, Client&)
PubSubClient(IPAddress, uint16_t, Client& client);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:105:4: note: candidate expects 3 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:104:4: note: PubSubClient::PubSubClient(Client&)
PubSubClient(Client& client);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:104:4: note: no known conversion for argument 1 from 'const char [1]' to 'Client&'
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:103:4: note: PubSubClient::PubSubClient()
PubSubClient();
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:103:4: note: candidate expects 0 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:83:7: note: PubSubClient::PubSubClient(const PubSubClient&)
class PubSubClient {
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:83:7: note: no known conversion for argument 1 from 'const char [1]' to 'const PubSubClient&'
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:83:7: note: PubSubClient::PubSubClient(PubSubClient&&)
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:83:7: note: no known conversion for argument 1 from 'const char [1]' to 'PubSubClient&&'
Controller:298: error: 'MQTT' does not name a type
void callback(const MQTT::Publish& pub) {
^
Controller:298: error: expected unqualified-id before '&' token
void callback(const MQTT::Publish& pub) {
^
Controller:298: error: expected ')' before '&' token
Controller:298: error: expected initializer before 'pub'
void callback(const MQTT::Publish& pub) {
^
Controller:298: error: 'MQTT' does not name a type
void callback(const MQTT::Publish& pub) {
^
Controller:298: error: expected unqualified-id before '&' token
void callback(const MQTT::Publish& pub) {
^
Controller:298: error: expected ')' before '&' token
Controller:298: error: expected initializer before 'pub'
void callback(const MQTT::Publish& pub) {
^
/home/mark/Downloads/ESPEasyRFID/Controller.ino: In function 'void MQTTConnect()':
Controller:310: error: 'class PubSubClient' has no member named 'set_server'
MQTTclient.set_server(MQTTBrokerIP, 1883);
^
Controller:311: error: 'class PubSubClient' has no member named 'set_callback'
MQTTclient.set_callback(callback);
^
Controller:311: error: 'callback' was not declared in this scope
MQTTclient.set_callback(callback);
^
Controller:319: error: no matching function for call to 'PubSubClient::connect(String&)'
if (MQTTclient.connect(clientid))
^
/home/mark/Downloads/ESPEasyRFID/Controller.ino:319:36: note: candidates are:
In file included from /home/mark/Downloads/ESPEasyRFID/ESPEasyRFID.ino:135:0:
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:125:12: note: boolean PubSubClient::connect(const char*)
boolean connect(const char* id);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:125:12: note: no known conversion for argument 1 from 'String' to 'const char*'
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:126:12: note: boolean PubSubClient::connect(const char*, const char*, const char*)
boolean connect(const char* id, const char* user, const char* pass);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:126:12: note: candidate expects 3 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:127:12: note: boolean PubSubClient::connect(const char*, const char*, uint8_t, boolean, const char*)
boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:127:12: note: candidate expects 5 arguments, 1 provided
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:128:12: note: boolean PubSubClient::connect(const char*, const char*, const char*, const char*, uint8_t, boolean, const char*)
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
^
/home/mark/Arduino/libraries/pubsubclient/src/PubSubClient.h:128:12: note: candidate expects 7 arguments, 1 provided
Multiple libraries were found for "LiquidCrystal_I2C.h"
Used: /home/mark/Arduino/libraries/LiquidCrystal_I2C
Not used: /home/mark/Downloads/arduino-1.8.4/libraries/LiquidCrystal_I2C
Multiple libraries were found for "PubSubClient.h"
Used: /home/mark/Arduino/libraries/pubsubclient
Not used: /home/mark/Arduino/libraries/PubSubClient
Not used: /home/mark/Downloads/arduino-1.8.4/libraries/pubsubclient

no matching function for call to 'PubSubClient::PubSubClient(const char [1])'

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: RFID Access control / door lock actuator

#40 Post by vader » 22 Dec 2017, 12:20

No compiling issues so far. Try Arduino 1.8.5 and 1M SPIFFS setting.

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: RFID Access control / door lock actuator

#41 Post by papperone » 22 Dec 2017, 12:47

I think you miss some libraries (at least the PubSub related to MQTT) in order to be able to compile ESPEasy...
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

mghaff007
New user
Posts: 4
Joined: 22 Dec 2017, 02:21

Re: RFID Access control / door lock actuator

#42 Post by mghaff007 » 22 Dec 2017, 21:06

/****************************************************************************************************************************\
* Arduino project "ESP Easy" © Copyright www.esp8266.nu
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You received a copy of the GNU General Public License along with this program in file 'License.txt'.
*
* IDE download : https://www.arduino.cc/en/Main/Software
* ESP8266 Package : https://github.com/esp8266/Arduino
*
* Source Code : https://sourceforge.net/projects/espeasy/
* Support : http://www.esp8266.nu
* Discussion : http://www.esp8266.nu/forum/
*
* Additional information about licensing can be found at : http://www.gnu.org/licenses
\*************************************************************************************************************************/

// This file incorporates work covered by the following copyright and permission notice:

/****************************************************************************************************************************\
* Arduino project "Nodo" © Copyright 2010..2015 Paul Tonkes
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You received a copy of the GNU General Public License along with this program in file 'License.txt'.
*
* Voor toelichting op de licentievoorwaarden zie : http://www.gnu.org/licenses
* Uitgebreide documentatie is te vinden op : http://www.nodo-domotica.nl
* Compiler voor deze programmacode te downloaden op : http://arduino.cc
\*************************************************************************************************************************/

// Simple Arduino sketch for ESP module, supporting:
// Dallas OneWire DS18b20 temperature sensors
// DHT11/22 humidity sensors
// BH1750 I2C Lux sensor
// BMP085 I2C Barometric Pressure sensor
// RFID Wiegand-26 reader
// MCP23017 I2C IO Expanders
// Analog input (ESP-7/12 only)
// LCD I2C display 4x20 chars
// Pulse counters
// Simple switch inputs
// Direct GPIO output control to drive relais, mosfets, etc

// ********************************************************************************
// User specific configuration
// ********************************************************************************

// Set default configuration settings if you want (not mandatory)
// You can allways change these during runtime and save to eeprom
// After loading firmware, issue a 'reset' command to load the defaults.

#define DEFAULT_NAME "" // Enter your device friendly name
#define DEFAULT_SSID "" // Enter your network SSID
#define DEFAULT_KEY "" // Enter your network WPA key
#define DEFAULT_SERVER "192.168.1.0" // Enter your Domoticz Server IP address
#define DEFAULT_PORT 8080 // Enter your Domoticz Server port value
#define DEFAULT_DELAY 60 // Enter your Send delay in seconds
#define DEFAULT_AP_KEY "configesp" // Enter network WPA key for AP (config) mode
#define DEFAULT_PROTOCOL 1 // Protocol used for controller communications
// 1 = Domoticz HTTP
// 2 = Domoticz MQTT
// 3 = Nodo Telnet
#define UNIT 0

#define KEYS_MAX 8
#define KEY1 1
#define KEY2 2345678
#define KEY3 3456789
#define KEY4 4567890
#define KEY5 1234567
#define KEY6 2345678
#define KEY7 3456789
#define KEY8 4567890
#define BUZZERPIN 5
#define BUZZERSHORTDELAY 200
#define BUZZERLONGDELAY 500
#define BUZZERPULSES 3
#define DOORPIN 14
#define DOORSHORTDELAY 100
#define DOORLONGDELAY 200
#define DOORPULSES 20

// ********************************************************************************
// DO NOT CHANGE ANYTHING BELOW THIS LINE
// ********************************************************************************

// sensor types
// 1 = single value, general purpose (Dallas, LUX, counters, etc)
// 2 = temp + hum (DHT)
// 3 = temp + hum + baro (BMP085)
// 10 = switch

#define ESP_PROJECT_PID 2015050101L
#define ESP_EASY
#define VERSION 4
#define BUILD 15
#define REBOOT_ON_MAX_CONNECTION_FAILURES 30

#define LOG_LEVEL_ERROR 1
#define LOG_LEVEL_INFO 2
#define LOG_LEVEL_DEBUG 3
#define LOG_LEVEL_DEBUG_MORE 4

#define CMD_REBOOT 89
#define CMD_WIFI_DISCONNECT 135

#define DEVICE_DS18B20 1
#define DEVICE_DHT11 2
#define DEVICE_DHT22 3
#define DEVICE_BMP085 4
#define DEVICE_BH1750 5
#define DEVICE_ANALOG 6
#define DEVICE_RFID 7
#define DEVICE_PULSE 8
#define DEVICE_SWITCH 9

#define DEVICES_MAX 10
#define TASKS_MAX 8

#define DEVICE_TYPE_SINGLE 1 // connected through 1 datapin
#define DEVICE_TYPE_I2C 2 // connected through I2C
#define DEVICE_TYPE_ANALOG 3 // tout pin
#define DEVICE_TYPE_DUAL 4 // connected through 2 datapins

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <Wire.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <LiquidCrystal_I2C.h>

// MQTT client
PubSubClient MQTTclient("");

// LCD
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display

// WebServer
ESP8266WebServer WebServer(80);

// syslog stuff
WiFiUDP portRX;
WiFiUDP portTX;

struct SettingsStruct
{
unsigned long PID;
int Version;
byte Unit;
char WifiSSID[26];
char WifiKey[26];
byte Controller_IP[4];
unsigned int ControllerPort;
byte IP_Octet;
char WifiAPKey[26];
unsigned long Delay;
unsigned int _Dallas;
unsigned int _DHT;
byte _DHTType;
unsigned int _BMP;
unsigned int _LUX;
unsigned int _RFID;
unsigned int _Analog;
unsigned int _Pulse1;
byte _BoardType;
int8_t Pin_i2c_sda;
int8_t Pin_i2c_scl;
int8_t _Pin_wired_in_1;
int8_t _Pin_wired_in_2;
int8_t _Pin_wired_out_1;
int8_t _Pin_wired_out_2;
byte Syslog_IP[4];
unsigned int UDPPort;
unsigned int Switch1;
byte Protocol;
byte IP[4];
byte Gateway[4];
byte Subnet[4];
byte Debug;
char Name[26];
byte SyslogLevel;
byte SerialLogLevel;
byte WebLogLevel;
unsigned long BaudRate;
char ControllerUser[26];
char ControllerPassword[26];
char Password[26];
unsigned long MessageDelay;
byte TaskDeviceNumber[TASKS_MAX];
unsigned int TaskDeviceID[TASKS_MAX];
int8_t TaskDevicePin1[TASKS_MAX];
int8_t TaskDevicePin2[TASKS_MAX];
int Keys[KEYS_MAX];
int buzzerPin;
int buzzerShortDelay;
int buzzerLongDelay;
int buzzerPulses;
int doorPin;
int doorShortDelay;
int doorLongDelay;
int doorPulses;

} Settings;

struct LogStruct
{
unsigned long timeStamp;
char Message[80];
} Logging[10];
int logcount = -1;

struct DeviceStruct
{
byte Number;
char Name[26];
byte Type;
} Device[DEVICES_MAX];

boolean printToWeb = false;
String printWebString = "";

float UserVar[2 * TASKS_MAX];
unsigned long pulseCounter[TASKS_MAX];
unsigned long pulseTotalCounter[TASKS_MAX];
byte switchstate[TASKS_MAX];

unsigned long timer;
unsigned long timer100ms;
unsigned long timer1s;
unsigned long timerwd;
unsigned int NC_Count = 0;
unsigned int C_Count = 0;
boolean AP_Mode = false;
byte cmd_within_mainloop = 0;
unsigned long connectionFailures;
unsigned long wdcounter = 0;

unsigned long pulseCounter1 = 0;
byte switch1state = 0;

boolean WebLoggedIn = false;
int WebLoggedInTimer = 300;


void setup()
{
EEPROM.begin(1024);

LoadSettings();
// if different version, eeprom settings structure has changed. Full Reset needed
// on a fresh ESP module eeprom values are set to 255. Version results into -1 (signed int)
if (Settings.Version != VERSION || Settings.PID != ESP_PROJECT_PID)
{
Serial.begin(9600); // Initialiseer de seriele poort
Serial.println(Settings.PID);
Serial.println(Settings.Version);
Serial.println(F("INIT : Incorrect PID or version!"));
delay(10000);
ResetFactory();
}

Serial.begin(Settings.BaudRate);
Serial.print(F("\nINIT : Booting Build nr:"));
Serial.println(BUILD);

if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE)
Serial.setDebugOutput(true);

Device_Init();
hardwareInit();

WifiAPconfig();
WifiConnect();

WebServerInit();

// setup UDP
if (Settings.UDPPort != 0)
portRX.begin(Settings.UDPPort);

// Setup timers
timer = millis() + 30000; // startup delay 30 sec
timer100ms = millis() + 100; // timer for periodic actions 10 x per/sec
timer1s = millis() + 1000; // timer for periodic actions once per/sec
timerwd = millis() + 30000; // timer for watchdog once per 30 sec

// Setup LCD display
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.print("ESP Easy");

// Setup MQTT Client
if (Settings.Protocol == 2)
MQTTConnect();

sendSysInfoUDP(3);
Serial.println(F("INIT : Boot OK"));
addLog(LOG_LEVEL_INFO,(char*)"Boot");
}

void loop()
{
if (Serial.available())
serial();

checkUDP();


if (cmd_within_mainloop != 0)
{
switch (cmd_within_mainloop)
{
case CMD_WIFI_DISCONNECT:
{
WifiDisconnect();
break;
}
case CMD_REBOOT:
{
ESP.reset();
break;
}
}
cmd_within_mainloop = 0;
}

// Watchdog trigger
if (millis() > timerwd)
{
wdcounter++;
timerwd = millis() + 30000;
char str[40];
str[0] = 0;
Serial.print("WD : ");
sprintf_P(str, PSTR("Uptime %u ConnectFailures %u FreeMem %u"), wdcounter / 2, connectionFailures, FreeMem());
Serial.println(str);
syslog(str);
sendSysInfoUDP(1);
refreshNodeList();
}

// Perform regular checks, 10 times/sec
if (millis() > timer100ms)
{
timer100ms = millis() + 100;
inputCheck();
}

// Perform regular checks, 1 time/sec
if (millis() > timer1s)
{
timer1s = millis() + 1000;
WifiCheck();

if (Settings.Password[0] != 0)
{
if (WebLoggedIn)
WebLoggedInTimer++;
if (WebLoggedInTimer > 300)
WebLoggedIn = false;
}
}

// Check sensors and send data to controller when sensor timer has elapsed
if (millis() > timer)
{
timer = millis() + Settings.Delay * 1000;
SensorSend();
}

if (connectionFailures > REBOOT_ON_MAX_CONNECTION_FAILURES)
{
Serial.println(F("Too many connection failures"));
delayedReboot(60);
}

backgroundtasks();

}

void inputCheck()
{
// Handle switches
for (byte x=0; x < TASKS_MAX; x++)
{
if(Settings.TaskDeviceNumber[x] == DEVICE_SWITCH && Settings.TaskDeviceID[x] != 0)
{
byte state = digitalRead(Settings.TaskDevicePin1[x]);
if (state != switchstate[x])
{
switchstate[x] = state;
UserVar[(x*2+1) - 1] = state;
sendData(10, Settings.TaskDeviceID[x], x*2+1);
delay(100);
}
}
}

// Handle rfid
boolean granted = false;
for (byte x=0; x < TASKS_MAX; x++)
{
if(Settings.TaskDeviceNumber[x] == DEVICE_RFID && Settings.TaskDeviceID[x] != 0)
{
unsigned long rfid_id = rfid();
if (rfid_id > 0)
{
Serial.print("RFID : Tag : ");
Serial.println(rfid_id);
UserVar[(x*2+1) - 1] = rfid_id;
sendData(1, Settings.TaskDeviceID[x], x*2+1);
for (byte x=0; x < KEYS_MAX;x++){
if (Settings.Keys[x]==rfid_id)
{
granted = true;
x = KEYS_MAX;
}
}
if(granted){
sendPulse(Settings.doorPin, Settings.doorShortDelay, Settings.doorLongDelay, Settings.doorPulses);
Serial.println("Key Accepted");
}else{
sendPulse(Settings.buzzerPin, Settings.buzzerShortDelay, Settings.buzzerLongDelay, Settings.buzzerPulses);
Serial.println("Key declined");
}
}
}
}
}

void SensorSend()
{
for (byte x=0; x < TASKS_MAX; x++)
{
if (Settings.TaskDeviceID[x] != 0)
{
switch(Settings.TaskDeviceNumber[x])
{
case DEVICE_DS18B20:
dallas(Settings.TaskDevicePin1[x], x*2+1);
sendData(1, Settings.TaskDeviceID[x], x*2+1);
break;

case DEVICE_DHT11:
dht(11, Settings.TaskDevicePin1[x], x*2+1);
if (!isnan(UserVar[(x*2+1) - 1]) && (UserVar[(x*2+2) - 1] > 0))
sendData(2,Settings.TaskDeviceID[x], x*2+1);
break;

case DEVICE_DHT22:
dht(22, Settings.TaskDevicePin1[x], x*2+1);
if (!isnan(UserVar[(x*2+1) - 1]) && (UserVar[(x*2+2) - 1] > 0))
sendData(2, Settings.TaskDeviceID[x], x*2+1);
break;

case DEVICE_BMP085:
bmp085(x*2+1);
if ((UserVar[(x*2+2) - 1] >= 300) && (UserVar[(x*2+2) - 1] <= 1100))
sendData(3, Settings.TaskDeviceID[x], x*2+1);
break;

case DEVICE_BH1750:
lux(x*2+1); // read BH1750 LUX sensor and store to var 6
sendData(1, Settings.TaskDeviceID[x], x*2+1);
break;

case DEVICE_ANALOG:
analog(x*2+1); // read ADC and store to var 7
sendData(1, Settings.TaskDeviceID[x], x*2+1);
break;

case DEVICE_PULSE:
UserVar[(x*2+1) - 1] = pulseCounter[x];
sendData(1, Settings.TaskDeviceID[x], x*2+1);
pulseCounter[x] = 0;
break;
}
}
}
}

void backgroundtasks()
{
WebServer.handleClient();
MQTTclient.loop();
delay(10);
}

mghaff007
New user
Posts: 4
Joined: 22 Dec 2017, 02:21

Re: RFID Access control / door lock actuator

#43 Post by mghaff007 » 22 Dec 2017, 21:11

I checked and i do have the PubSubClient Version 2.6.0 on arduino 1.8.5 Installed... what am i missing????? Thanks in advance!!!

UPDATE:

Alright so i found a workaround just using ESPeasy rules. for what i needed it to do it works just fine! Thanks for the insight.

Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests