Skip to content
Closed
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
33 changes: 32 additions & 1 deletion UNOR4USBBridge/cmds_esp_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#define CMDS_ESP_GENERIC_H

#include "at_handler.h"

char epoch[12]; // gettime
#define SECS_YR_2000 (946684800UL) // the time at the start of y2k

extern "C" {
#include "esp32-hal-tinyusb.h"
}
Expand Down Expand Up @@ -332,6 +336,33 @@ void CAtHandler::add_cmds_esp_generic() {
return chAT::CommandStatus::ERROR;
}
};

/* ....................................................................... */
command_table[_GETTIME] = [this](auto & srv, auto & parser) {
/* ....................................................................... */

switch (parser.cmd_mode) {
case chAT::CommandMode::Write: {

configTime(0, 0, "pool.ntp.org");
time_t now = time(nullptr);

while (now < SECS_YR_2000) {
delay(100);
now = time(nullptr);
}

srv.write_response_prompt();
sprintf(epoch,"%d", (unsigned long) now);
srv.write_cstr((const char *) epoch);
srv.write_line_end();

return chAT::CommandStatus::OK;
}
default:
return chAT::CommandStatus::ERROR;
}
};
}

#endif
#endif
1 change: 1 addition & 0 deletions UNOR4USBBridge/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum file_op {
#define _ENDL "\r\n"
#define _WIFISCAN "+WIFISCAN"

#define _GETTIME "+GETTIME"
#define _RESET "+RESET"
#define _RESTART_BOOTLOADER "+RESTARTBOOTLOADER"
#define _GMR "+GMR"
Expand Down