diff --git a/UNOR4USBBridge/cmds_esp_generic.h b/UNOR4USBBridge/cmds_esp_generic.h index cd0e2d9..ec3643a 100644 --- a/UNOR4USBBridge/cmds_esp_generic.h +++ b/UNOR4USBBridge/cmds_esp_generic.h @@ -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" } @@ -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 \ No newline at end of file +#endif diff --git a/UNOR4USBBridge/commands.h b/UNOR4USBBridge/commands.h index ffa9555..52cba99 100644 --- a/UNOR4USBBridge/commands.h +++ b/UNOR4USBBridge/commands.h @@ -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"