|
@ -150,7 +150,6 @@ uint8_t nightLedBrightness = 2; // Brightness of Neopixe |
|
|
// MQTT
|
|
|
// MQTT
|
|
|
bool enableMqtt = true; |
|
|
bool enableMqtt = true; |
|
|
#ifdef MQTT_ENABLE
|
|
|
#ifdef MQTT_ENABLE
|
|
|
uint8_t mqttFailCount = 3; // Number of times mqtt-reconnect is allowed to fail. If >= mqttFailCount to further reconnects take place
|
|
|
|
|
|
uint8_t const stillOnlineInterval = 60; // Interval 'I'm still alive' is sent via MQTT (in seconds)
|
|
|
uint8_t const stillOnlineInterval = 60; // Interval 'I'm still alive' is sent via MQTT (in seconds)
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
@ -413,20 +412,23 @@ void IRAM_ATTR onTimer() { |
|
|
* @param message |
|
|
* @param message |
|
|
*/ |
|
|
*/ |
|
|
void createFile(fs::FS &fs, const char * path, const char * message) { |
|
|
void createFile(fs::FS &fs, const char * path, const char * message) { |
|
|
snprintf(logBuf, serialLoglength, "Writing file: %s\n", path); |
|
|
|
|
|
|
|
|
//snprintf(logBuf, serialLoglength, "Writing file: %s\n", path);
|
|
|
|
|
|
snprintf(logBuf, serialLoglength, "%s: %s", (char *) FPSTR(writingFile), path); |
|
|
loggerNl(logBuf, LOGLEVEL_DEBUG); |
|
|
loggerNl(logBuf, LOGLEVEL_DEBUG); |
|
|
File file = fs.open(path, FILE_WRITE); |
|
|
File file = fs.open(path, FILE_WRITE); |
|
|
if(!file){ |
|
|
|
|
|
snprintf(logBuf, serialLoglength, "Failed to open file for writing"); |
|
|
|
|
|
|
|
|
if (!file) { |
|
|
|
|
|
snprintf(logBuf, serialLoglength, "%s", (char *) FPSTR(failedOpenFileForWrite)); |
|
|
|
|
|
//snprintf(logBuf, serialLoglength, "Failed to open file for writing");
|
|
|
loggerNl(logBuf, LOGLEVEL_ERROR); |
|
|
loggerNl(logBuf, LOGLEVEL_ERROR); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
if(file.print(message)){ |
|
|
|
|
|
snprintf(logBuf, serialLoglength, "File written"); |
|
|
|
|
|
|
|
|
if (file.print(message)) { |
|
|
|
|
|
//snprintf(logBuf, serialLoglength, "File written");
|
|
|
|
|
|
snprintf(logBuf, serialLoglength, "%s", (char *) FPSTR(fileWritten)); |
|
|
loggerNl(logBuf, LOGLEVEL_DEBUG); |
|
|
loggerNl(logBuf, LOGLEVEL_DEBUG); |
|
|
} else { |
|
|
} else { |
|
|
Serial.println("Write failed"); |
|
|
|
|
|
snprintf(logBuf, serialLoglength, "Write failed"); |
|
|
|
|
|
|
|
|
//snprintf(logBuf, serialLoglength, "Write failed");
|
|
|
|
|
|
snprintf(logBuf, serialLoglength, "%s", (char *) FPSTR(writeFailed)); |
|
|
loggerNl(logBuf, LOGLEVEL_ERROR); |
|
|
loggerNl(logBuf, LOGLEVEL_ERROR); |
|
|
} |
|
|
} |
|
|
file.close(); |
|
|
file.close(); |
|
@ -533,39 +535,39 @@ void parseSDFileList(fs::FS &fs, const char * dirname, const char * parent, uint |
|
|
yield(); |
|
|
yield(); |
|
|
File root = fs.open(dirname); |
|
|
File root = fs.open(dirname); |
|
|
|
|
|
|
|
|
if(!root){ |
|
|
|
|
|
|
|
|
if (!root) { |
|
|
snprintf(logBuf, serialLoglength, "Failed to open directory"); |
|
|
snprintf(logBuf, serialLoglength, "Failed to open directory"); |
|
|
loggerNl(logBuf, LOGLEVEL_DEBUG); |
|
|
loggerNl(logBuf, LOGLEVEL_DEBUG); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(!root.isDirectory()){ |
|
|
|
|
|
|
|
|
if (!root.isDirectory()) { |
|
|
snprintf(logBuf, serialLoglength, "Not a directory"); |
|
|
snprintf(logBuf, serialLoglength, "Not a directory"); |
|
|
loggerNl(logBuf, LOGLEVEL_DEBUG); |
|
|
loggerNl(logBuf, LOGLEVEL_DEBUG); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
File file = root.openNextFile(); |
|
|
File file = root.openNextFile(); |
|
|
|
|
|
|
|
|
while(file){ |
|
|
|
|
|
|
|
|
while(file) { |
|
|
esp_task_wdt_reset(); |
|
|
esp_task_wdt_reset(); |
|
|
const char *parent; |
|
|
const char *parent; |
|
|
|
|
|
|
|
|
if (strcmp(root.name(), "/") == 0 || root.name() == 0){ |
|
|
|
|
|
|
|
|
if (strcmp(root.name(), "/") == 0 || root.name() == 0) { |
|
|
parent = "#\0"; |
|
|
parent = "#\0"; |
|
|
} else { |
|
|
} else { |
|
|
parent = root.name(); |
|
|
parent = root.name(); |
|
|
} |
|
|
} |
|
|
if (file.name() == 0 ){ |
|
|
|
|
|
|
|
|
if (file.name() == 0 ) { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
strncpy(fileNameBuf, (char *) file.name(), sizeof(fileNameBuf) / sizeof(fileNameBuf[0])); |
|
|
strncpy(fileNameBuf, (char *) file.name(), sizeof(fileNameBuf) / sizeof(fileNameBuf[0])); |
|
|
|
|
|
|
|
|
// we have a folder
|
|
|
// we have a folder
|
|
|
if(file.isDirectory()){ |
|
|
|
|
|
|
|
|
if(file.isDirectory()) { |
|
|
|
|
|
|
|
|
esp_task_wdt_reset(); |
|
|
esp_task_wdt_reset(); |
|
|
if (pathValid(fileNameBuf)){ |
|
|
|
|
|
|
|
|
if (pathValid(fileNameBuf)) { |
|
|
sendWebsocketData(0, 31); |
|
|
sendWebsocketData(0, 31); |
|
|
appendNodeToJSONFile(SD, DIRECTORY_INDEX_FILE, fileNameBuf, parent, "folder" ); |
|
|
appendNodeToJSONFile(SD, DIRECTORY_INDEX_FILE, fileNameBuf, parent, "folder" ); |
|
|
|
|
|
|
|
@ -577,7 +579,7 @@ void parseSDFileList(fs::FS &fs, const char * dirname, const char * parent, uint |
|
|
// we have a file
|
|
|
// we have a file
|
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
if (fileValid(fileNameBuf)){ |
|
|
|
|
|
|
|
|
if (fileValid(fileNameBuf)) { |
|
|
appendNodeToJSONFile(SD, DIRECTORY_INDEX_FILE, fileNameBuf, parent, "file" ); |
|
|
appendNodeToJSONFile(SD, DIRECTORY_INDEX_FILE, fileNameBuf, parent, "file" ); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -805,11 +807,20 @@ void postHeartbeatViaMqtt(void) { |
|
|
/* Connects/reconnects to MQTT-Broker unless connection is not already available.
|
|
|
/* Connects/reconnects to MQTT-Broker unless connection is not already available.
|
|
|
Manages MQTT-subscriptions. |
|
|
Manages MQTT-subscriptions. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
uint32_t mqttLastRetryTimestamp = 0; |
|
|
|
|
|
|
|
|
bool reconnect() { |
|
|
bool reconnect() { |
|
|
uint8_t maxRetries = 10; |
|
|
|
|
|
uint8_t connect = false; |
|
|
uint8_t connect = false; |
|
|
|
|
|
uint8_t i = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (!mqttLastRetryTimestamp || millis() - mqttLastRetryTimestamp >= mqttRetryInterval * 1000) { |
|
|
|
|
|
mqttLastRetryTimestamp = millis(); |
|
|
|
|
|
} else { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
while (!MQTTclient.connected() && mqttFailCount < maxRetries) { |
|
|
|
|
|
|
|
|
while (!MQTTclient.connected() && i < mqttMaxRetriesPerInterval) { |
|
|
|
|
|
i++; |
|
|
snprintf(logBuf, serialLoglength, "%s %s", (char *) FPSTR(tryConnectMqttS), mqtt_server); |
|
|
snprintf(logBuf, serialLoglength, "%s %s", (char *) FPSTR(tryConnectMqttS), mqtt_server); |
|
|
loggerNl(logBuf, LOGLEVEL_NOTICE); |
|
|
loggerNl(logBuf, LOGLEVEL_NOTICE); |
|
|
|
|
|
|
|
@ -868,10 +879,8 @@ bool reconnect() { |
|
|
|
|
|
|
|
|
return MQTTclient.connected(); |
|
|
return MQTTclient.connected(); |
|
|
} else { |
|
|
} else { |
|
|
snprintf(logBuf, serialLoglength, "%s: rc=%i (%d / %d)", (char *) FPSTR(mqttConnFailed), MQTTclient.state(), mqttFailCount+1, maxRetries); |
|
|
|
|
|
|
|
|
snprintf(logBuf, serialLoglength, "%s: rc=%i (%d / %d)", (char *) FPSTR(mqttConnFailed), MQTTclient.state(), i, mqttMaxRetriesPerInterval); |
|
|
loggerNl(logBuf, LOGLEVEL_ERROR); |
|
|
loggerNl(logBuf, LOGLEVEL_ERROR); |
|
|
mqttFailCount++; |
|
|
|
|
|
delay(500); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
@ -3214,9 +3223,9 @@ void sendWebsocketData(uint32_t client, uint8_t code) { |
|
|
object["rfidId"] = currentRfidTagId; |
|
|
object["rfidId"] = currentRfidTagId; |
|
|
} else if (code == 20) { |
|
|
} else if (code == 20) { |
|
|
object["pong"] = "pong"; |
|
|
object["pong"] = "pong"; |
|
|
} else if (code == 30){ |
|
|
|
|
|
|
|
|
} else if (code == 30) { |
|
|
object["refreshFileList"] = "ready"; |
|
|
object["refreshFileList"] = "ready"; |
|
|
}else if (code == 31){ |
|
|
|
|
|
|
|
|
} else if (code == 31) { |
|
|
object["indexingState"] = fileNameBuf; |
|
|
object["indexingState"] = fileNameBuf; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|