Skip to content
Merged
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
3 changes: 3 additions & 0 deletions UNOR4USBBridge/UNOR4USBBridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ void setup() {
/* Set up wifi event */
WiFi.onEvent(CAtHandler::onWiFiEvent);

/* Configure ntp */
configTime(0, 0, "pool.ntp.org");

Debug.setDebugOutputStream(&USBSerial);
Debug.setDebugLevel(DBG_ERROR);

Expand Down
27 changes: 27 additions & 0 deletions UNOR4USBBridge/cmds_esp_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CMDS_ESP_GENERIC_H

#include "at_handler.h"

extern "C" {
#include "esp32-hal-tinyusb.h"
}
Expand Down Expand Up @@ -359,6 +360,32 @@ 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: {
char epoch[12]; // gettime
constexpr uint32_t SECS_YR_2000 = 946684800UL; // the time at the start of y2k
time_t now = time(nullptr);

if (now < SECS_YR_2000) {
now = 0;
}

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

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

#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