@@ -463,7 +463,8 @@ void MqttClient::ros2mqtt(const topic_tools::ShapeShifter::ConstPtr& ros_msg,
463463}
464464
465465
466- void MqttClient::mqtt2ros (mqtt::const_message_ptr mqtt_msg) {
466+ void MqttClient::mqtt2ros (mqtt::const_message_ptr mqtt_msg,
467+ const ros::WallTime& arrival_stamp) {
467468
468469 std::string mqtt_topic = mqtt_msg->get_topic ();
469470 Mqtt2RosInterface& mqtt2ros = mqtt2ros_[mqtt_topic];
@@ -492,8 +493,7 @@ void MqttClient::mqtt2ros(mqtt::const_message_ptr mqtt_msg) {
492493 ros::serialization::deserialize (stamp_stream, stamp);
493494
494495 // compute ROS2MQTT latency
495- ros::WallTime now_wall = ros::WallTime::now ();
496- ros::Time now (now_wall.sec , now_wall.nsec );
496+ ros::Time now (arrival_stamp.sec , arrival_stamp.nsec );
497497 if (now.isZero ())
498498 NODELET_WARN (
499499 " Cannot compute latency for MQTT topic %s when ROS time is 0, is a ROS "
@@ -574,6 +574,9 @@ bool MqttClient::isConnectedService(IsConnected::Request& request,
574574
575575void MqttClient::message_arrived (mqtt::const_message_ptr mqtt_msg) {
576576
577+ // instantly take arrival timestamp
578+ ros::WallTime arrival_stamp = ros::WallTime::now ();
579+
577580 std::string mqtt_topic = mqtt_msg->get_topic ();
578581 NODELET_DEBUG (" Received MQTT message on topic '%s'" , mqtt_topic.c_str ());
579582 auto & payload = mqtt_msg->get_payload_ref ();
@@ -624,7 +627,7 @@ void MqttClient::message_arrived(mqtt::const_message_ptr mqtt_msg) {
624627
625628 // publish ROS message, if publisher initialized
626629 if (!mqtt2ros_[mqtt_topic].ros .publisher .getTopic ().empty ()) {
627- mqtt2ros (mqtt_msg);
630+ mqtt2ros (mqtt_msg, arrival_stamp );
628631 } else {
629632 NODELET_WARN (
630633 " ROS publisher for data from MQTT topic '%s' is not yet initialized: "
0 commit comments