Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Commit e9c2e9d

Browse files
committed
use RPC function for time
1 parent 9c0df56 commit e9c2e9d

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

src/thingsboard.c

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,38 +104,14 @@ static int timestamp_from_buf(int64_t *value, const void *buf, size_t sz)
104104
return 0;
105105
}
106106

107-
static int client_handle_time_response(struct coap_client_request *req,
108-
struct coap_packet *response)
107+
void client_handle_time_response(const uint8_t *data, size_t len)
109108
{
110109
int64_t ts = 0;
111-
const uint8_t *payload;
112-
uint16_t payload_len;
113-
uint8_t code;
114-
char code_str[5];
115-
char expected_code_str[5];
116-
int err;
117-
118-
LOG_INF("%s", __func__);
119-
120-
code = coap_header_get_code(response);
121-
if (code != COAP_RESPONSE_CODE_CONTENT) {
122-
coap_response_code_to_str(code, code_str);
123-
coap_response_code_to_str(COAP_RESPONSE_CODE_CONTENT, expected_code_str);
124-
LOG_ERR("Unexpected response code for timestamp request: got %s, expected %s",
125-
code_str, expected_code_str);
126-
return -1;
127-
}
128-
129-
payload = coap_packet_get_payload(response, &payload_len);
130-
if (!payload_len) {
131-
LOG_ERR("Received empty timestamp");
132-
return payload_len;
133-
}
134110

135-
err = timestamp_from_buf(&ts, payload, payload_len);
111+
int err = timestamp_from_buf(&ts, data, len);
136112
if (err) {
137113
LOG_ERR("Parsing of time response failed");
138-
return err;
114+
return;
139115
}
140116

141117
tb_time.tb_time = ts;
@@ -146,7 +122,7 @@ static int client_handle_time_response(struct coap_client_request *req,
146122
k_work_reschedule(&work_time, K_SECONDS(CONFIG_THINGSBOARD_TIME_REFRESH_INTERVAL_SECONDS));
147123

148124
k_sem_give(&time_sem);
149-
return 0;
125+
return;
150126
}
151127

152128
static int client_subscribe_to_attributes(void)
@@ -184,11 +160,7 @@ static void client_request_time(struct k_work *work)
184160
{
185161
int err;
186162

187-
static const char *payload = "{\"method\": \"getCurrentTime\", \"params\": {}}";
188-
const uint8_t *uri[] = {"api", "v1", access_token, "rpc", NULL};
189-
190-
err = coap_client_make_request(uri, payload, strlen(payload), COAP_TYPE_CON,
191-
COAP_METHOD_POST, client_handle_time_response);
163+
err = thingsboard_rpc("getCurrentTime", client_handle_time_response);
192164
if (err) {
193165
LOG_ERR("Failed to request time");
194166
}

0 commit comments

Comments
 (0)