Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/fdrs_datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ enum crcResult {
CRC_BAD,
} returnCRC;

enum FDRSMode {
MODE_NORMAL,
MODE_UPDATE,
};

enum cmd_t {
cmd_clear,
cmd_ping,
Expand Down
2 changes: 1 addition & 1 deletion src/fdrs_gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ void printFDRS(DataReading*, int);
#ifdef USE_WIFI
#include "fdrs_gateway_wifi.h"
#include "fdrs_gateway_mqtt.h"
#include "fdrs_gateway_ota.h"
#endif
#include "fdrs_ota.h"

#ifdef DEBUG_CONFIG
#include "fdrs_checkConfig.h"
Expand Down
56 changes: 56 additions & 0 deletions src/fdrs_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ uint8_t incMAC[6];
DataReading fdrsData[espnow_size];
DataReading incData[espnow_size];
TimeSource timeSource;
FDRSMode fdrsMode = MODE_NORMAL;

uint8_t data_count = 0;

Expand Down Expand Up @@ -429,6 +430,61 @@ bool reqTimeFDRS() {
#endif
}

// goes into Update Mode where new software can be uploaded
bool updateFDRS() {
bool backToSta = false;

fdrsMode = MODE_UPDATE;
DBG("Update Mode.");

// Finish any async operations
#ifdef USE_LORA
unsigned long timeout = millis() + 1000;
while(millis() < timeout && !isLoRaAsyncComplete()) {
handleLoRa();
handleTime();
yield();
}
#endif // USE_LORA

if(WiFi.getMode() == WIFI_MODE_STA) {
WiFi.mode(WIFI_MODE_APSTA);
backToSta = true;
}
else {
WiFi.mode(WIFI_MODE_AP);
}

WiFi.softAP("fdrs", "fdrs1234");
// print IP address
DBG("IP: " + WiFi.softAPIP().toString());
// WiFi.softAPConfig();
// start OTA listening for x minutes
begin_OTA();
unsigned long timeout = (1000 * 60 * 5); // 5 minutes
DBG("Mode time out in " + String(timeout/1000) + " seconds."); // x seconds remaining
timeout += millis();
// timeout after x minutes
while(millis() < timeout) {
handleOTA();
handleTime();
yield();
if((timeout - millis()) % (60 * 1000) == 0) {
DBG("Mode time out in " + String((timeout - millis())/1000) + " seconds."); // x seconds remaining
}

}
if(backToSta) {
WiFi.mode(WIFI_MODE_STA);
}
else {
WiFi.mode(WIFI_MODE_NULL);
}
fdrsMode = MODE_NORMAL;
DBG("Leaving Update Mode.");
return false;
}

// Skeleton Functions related to function calls to files that are not included
#ifndef USE_LORA
void sendTimeLoRa() {}
Expand Down
File renamed without changes.