|
|
|
|
@ -432,7 +432,8 @@ void atualizaEnviosPendentes( String mensagem)
@@ -432,7 +432,8 @@ void atualizaEnviosPendentes( String mensagem)
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(Json[F("recebido")] == false) |
|
|
|
|
bool recebidoAck = Json[F("recebido")].as<bool>(); |
|
|
|
|
if(!recebidoAck) |
|
|
|
|
{ |
|
|
|
|
LOGLN(F("Recebido = false")); |
|
|
|
|
return; |
|
|
|
|
@ -476,13 +477,7 @@ void atualizaEnviosPendentes( String mensagem)
@@ -476,13 +477,7 @@ void atualizaEnviosPendentes( String mensagem)
|
|
|
|
|
resp += " foi removido"; |
|
|
|
|
resp += "\"}"; |
|
|
|
|
|
|
|
|
|
if (qntEnvPend > 0) { |
|
|
|
|
qntEnvPend--; |
|
|
|
|
//Menu Principal
|
|
|
|
|
if (indiceMenu == 0) { |
|
|
|
|
menuRedrawPending = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
enviosPendentes(); |
|
|
|
|
|
|
|
|
|
if(MQTT_connected == true) |
|
|
|
|
{ |
|
|
|
|
@ -555,8 +550,9 @@ void enviarAbastecimento()
@@ -555,8 +550,9 @@ void enviarAbastecimento()
|
|
|
|
|
{ |
|
|
|
|
LOGLN(F("Enviando dados de abastecimento pendente")); |
|
|
|
|
|
|
|
|
|
StaticJsonDocument<MQTT_MAX_PACKET_SIZE> Json; |
|
|
|
|
char pub_message[MQTT_MAX_PACKET_SIZE]; |
|
|
|
|
StaticJsonDocument<600> Json; |
|
|
|
|
char in_message[MQTT_MAX_PACKET_SIZE]; |
|
|
|
|
char out_message[MQTT_MAX_PACKET_SIZE]; |
|
|
|
|
|
|
|
|
|
byte tentativas = 0; |
|
|
|
|
|
|
|
|
|
@ -584,26 +580,74 @@ void enviarAbastecimento()
@@ -584,26 +580,74 @@ void enviarAbastecimento()
|
|
|
|
|
LOGLN(F("Nao foi possivel abrir a pasta ou ela não existe")); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(file.openNext(&root, O_RDONLY)) |
|
|
|
|
//modificacapo
|
|
|
|
|
while(file.openNext(&root, O_RDONLY)) |
|
|
|
|
{ |
|
|
|
|
DeserializationError deserializeError = deserializeJson(Json, file); |
|
|
|
|
if (file.isHidden()) |
|
|
|
|
{ |
|
|
|
|
file.close(); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char currentFile[64]; |
|
|
|
|
file.getName(currentFile, 64); |
|
|
|
|
bool isDir = file.isDir(); |
|
|
|
|
|
|
|
|
|
file.close(); |
|
|
|
|
|
|
|
|
|
if (isDir) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (strstr(currentFile, ".txt") == 0) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char pathFile[96]; |
|
|
|
|
snprintf(pathFile, sizeof(pathFile), "%s/%s", "envios", currentFile); |
|
|
|
|
file = SD.open(pathFile, O_RDONLY); |
|
|
|
|
if (!file) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
size_t n = file.read(in_message, sizeof(in_message) - 1); |
|
|
|
|
file.close(); |
|
|
|
|
in_message[n] = '\0'; |
|
|
|
|
|
|
|
|
|
LOG(F("Lendo pendente: ")); |
|
|
|
|
LOGLN(pathFile); |
|
|
|
|
LOG(F("Tamanho payload: ")); |
|
|
|
|
LOGLN(n); |
|
|
|
|
|
|
|
|
|
DeserializationError deserializeError = deserializeJson(Json, in_message); |
|
|
|
|
if (deserializeError) |
|
|
|
|
{ |
|
|
|
|
LOG(F("deserializeJson() failed: ")); |
|
|
|
|
LOGLN(deserializeError.f_str()); |
|
|
|
|
return; |
|
|
|
|
LOG(F("Falha ao desserializar, movendo para envios_corrompidos: ")); |
|
|
|
|
LOGLN(pathFile); |
|
|
|
|
|
|
|
|
|
if(!SD.exists("envios_corrompidos")) |
|
|
|
|
{ |
|
|
|
|
SD.mkdir("envios_corrompidos"); |
|
|
|
|
} |
|
|
|
|
char newPath[128]; |
|
|
|
|
snprintf(newPath, sizeof(newPath), "%s/%s", "envios_corrompidos", currentFile); |
|
|
|
|
SD.rename(pathFile, newPath); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(MQTT_connected == true) |
|
|
|
|
{ |
|
|
|
|
serializeJson(Json, pub_message); |
|
|
|
|
MQTT.publish(TOPICO_PUB_ENVIO_ABASTECIMENTO, pub_message, false); |
|
|
|
|
LOG(F("Publicando em: ")); |
|
|
|
|
LOGLN(TOPICO_PUB_ENVIO_ABASTECIMENTO); |
|
|
|
|
serializeJson(Json, out_message); |
|
|
|
|
MQTT.publish(TOPICO_PUB_ENVIO_ABASTECIMENTO, out_message, false); |
|
|
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
|
LOG(F("Publicando pendente: ")); |
|
|
|
|
LOGLN(pathFile); |
|
|
|
|
serializeJsonPretty(Json, Serial); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
@ -613,10 +657,7 @@ void enviarAbastecimento()
@@ -613,10 +657,7 @@ void enviarAbastecimento()
|
|
|
|
|
{ |
|
|
|
|
LOGLN(F("MQTT desconectado!")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
LOGLN(F("Aparentemente a pasta esta vazia")); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(file.isOpen()) |
|
|
|
|
|