This commit is contained in:
TheJoKlLa 2022-09-01 21:49:49 +02:00
parent ff8f51c173
commit 750ae399e0
10 changed files with 258 additions and 1418 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,34 @@
#include "Config.h"
#include <EEPROM.h>
#include <string.h>
Config::Config()
{
EEPROM.begin(512);
}
Config::Config(int ID, char broker[], char username[], char password[])
{
this->Data.ID = ID;
strcpy(this->Data.MQTT_Broker, broker);
strcpy(this->Data.MQTT_Username, username);
strcpy(this->Data.MQTT_Password, password);
EEPROM.begin(512);
}
void Config::Load()
{
EEPROM.get(0, this->Data);
}
void Config::Save()
{
EEPROM.put(0, this->Data);
EEPROM.commit();
}
bool Config::IsEmpty()
{
return this->Data.ID == 0;
}

28
src/FabReader_v2/Config.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef CONFIG_H
#define CONFIG_H
struct Config_Data
{
int ID = 0;
char MQTT_Broker[256];
char MQTT_Username[64];
char MQTT_Password[64];
};
class Config {
public:
const char WLAN_SSID[32] = "FabReader";
const char WLAN_Password[64] = "FabReader";
Config_Data Data;
Config();
Config(int ID, char broker[], char username[], char password[]);
void Load();
void Save();
bool IsEmpty();
};
#endif

View File

View File

@ -0,0 +1,21 @@
#ifndef DISPLAY_H
#define DISPLAY_H
enum State
{
CONNECT_WIFI,
CONNECT_MQTT,
FREE,
INUSE,
AUTHORIZE
};
String Messages [] =
{
"Connecting to WIFI ...",
"Connecting to MQTT ...",
"Free",
"In Use",
"Authorize ..."
}
#endif

View File

@ -0,0 +1,37 @@
#include "Config.h"
#include "Pins.h"
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <PubSubClient.h>
#include <SPI.h>
#include <MFRC522.h>
#include <SSD1306Wire.h>
#include <DES.h>
Config config;
WiFiClient wifiClient;
PubSubClient MQTTclient;
MFRC522 rfid(PIN_RFID_SPI_SS, PIN_RFID_RST);
void setup()
{
Serial.begin(115200);
pinMode(PIN_BUZZER, OUTPUT);
pinMode(PIN_BUTTON, INPUT);
pinMode(PIN_ETH_SPI_SS, OUTPUT);
digitalWrite(PIN_ETH_SPI_SS, HIGH);
rfid.PCD_Init();
}
void loop()
{
if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial())
{
Serial.println(rfid.uid.sak);
}
}

36
src/FabReader_v2/NFC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "NFC.h"
#include <SPI.h>
NFC::NFC(int pin_ss, int pin_rst, PubSubClient mqtt)
{
SPI.begin();
this->rfid = rfid(pin_ss, pin_rst);
this->rfid.PCD_Init();
}
bool NFC::hasNewCard()
{
return this->rfid.PICC_IsNewCardPresent() && this->rfid.PICC_ReadCardSerial()
}
void NFC::hasActiveOTA()
{
return this->activOTA;
}
void NFC::startOTA()
{
// TODO
}
void NFC::continueOTA()
{
// TODO
}
void NFC::cancelOTA()
{
}

24
src/FabReader_v2/NFC.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef NFC_H
#define NFC_H
#include <PubSubClient.h>
#include <MFRC522.h>
class NFC_H
{
private:
MFRC522 rfid;
PubSubClient* mqtt;
bool activOTA = false;
public:
NFC(int pin_ss, int pin_rst, PubSubClient* mqtt);
bool hasNewCard();
void hasActiveOTA();
void startOTA();
void continueOTA();
void cancelOTA();
}
#endif

18
src/FabReader_v2/Pins.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef PINS_H
#define PINS_H
// Pins for ESP8266
#define PIN_SDA 5
#define PIN_SCL 4
#define PIN_SPI_MOSI 13
#define PIN_SPI_MISO 12
#define PIN_SPI_SCK 14
#define PIN_RFID_RST 0
#define PIN_RFID_SPI_SS 2
#define PIN_ETH_SPI_SS 15
#define PIN_BUZZER 16
#define PIN_BUTTON A0
#endif

View File

@ -0,0 +1,60 @@
#ifndef WEBSITE_H
#define WEBSITE_H
const struct Website
{
const char INDEX[] =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<meta content=\"text/html; charset=ISO-8859-1\""
" http-equiv=\"content-type\">"
"<meta name = \"viewport\" content = \"width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable=0\">"
"<title>Verbindungsdaten RFID-Reader</title>"
"<style>"
"\"body { background-color: #808080; font-family: Arial, Helvetica, Sans-Serif; Color: #000000; }\""
"</style>"
"</head>"
"<body>"
"<h1>Verbindungsdaten RFID-Reader</h1>"
"<FORM action=\"/\" method=\"post\">"
"<P>"
"<label>ssid:&nbsp;</label><input maxlength=\"30\" name=\"ssid\"><br>"
"<label>Passwort:&nbsp;</label><input maxlength=\"30\" name=\"Passwort\"><br>"
"<label>BrokerIP:&nbsp;</label><input maxlength=\"15\" name=\"BrokerIP\"><br>"
"<label>ReaderID:&nbsp;</label><input maxlength=\"3\" name=\"ReaderID\"><br>"
"Connection<BR>"
"<INPUT type=\"radio\" name=\"ConType\" value=\"1\">Ehternet<BR>"
"<INPUT type=\"radio\" name=\"ConType\" value=\"0\">WiFi<BR>"
"RFID-Type<BR>"
"<INPUT type=\"radio\" name=\"RFIDType\" value=\"0\">Mifare Classic<BR>"
"<INPUT type=\"radio\" name=\"RFIDType\" value=\"1\">Mifare Classic + Timestamp<BR>"
"<INPUT type=\"radio\" name=\"RFIDType\" value=\"2\">Mifare DESFire<BR>"
"<INPUT type=\"radio\" name=\"RFIDType\" value=\"3\">Mifar Ultralight C<BR>"
"Data Package Format<BR>"
"<INPUT type=\"radio\" name=\"DatFormat\" value=\"0\">JSON<BR>"
"<INPUT type=\"radio\" name=\"DatFormat\" value=\"1\">Text <BR>"
"<INPUT type=\"submit\" value=\"Send\"> <INPUT type=\"reset\">"
"</P>"
"</FORM>"
"</body>"
"</html>";
const char SAVED[] =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<meta content=\"text/html; charset=ISO-8859-1\""
" http-equiv=\"content-type\">"
"<meta name = \"viewport\" content = \"width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable=0\">"
"<title>Verbindungsdaten RFID-Reader</title>"
"<style>"
"\"body { background-color: #808080; font-family: Arial, Helvetica, Sans-Serif; Color: #000000; }\""
"</style>"
"</head>"
"<body>"
"<h1>Saved</h1>"
"<h2><a href=\"/\">go back</a></h2>"
"</body>"
"</html>";
};
#endif