@@ -341,15 +341,23 @@ static void handle_network_data_message(const struct network_msg *msg)
341341{
342342 int err ;
343343 bool confirmable = IS_ENABLED (CONFIG_APP_CLOUD_CONFIRMABLE_MESSAGES );
344+ int64_t timestamp_ms = NRF_CLOUD_NO_TIMESTAMP ;
344345
345346 if (msg -> type != NETWORK_QUALITY_SAMPLE_RESPONSE ) {
346347 return ;
347348 }
348349
350+ /* Convert uptime to unix time */
351+ timestamp_ms = msg -> uptime ;
352+ err = date_time_uptime_to_unix_time_ms (& timestamp_ms );
353+ if (err ) {
354+ LOG_ERR ("date_time_uptime_to_unix_time_ms, error: %d" , err );
355+ }
356+
349357 err = nrf_cloud_coap_sensor_send (CUSTOM_JSON_APPID_VAL_CONEVAL ,
350- msg -> conn_eval_params .energy_estimate ,
351- NRF_CLOUD_NO_TIMESTAMP ,
352- confirmable );
358+ msg -> conn_eval_params .energy_estimate ,
359+ timestamp_ms ,
360+ confirmable );
353361 if (err ) {
354362 LOG_ERR ("nrf_cloud_coap_sensor_send, error: %d" , err );
355363 send_request_failed ();
@@ -358,9 +366,9 @@ static void handle_network_data_message(const struct network_msg *msg)
358366 }
359367
360368 err = nrf_cloud_coap_sensor_send (NRF_CLOUD_JSON_APPID_VAL_RSRP ,
361- msg -> conn_eval_params .rsrp ,
362- NRF_CLOUD_NO_TIMESTAMP ,
363- confirmable );
369+ msg -> conn_eval_params .rsrp ,
370+ timestamp_ms ,
371+ confirmable );
364372 if (err ) {
365373 LOG_ERR ("nrf_cloud_coap_sensor_send, error: %d" , err );
366374 send_request_failed ();
@@ -375,27 +383,27 @@ static int send_storage_data_to_cloud(const struct storage_data_item *item)
375383 int64_t timestamp_ms = NRF_CLOUD_NO_TIMESTAMP ;
376384 const bool confirmable = IS_ENABLED (CONFIG_APP_CLOUD_CONFIRMABLE_MESSAGES );
377385
378- /* Get current timestamp */
379- err = date_time_now (& timestamp_ms );
380- if (err ) {
381- LOG_WRN ("Failed to get current time, using no timestamp" );
382- timestamp_ms = NRF_CLOUD_NO_TIMESTAMP ;
383- }
384-
385386#if defined(CONFIG_APP_POWER )
386387 if (item -> type == STORAGE_TYPE_BATTERY ) {
387- double battery_percentage = item -> data .BATTERY ;
388+ const struct power_msg * power = & item -> data .BATTERY ;
389+
390+ /* Convert uptime to unix time */
391+ timestamp_ms = power -> uptime ;
392+ err = date_time_uptime_to_unix_time_ms (& timestamp_ms );
393+ if (err ) {
394+ LOG_ERR ("date_time_uptime_to_unix_time_ms, error: %d" , err );
395+ }
388396
389397 err = nrf_cloud_coap_sensor_send (CUSTOM_JSON_APPID_VAL_BATTERY ,
390- battery_percentage ,
398+ power -> percentage ,
391399 timestamp_ms ,
392400 confirmable );
393401 if (err ) {
394402 LOG_ERR ("Failed to send battery data to cloud, error: %d" , err );
395403 return err ;
396404 }
397405
398- LOG_DBG ("Battery data sent to cloud: %.1f%%" , battery_percentage );
406+ LOG_DBG ("Battery data sent to cloud: %.1f%%" , power -> percentage );
399407
400408 /* Unused variable if no other sources compiled in */
401409 (void )confirmable ;
@@ -408,6 +416,13 @@ static int send_storage_data_to_cloud(const struct storage_data_item *item)
408416 if (item -> type == STORAGE_TYPE_ENVIRONMENTAL ) {
409417 const struct environmental_msg * env = & item -> data .ENVIRONMENTAL ;
410418
419+ /* Convert uptime to unix time */
420+ timestamp_ms = env -> uptime ;
421+ err = date_time_uptime_to_unix_time_ms (& timestamp_ms );
422+ if (err ) {
423+ LOG_ERR ("date_time_uptime_to_unix_time_ms, error: %d" , err );
424+ }
425+
411426 return cloud_environmental_send (env , timestamp_ms , confirmable );
412427 }
413428#endif /* CONFIG_APP_ENVIRONMENTAL */
@@ -432,8 +447,9 @@ static int send_storage_data_to_cloud(const struct storage_data_item *item)
432447
433448 LOG_WRN ("Unknown storage data type: %d" , item -> type );
434449
435- /* Unused variable if no data sources are enabled */
450+ /* Unused variables if no data sources are enabled */
436451 (void )confirmable ;
452+ (void )timestamp_ms ;
437453
438454 return - ENOTSUP ;
439455}
0 commit comments