File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,9 @@ void setup() {
162162 /* Set up wifi event */
163163 WiFi.onEvent (CAtHandler::onWiFiEvent);
164164
165+ /* Configure ntp */
166+ configTime (0 , 0 , " pool.ntp.org" );
167+
165168 Debug.setDebugOutputStream (&USBSerial);
166169 Debug.setDebugLevel (DBG_ERROR);
167170
Original file line number Diff line number Diff line change 22#define CMDS_ESP_GENERIC_H
33
44#include " at_handler.h"
5+
56extern " C" {
67 #include " esp32-hal-tinyusb.h"
78}
@@ -359,6 +360,32 @@ void CAtHandler::add_cmds_esp_generic() {
359360 return chAT::CommandStatus::ERROR;
360361 }
361362 };
363+
364+ /* ....................................................................... */
365+ command_table[_GETTIME] = [this ](auto & srv, auto & parser) {
366+ /* ....................................................................... */
367+
368+ switch (parser.cmd_mode ) {
369+ case chAT::CommandMode::Write: {
370+ char epoch[12 ]; // gettime
371+ constexpr uint32_t SECS_YR_2000 = 946684800UL ; // the time at the start of y2k
372+ time_t now = time (nullptr );
373+
374+ if (now < SECS_YR_2000) {
375+ now = 0 ;
376+ }
377+
378+ srv.write_response_prompt ();
379+ sprintf (epoch," %d" , (unsigned long ) now);
380+ srv.write_str ((const char *) epoch);
381+ srv.write_line_end ();
382+
383+ return chAT::CommandStatus::OK;
384+ }
385+ default :
386+ return chAT::CommandStatus::ERROR;
387+ }
388+ };
362389}
363390
364391#endif
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ enum file_op {
2020#define _ENDL "\r\n"
2121#define _WIFISCAN "+WIFISCAN"
2222
23+ #define _GETTIME "+GETTIME"
2324#define _RESET "+RESET"
2425#define _RESTART_BOOTLOADER "+RESTARTBOOTLOADER"
2526#define _GMR "+GMR"
You can’t perform that action at this time.
0 commit comments