For your purpose, here is the code I've decided to make opensource with credits, as I found someone was stealing my codes and ideas for commercial purpose and made a good amount of money too...
It was the first kind of cloud type thing, which sends polling data, and also posts into SQL directly via a php script. It's hugely used in my hotel for in-out reporting and i tried to implement it in a school and the vendor stolen it and made his money. (I was given the task of development by a brigadier general who was transferred and new admin appointed new vendor and new vendor cheated).
The device serial generation is not quite good here and in my another project I corrected that. the library bdneteeprom2.h is basically a modified version of neteeprom2.h.
/*
* Target Hardware: mega2560
*
* Target Network module W5500
*
* The system uses Weigand 26 and readers are supporting both. Thus it needsproper selection via reader's pins
* for ARDUINO MEGA2560 :
* Reader 1 :
* DATA0 of Wiegand connects to Arduino PIN 2
* DATA1 of Wiegand connects to Arduino PIN 3
* Reader 2 :
* DATA0 of Wiegand connects to Arduino PIN 21
* DATA1 of Wiegand connects to Arduino PIN 20
* Reader 3 :
* DATA0 of Wiegand connects to Arduino PIN 19
* DATA1 of Wiegand connects to Arduino PIN 18
*
* LED is to be pulled down for turning green. Buzzer sounds when pushed hi.
* For both LED and buzzer, we may use smart delay, which is a logical delay (but not code execution halt) so that system
* will get enough time to post in server.
*
* The system will send keepalive every after 3 mins.
* The ystem will reboot itself every after 2 hours and few mre seconds.
* The system is enabled with a watchdog timer of 8s. Make sure to use the reset watchdog in proper locations.
*
* EEPROM MAP, each address has 1 byte storage.
*
* The below address map is available in BDNetEEPROM library
* * DEFAULT eepromOffset = 0 [Address 0]
* #define MAC_OFFSET (eepromOffset + 1) [Start at 0+1=1, used for MAC (6byte), ends at 6]
* #define DHCP_OFFSET (MAC_OFFSET + 6) [Start at 1+6=7, used for DHCP config (1byte), ends at 7]
* #define IP_OFFSET (DHCP_OFFSET + 1) [Start at 7+1=8, used for IP config (4byte), ends at 11]
* #define DNS_OFFSET (IP_OFFSET + 4) [Start at 11+4=15, used for DNS config (4byte), ends at 18]
* #define GW_OFFSET (DNS_OFFSET + 4) [Start at 18+4=22, used for Gateway config (4byte), ends at 25]
* #define SUBNET_OFFSET (GW_OFFSET + 4) [Start at 25+4=29, used for Subnet config (4byte), ends at 32]
*
* Anything else is to be used from Address 33 and onwards. [Aka. ADDR 0-32 RESERVED for NETWORK CONFIG]
* Maxthhere has been considered as 100 bytes.
* #define WIEGAND_OFFSET (33) [Start at 33, used for WIEGAND config (1byte), ends at 33]
* #define REBOOT_OFFSET (WIEGAND_OFFSET + 1) [Start at 33+1=34, used for REBOOT_OFFSET (1byte), ends at 34]
* #define KEEPALIVE_OFFSET (REBOOT_OFFSET + 1) [Start at 34+1=35, used for KEEPALIVE_OFFSET (1byte), ends at 35]
* #define SERVER_ADDR_SIZE (WIEGAND_OFFSET + 1) [Start at 35+1=36, used for SERVER_ADDR_SIZE (1byte), ends at 36]
* #define SERVER_ADDR_OFFSET (SERVER_ADDR_SIZE + 1) [Start at 36+1=37, used for SERVER_ADDR_OFFSET (100byte including NULL Char), ends at 137]
* #define NEXT_STR_SIZE (SERVER_ADDR_OFFSET + 100) [Start at 35+100=135, used for NEXT_STR_SIZE (1byte), ends at 136]
* #define NEXT_STR_OFFSET (NEXT_STR_SIZE + 1) [Start at 137+1=138, used for NEXT_STR_OFFSET (100byte including NULL Char), ends at 238]
*
*
*/
#include <SPI.h>
#include <Ethernet2.h>
#include <EEPROM.h>
#include <BDNetEEPROM2.h> //Special library for banglardamal.org's NetEEPROM
#include <Wiegand.h>
#include <elapsedMillis.h>
#include <avr/wdt.h>
#include <MemoryFree.h>
#define fw_ver "2.1.0"
#define softwareTAG "NRFID20171216"
#define hwSS 53
#define ethCS 10
#define systemLED 13
#define readerLED 4
#define buzzer 5
#define protocolSelector 6
#define configTimeoutTick 60000 //1 min
// EEPROM Address Definitions
//#define STRING_LENGTH_BYTE 100
#define DHCP_OFFSET 7 //Originally 7 as per BDNetEEPROM library
#define WIEGAND_OFFSET 33
#define REBOOT_OFFSET (WIEGAND_OFFSET + 1)
#define KEEPALIVE_OFFSET (REBOOT_OFFSET + 1)
#define SERVER_ADDR_SIZE (KEEPALIVE_OFFSET + 1)
#define SERVER_ADDR_OFFSET (SERVER_ADDR_SIZE + 1)
// The necessary variables for RS232 Communication
//String sub_str = "";
String str_rx = "";
String data = "";
boolean isBusy = false;
boolean inetOK;
unsigned long rebootTimer;
unsigned long keepAliveTimer;
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetServer server(8080);
EthernetClient client;
elapsedMillis keepAliveTimeElapsed;
elapsedMillis systemRunningTimeElapsed;
elapsedMillis configTimeoutTimer;
WIEGAND wg;
void setup() {
pinMode(hwSS, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(readerLED, OUTPUT);
pinMode(systemLED, OUTPUT);
digitalWrite(buzzer, LOW);
digitalWrite(readerLED, HIGH);
digitalWrite(systemLED, HIGH);
delay(100);
digitalWrite(buzzer, HIGH);
rebootTimer = EEPROM.read(REBOOT_OFFSET) * 3600000;
keepAliveTimer = EEPROM.read(KEEPALIVE_OFFSET) * 60000;
// Open serial communications and wait for port to open:
Serial.begin(9600);
splashScreen();
Serial.println();
Serial.println(F("Type 'conf t' in 4 seconds to enter config mode\n"));
smartDelayPrompt(4000);
//Config the system
if (str_rx == "conf t") {
str_rx = "";
configMode();
}
wdt_enable(WDTO_8S);
wiegandInit();
Serial.println();
// start the Ethernet connection:
if (inetInit()){
Serial.println(F("Ethernet is up and ready with the config:"));
showNetConfig ();
keepAlive();
digitalWrite(readerLED, LOW);
digitalWrite(systemLED, LOW);
} else {Serial.println(F("Ethernet failed to be ready."));soft_reset(3000);}
}
void loop() {
wdt_reset();
digitalWrite(readerLED, LOW);
digitalWrite(systemLED, LOW);
while (Serial.available() > 0){
str_rx = String(Serial.readStringUntil('\n'));
if (str_rx == "conf t") {
str_rx = "";
configMode();
}
}
if(wg.available()) {
wdt_reset();
isBusy = true;
digitalWrite(readerLED, HIGH);
//delay(500);
Serial.print(F("Wiegand HEX = "));
Serial.print(wg.getCode(),HEX);
Serial.print(F(", DECIMAL = "));
Serial.print(wg.getCode());
Serial.print(F(", Type W"));
Serial.println(wg.getWiegandType());
data = String(wg.getCode());
data.trim();
Serial.print(F("Found Data:"));
Serial.println(data);
postData();
delay(1000);
data = "";
digitalWrite(readerLED, LOW);
isBusy = false;
}
if (keepAliveTimeElapsed > keepAliveTimer) {
if (isBusy == false) {
isBusy = false;
keepAlive();
}
}
if (systemRunningTimeElapsed > rebootTimer) {
if (isBusy == false) {
isBusy = false;
soft_reset(3000);
}
}
}
// End of main loop