File tree 3 files changed +31
-0
lines changed 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,9 @@ void setup() {
162
162
/* Set up wifi event */
163
163
WiFi.onEvent (CAtHandler::onWiFiEvent);
164
164
165
+ /* Configure ntp */
166
+ configTime (0 , 0 , " pool.ntp.org" );
167
+
165
168
Debug.setDebugOutputStream (&USBSerial);
166
169
Debug.setDebugLevel (DBG_ERROR);
167
170
Original file line number Diff line number Diff line change 2
2
#define CMDS_ESP_GENERIC_H
3
3
4
4
#include " at_handler.h"
5
+
5
6
extern " C" {
6
7
#include " esp32-hal-tinyusb.h"
7
8
}
@@ -359,6 +360,32 @@ void CAtHandler::add_cmds_esp_generic() {
359
360
return chAT::CommandStatus::ERROR;
360
361
}
361
362
};
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
+ };
362
389
}
363
390
364
391
#endif
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ enum file_op {
20
20
#define _ENDL "\r\n"
21
21
#define _WIFISCAN "+WIFISCAN"
22
22
23
+ #define _GETTIME "+GETTIME"
23
24
#define _RESET "+RESET"
24
25
#define _RESTART_BOOTLOADER "+RESTARTBOOTLOADER"
25
26
#define _GMR "+GMR"
You can’t perform that action at this time.
0 commit comments