int Exosite_SyncTime() { char day[11]; char time[9]; int http_status = 0; int strLen; char *testStr = "GET /ip HTTP/1.1\r\n"; unsigned char serverAddr[6] = {54, 183, 115, 21, 0, 80}; char strBuf[RX_SIZE]; DateTime datetime; if (!exosite_initialized) { return -1; } long sock = connect_to_exosite_with_server_addr("", serverAddr); if (sock < 0) { return -1; } exoHAL_SocketSend(sock, testStr, strlen(testStr)); sendLine(sock, HOST_LINE, NULL); sendLine(sock, ACCEPT_LINE, "\r\n"); http_status = get_http_status(sock); if (200 != http_status) return -1; strLen = exoHAL_SocketRecv(sock, strBuf, RX_SIZE); exoHAL_SocketClose(sock); if(strLen <= 0) return -1; if(parse_datetime(strBuf, strLen, &datetime) < 0) return -1; sprintf(day, "%s/%02d/%s", datetime.dayStr, month_to_num(datetime.monStr), datetime.yearStr); sprintf(time, "%s:%s:%s", datetime.hourStr, datetime.minStr, datetime.secStr); if(AtLibGs_SetTime(day, time) != ATLIBGS_MSG_ID_OK) return -1; return 0; }
/** * @brief Set time into GS module * * Calls AT+SETTIME=[<dd/mm/yyyy>,<HH:MM:SS>],[ System time in milliseconds since epoch(1970)] * command, and parses standard response. * * @param Desired time string in format * "dd/mm/yyyy,HH:MM:SS" or * ",xxxxxxxxxxxxx" * * @return True if successful */ bool GS_API_SetTime(uint8_t* time){ return gs_api_handle_cmd_resp(AtLibGs_SetTime((int8_t *) time)); }