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/c_cpp_properties.json
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.vscode/ipch
|
.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
|
@ -15,25 +15,26 @@ bool NFC::hasNewCard()
|
|||||||
{
|
{
|
||||||
if(rfid->PICC_IsNewCardPresent() && rfid->PICC_ReadCardSerial())
|
if(rfid->PICC_IsNewCardPresent() && rfid->PICC_ReadCardSerial())
|
||||||
{
|
{
|
||||||
byte atqaLen = sizeof(atqa);
|
return true;
|
||||||
MFRC522::StatusCode status = rfid->PICC_RequestA(atqa, &atqaLen);
|
// byte atqaLen = sizeof(atqa);
|
||||||
Serial.printf("PICC_RequestA: 0x%02x\n", status);
|
// MFRC522::StatusCode status = rfid->PICC_RequestA(atqa, &atqaLen);
|
||||||
if(status == MFRC522::STATUS_OK && atqa[0] == 0x44)
|
// Serial.printf("PICC_RequestA: 0x%02x\n", status);
|
||||||
{
|
// if(status == MFRC522::STATUS_OK && atqa[0] == 0x44)
|
||||||
return true;
|
// {
|
||||||
}
|
// return true;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NFC::selectCard()
|
bool NFC::selectCard()
|
||||||
{
|
{
|
||||||
MFRC522::StatusCode status = rfid->PICC_Select(&(rfid->uid));
|
// MFRC522::StatusCode status = rfid->PICC_Select(&(rfid->uid));
|
||||||
Serial.printf("PICC_Select: 0x%02x\n", status);
|
// Serial.printf("PICC_Select: 0x%02x\n", status);
|
||||||
if(status != MFRC522::STATUS_OK)
|
// if(status != MFRC522::STATUS_OK)
|
||||||
{
|
// {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
cardSelected = true;
|
cardSelected = true;
|
||||||
uid = rfid->uid;
|
uid = rfid->uid;
|
||||||
@ -43,12 +44,12 @@ bool NFC::selectCard()
|
|||||||
|
|
||||||
bool NFC::deselectCard()
|
bool NFC::deselectCard()
|
||||||
{
|
{
|
||||||
MFRC522::StatusCode status = rfid->PICC_HaltA();
|
// MFRC522::StatusCode status = rfid->PICC_HaltA();
|
||||||
Serial.printf("PICC_HaltA: 0x%02x\n", status);
|
// Serial.printf("PICC_HaltA: 0x%02x\n", status);
|
||||||
if(status != MFRC522::STATUS_OK)
|
// if(status != MFRC522::STATUS_OK)
|
||||||
{
|
// {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
cardSelected = false;
|
cardSelected = false;
|
||||||
Serial.println("Card Deselected");
|
Serial.println("Card Deselected");
|
||||||
|
@ -44,22 +44,39 @@ void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
|
|||||||
char topic_restartOTA[] = "fabreader/00000/restartOTA";
|
char topic_restartOTA[] = "fabreader/00000/restartOTA";
|
||||||
sprintf(topic_restartOTA, "fabreader/%05d/restartOTA", id);
|
sprintf(topic_restartOTA, "fabreader/%05d/restartOTA", id);
|
||||||
|
|
||||||
if(strcmp(topic, topic_requestOTA))
|
if(!strcmp(topic, topic_requestOTA))
|
||||||
{
|
{
|
||||||
Serial.println("Request OTA");
|
Serial.println("Request OTA");
|
||||||
byte response[APDU_BUFFER_SIZE] = {0};
|
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);
|
mqtt->publish(topic_responseOTA, response, APDU_BUFFER_SIZE);
|
||||||
Serial.println("Response OTA");
|
Serial.println("Response OTA");
|
||||||
}
|
}
|
||||||
else if(strcmp(topic, topic_stopOTA))
|
else if(!strcmp(topic, topic_stopOTA))
|
||||||
{
|
{
|
||||||
Serial.println("Stop OTA");
|
Serial.println("Stop OTA");
|
||||||
while(!(nfc->deselectCard()));
|
while(!(nfc->deselectCard()));
|
||||||
activeOTA = false;
|
activeOTA = false;
|
||||||
}
|
}
|
||||||
else if(strcmp(topic, topic_restartOTA))
|
else if(!strcmp(topic, topic_restartOTA))
|
||||||
{
|
{
|
||||||
Serial.println("Restart OTA");
|
Serial.println("Restart OTA");
|
||||||
while(!(nfc->deselectCard()));
|
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 <Arduino.h>
|
||||||
#include <ArduinoLog.h>
|
#include <ArduinoLog.h>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "config.h"
|
||||||
#include "Pins.h"
|
#include "pins.h"
|
||||||
#include "NFC.h"
|
#include "nfc.h"
|
||||||
#include "OTAProxy.h"
|
#include "otaproxy.h"
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
#include <SSD1306Wire.h>
|
#include <SSD1306Wire.h>
|
||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
Config_Data config;
|
//Config_Data config;
|
||||||
|
|
||||||
PubSubClient* mqtt;
|
PubSubClient* mqtt;
|
||||||
NFC* nfc;
|
NFC* nfc;
|
||||||
@ -28,7 +28,7 @@ void setup_wifi()
|
|||||||
Serial.println("Connecting Wifi ...");
|
Serial.println("Connecting Wifi ...");
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(config.WLAN_SSID, config.WLAN_Password);
|
WiFi.begin(WLAN_SSID, WLAN_PASS);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
@ -44,22 +44,22 @@ void reconnect()
|
|||||||
while (!mqtt->connected())
|
while (!mqtt->connected())
|
||||||
{
|
{
|
||||||
String clientId = "FabReader_";
|
String clientId = "FabReader_";
|
||||||
clientId += String(config.ID);
|
clientId += String(FABREADERID);
|
||||||
|
|
||||||
Serial.println("Connecting MQTT ...");
|
Serial.println("Connecting MQTT ...");
|
||||||
if (mqtt->connect(clientId.c_str()))
|
if (mqtt->connect(clientId.c_str()))
|
||||||
{
|
{
|
||||||
Serial.println("MQTT connected");
|
Serial.println("MQTT connected");
|
||||||
char id[6] = "00000";
|
char id[6] = "00000";
|
||||||
sprintf(id, "%05d", config.ID);
|
sprintf(id, "%05d", FABREADERID);
|
||||||
mqtt->publish("fabreader", id);
|
mqtt->publish("fabreader", id);
|
||||||
|
|
||||||
char topic_requestOTA[] = "fabreader/00000/requestOTA";
|
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);
|
mqtt->subscribe(topic_requestOTA);
|
||||||
|
|
||||||
char topic_stopOTA[] = "fabreader/00000/stopOTA";
|
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);
|
mqtt->subscribe(topic_stopOTA);
|
||||||
} else {
|
} else {
|
||||||
Serial.print("failed, rc=");
|
Serial.print("failed, rc=");
|
||||||
@ -72,7 +72,8 @@ void reconnect()
|
|||||||
|
|
||||||
void callback(char* topic, byte* payload, unsigned int length)
|
void callback(char* topic, byte* payload, unsigned int length)
|
||||||
{
|
{
|
||||||
Serial.println("Recive Message");
|
Serial.println("Receive Message");
|
||||||
|
Serial.println(topic);
|
||||||
if(ota->hasActiveOTA())
|
if(ota->hasActiveOTA())
|
||||||
{
|
{
|
||||||
ota->continueOTA(topic, payload, length);
|
ota->continueOTA(topic, payload, length);
|
||||||
@ -81,18 +82,13 @@ void callback(char* topic, byte* payload, unsigned int length)
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
config.ID = 1;
|
|
||||||
strcpy(config.WLAN_SSID, "");
|
|
||||||
strcpy(config.WLAN_Password, "");
|
|
||||||
strcpy(config.MQTT_Broker, "");
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.print("\n\n\n");
|
Serial.print("\n\n\n");
|
||||||
Serial.println("Booting ...");
|
Serial.println("Booting ...");
|
||||||
|
|
||||||
pinMode(PIN_BUZZER, OUTPUT);
|
pinMode(PIN_BUZZER, OUTPUT);
|
||||||
pinMode(PIN_BUTTON, INPUT);
|
pinMode(PIN_BUTTON, INPUT);
|
||||||
pinMode(PIN_ETH_SPI_SS, OUTPUT);
|
pinMode(PIN_ETH_SPI_SS, OUTPUT);
|
||||||
digitalWrite(PIN_ETH_SPI_SS, HIGH);
|
digitalWrite(PIN_ETH_SPI_SS, HIGH);
|
||||||
|
|
||||||
Serial.println("Connecting NFC ...");
|
Serial.println("Connecting NFC ...");
|
||||||
@ -101,16 +97,15 @@ void setup()
|
|||||||
{
|
{
|
||||||
Serial.println("NFC Test failed");
|
Serial.println("NFC Test failed");
|
||||||
}
|
}
|
||||||
//nfc->rfid->PCD_SetAntennaGain(MFRC522::RxGain_max);
|
|
||||||
Serial.println("NFC connected");
|
Serial.println("NFC connected");
|
||||||
|
|
||||||
setup_wifi();
|
setup_wifi();
|
||||||
|
|
||||||
mqtt = new PubSubClient(espClient);
|
mqtt = new PubSubClient(espClient);
|
||||||
mqtt->setServer(config.MQTT_Broker, config.MQTT_Port);
|
mqtt->setServer(MQTT_BROKER, 1883);
|
||||||
mqtt->setCallback(callback);
|
mqtt->setCallback(callback);
|
||||||
|
|
||||||
ota = new OTAProxy(mqtt, nfc, config.ID);
|
ota = new OTAProxy(mqtt, nfc, FABREADERID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
@ -121,12 +116,13 @@ void loop()
|
|||||||
}
|
}
|
||||||
mqtt->loop();
|
mqtt->loop();
|
||||||
|
|
||||||
if(!ota->hasActiveOTA() && nfc->hasNewCard())
|
|
||||||
{
|
|
||||||
ota->startOTA();
|
|
||||||
}
|
|
||||||
if(ota->hasActiveOTA() && nfc->isCardLost())
|
if(ota->hasActiveOTA() && nfc->isCardLost())
|
||||||
{
|
{
|
||||||
ota->cancelOTA();
|
ota->cancelOTA();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!ota->hasActiveOTA())
|
||||||
|
{
|
||||||
|
ota->startOTA();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user