mirror of
https://gitlab.com/fabinfra/fabhardware/fabreader.git
synced 2025-04-20 17:46:26 +02:00
Fixed Config
This commit is contained in:
parent
984bc9d873
commit
3122fabc36
1
src/FabReader_v2/.gitignore
vendored
1
src/FabReader_v2/.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
src/config.h
|
32
src/FabReader_v2/src/Deprecated/config.h.old
Normal file
32
src/FabReader_v2/src/Deprecated/config.h.old
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
struct Config_Data
|
||||
{
|
||||
int ID = 0;
|
||||
|
||||
char MQTT_Broker[256];
|
||||
int MQTT_Port = 1883;
|
||||
char MQTT_Username[64];
|
||||
char MQTT_Password[64];
|
||||
|
||||
char WLAN_SSID[65];
|
||||
char WLAN_Password[64];
|
||||
};
|
||||
|
||||
class Config {
|
||||
public:
|
||||
const char WLANAP_SSID[32] = "FabReader";
|
||||
const char WLANAP_Password[64] = "FabReader";
|
||||
|
||||
Config_Data Data;
|
||||
|
||||
Config();
|
||||
Config(int ID, char mqtt_broker[], int mqtt_port, char mqtt_username[], char mqtt_password[], char wlan_ssid[], char wlan_password[]);
|
||||
|
||||
void Load();
|
||||
void Save();
|
||||
|
||||
bool IsEmpty();
|
||||
};
|
||||
#endif
|
@ -14,26 +14,27 @@ NFC::NFC(int pin_ss, int pin_rst)
|
||||
bool NFC::hasNewCard()
|
||||
{
|
||||
if(rfid->PICC_IsNewCardPresent() && rfid->PICC_ReadCardSerial())
|
||||
{
|
||||
byte atqaLen = sizeof(atqa);
|
||||
MFRC522::StatusCode status = rfid->PICC_RequestA(atqa, &atqaLen);
|
||||
Serial.printf("PICC_RequestA: 0x%02x\n", status);
|
||||
if(status == MFRC522::STATUS_OK && atqa[0] == 0x44)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// byte atqaLen = sizeof(atqa);
|
||||
// MFRC522::StatusCode status = rfid->PICC_RequestA(atqa, &atqaLen);
|
||||
// Serial.printf("PICC_RequestA: 0x%02x\n", status);
|
||||
// if(status == MFRC522::STATUS_OK && atqa[0] == 0x44)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NFC::selectCard()
|
||||
{
|
||||
MFRC522::StatusCode status = rfid->PICC_Select(&(rfid->uid));
|
||||
Serial.printf("PICC_Select: 0x%02x\n", status);
|
||||
if(status != MFRC522::STATUS_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// MFRC522::StatusCode status = rfid->PICC_Select(&(rfid->uid));
|
||||
// Serial.printf("PICC_Select: 0x%02x\n", status);
|
||||
// if(status != MFRC522::STATUS_OK)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
cardSelected = true;
|
||||
uid = rfid->uid;
|
||||
@ -43,12 +44,12 @@ bool NFC::selectCard()
|
||||
|
||||
bool NFC::deselectCard()
|
||||
{
|
||||
MFRC522::StatusCode status = rfid->PICC_HaltA();
|
||||
Serial.printf("PICC_HaltA: 0x%02x\n", status);
|
||||
if(status != MFRC522::STATUS_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// MFRC522::StatusCode status = rfid->PICC_HaltA();
|
||||
// Serial.printf("PICC_HaltA: 0x%02x\n", status);
|
||||
// if(status != MFRC522::STATUS_OK)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
cardSelected = false;
|
||||
Serial.println("Card Deselected");
|
||||
|
@ -44,22 +44,39 @@ void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
|
||||
char topic_restartOTA[] = "fabreader/00000/restartOTA";
|
||||
sprintf(topic_restartOTA, "fabreader/%05d/restartOTA", id);
|
||||
|
||||
if(strcmp(topic, topic_requestOTA))
|
||||
if(!strcmp(topic, topic_requestOTA))
|
||||
{
|
||||
Serial.println("Request OTA");
|
||||
byte response[APDU_BUFFER_SIZE] = {0};
|
||||
nfc->Transceive(payload, length, response, APDU_BUFFER_SIZE);
|
||||
|
||||
MFRC522::StatusCode status;
|
||||
do
|
||||
{
|
||||
status = nfc->Transceive(payload, length, response, APDU_BUFFER_SIZE);
|
||||
Serial.printf("PICC_Tranceive: 0x%02x\n", status);
|
||||
delay(100);
|
||||
}
|
||||
while (status != MFRC522::STATUS_OK);
|
||||
|
||||
for(int i = 0; i < APDU_BUFFER_SIZE; i++)
|
||||
{
|
||||
char hexCar[2];
|
||||
|
||||
sprintf(hexCar, "%02X", response[i]);
|
||||
Serial.print(hexCar);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
mqtt->publish(topic_responseOTA, response, APDU_BUFFER_SIZE);
|
||||
Serial.println("Response OTA");
|
||||
}
|
||||
else if(strcmp(topic, topic_stopOTA))
|
||||
else if(!strcmp(topic, topic_stopOTA))
|
||||
{
|
||||
Serial.println("Stop OTA");
|
||||
while(!(nfc->deselectCard()));
|
||||
activeOTA = false;
|
||||
}
|
||||
else if(strcmp(topic, topic_restartOTA))
|
||||
else if(!strcmp(topic, topic_restartOTA))
|
||||
{
|
||||
Serial.println("Restart OTA");
|
||||
while(!(nfc->deselectCard()));
|
||||
|
4
src/FabReader_v2/src/config.h copy.example
Normal file
4
src/FabReader_v2/src/config.h copy.example
Normal file
@ -0,0 +1,4 @@
|
||||
#define WLAN_SSID ""
|
||||
#define WLAN_PASS ""
|
||||
#define MQTT_BROKER ""
|
||||
#define FABREADERID 1
|
@ -1,10 +1,10 @@
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoLog.h>
|
||||
|
||||
#include "Config.h"
|
||||
#include "Pins.h"
|
||||
#include "NFC.h"
|
||||
#include "OTAProxy.h"
|
||||
#include "config.h"
|
||||
#include "pins.h"
|
||||
#include "nfc.h"
|
||||
#include "otaproxy.h"
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
@ -16,7 +16,7 @@
|
||||
#include <SSD1306Wire.h>
|
||||
|
||||
WiFiClient espClient;
|
||||
Config_Data config;
|
||||
//Config_Data config;
|
||||
|
||||
PubSubClient* mqtt;
|
||||
NFC* nfc;
|
||||
@ -28,7 +28,7 @@ void setup_wifi()
|
||||
Serial.println("Connecting Wifi ...");
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(config.WLAN_SSID, config.WLAN_Password);
|
||||
WiFi.begin(WLAN_SSID, WLAN_PASS);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
@ -44,22 +44,22 @@ void reconnect()
|
||||
while (!mqtt->connected())
|
||||
{
|
||||
String clientId = "FabReader_";
|
||||
clientId += String(config.ID);
|
||||
clientId += String(FABREADERID);
|
||||
|
||||
Serial.println("Connecting MQTT ...");
|
||||
if (mqtt->connect(clientId.c_str()))
|
||||
{
|
||||
Serial.println("MQTT connected");
|
||||
char id[6] = "00000";
|
||||
sprintf(id, "%05d", config.ID);
|
||||
sprintf(id, "%05d", FABREADERID);
|
||||
mqtt->publish("fabreader", id);
|
||||
|
||||
char topic_requestOTA[] = "fabreader/00000/requestOTA";
|
||||
sprintf(topic_requestOTA, "fabreader/%05d/requestOTA", config.ID);
|
||||
sprintf(topic_requestOTA, "fabreader/%05d/requestOTA", FABREADERID);
|
||||
mqtt->subscribe(topic_requestOTA);
|
||||
|
||||
char topic_stopOTA[] = "fabreader/00000/stopOTA";
|
||||
sprintf(topic_stopOTA, "fabreader/%05d/stopOTA", config.ID);
|
||||
sprintf(topic_stopOTA, "fabreader/%05d/stopOTA", FABREADERID);
|
||||
mqtt->subscribe(topic_stopOTA);
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
@ -72,7 +72,8 @@ void reconnect()
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length)
|
||||
{
|
||||
Serial.println("Recive Message");
|
||||
Serial.println("Receive Message");
|
||||
Serial.println(topic);
|
||||
if(ota->hasActiveOTA())
|
||||
{
|
||||
ota->continueOTA(topic, payload, length);
|
||||
@ -81,11 +82,6 @@ void callback(char* topic, byte* payload, unsigned int length)
|
||||
|
||||
void setup()
|
||||
{
|
||||
config.ID = 1;
|
||||
strcpy(config.WLAN_SSID, "");
|
||||
strcpy(config.WLAN_Password, "");
|
||||
strcpy(config.MQTT_Broker, "");
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.print("\n\n\n");
|
||||
Serial.println("Booting ...");
|
||||
@ -101,16 +97,15 @@ void setup()
|
||||
{
|
||||
Serial.println("NFC Test failed");
|
||||
}
|
||||
//nfc->rfid->PCD_SetAntennaGain(MFRC522::RxGain_max);
|
||||
Serial.println("NFC connected");
|
||||
|
||||
setup_wifi();
|
||||
|
||||
mqtt = new PubSubClient(espClient);
|
||||
mqtt->setServer(config.MQTT_Broker, config.MQTT_Port);
|
||||
mqtt->setServer(MQTT_BROKER, 1883);
|
||||
mqtt->setCallback(callback);
|
||||
|
||||
ota = new OTAProxy(mqtt, nfc, config.ID);
|
||||
ota = new OTAProxy(mqtt, nfc, FABREADERID);
|
||||
}
|
||||
|
||||
void loop()
|
||||
@ -121,12 +116,13 @@ void loop()
|
||||
}
|
||||
mqtt->loop();
|
||||
|
||||
if(!ota->hasActiveOTA() && nfc->hasNewCard())
|
||||
{
|
||||
ota->startOTA();
|
||||
}
|
||||
if(ota->hasActiveOTA() && nfc->isCardLost())
|
||||
{
|
||||
ota->cancelOTA();
|
||||
}
|
||||
|
||||
if(!ota->hasActiveOTA())
|
||||
{
|
||||
ota->startOTA();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user