Skip to content

Publish capabilities via MQTT#254

Merged
rovo89 merged 1 commit intomainfrom
feat/capabilities
Nov 5, 2025
Merged

Publish capabilities via MQTT#254
rovo89 merged 1 commit intomainfrom
feat/capabilities

Conversation

@rovo89
Copy link
Copy Markdown
Collaborator

@rovo89 rovo89 commented Nov 5, 2025

The idea is to have a map of capabilities that make it easy for apps to check what the mower supports, without having to compare versions.

For simplicity in usage, the capabilities should be represented by a simple, flat object with the respective capabilities as keys and the "generation" as value. It starts with 1 when the capability gets added and increases whenever a significant change was done.

Summary by CodeRabbit

  • New Features

    • System capabilities are now published as JSON on connection for improved discovery.
  • Updates

    • Version publication now includes a JSON payload on an updated topic path while retaining the existing binary publication.
    • Capabilities publication occurs early during connection setup to ensure consumers receive current state promptly.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 5, 2025

Walkthrough

Adds a new CAPABILITIES JSON constant and publishes it on MQTT; calls capability publication when the MQTT client connects. Adjusts the version JSON publish topic to version/json while keeping the binary version publication.

Changes

Cohort / File(s) Summary
New header
src/lib/xbot_monitoring/src/capabilities.h
Adds #pragma once, includes nlohmann/json.hpp, and defines inline const nlohmann::ordered_json CAPABILITIES = { {"rpc", 1} };.
Monitoring implementation
src/lib/xbot_monitoring/src/xbot_monitoring.cpp
Adds #include "capabilities.h", declares/implements void publish_capabilities(), calls it from MqttCallback::connected, and changes JSON version publication topic to version/json (binary version remains).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify CAPABILITIES JSON shape and header include are correct.
  • Check publish_capabilities() serializes and publishes to capabilities/json correctly.
  • Confirm the version/json topic change is consistent with consumers.

Poem

🐰 I nibble code and stamp my paw,

CAPABILITIES now hop on the raw,
A JSON carrot on capabilities/json string,
Version paths adjusted — hear me sing! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Publish capabilities via MQTT' clearly and concisely describes the main change: introducing capabilities publication over MQTT as evidenced by the new capabilities.h header, publish_capabilities() function, and MQTT publishing implementation.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/capabilities

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e745b3f and 7c2e841.

📒 Files selected for processing (2)
  • src/lib/xbot_monitoring/src/capabilities.h (1 hunks)
  • src/lib/xbot_monitoring/src/xbot_monitoring.cpp (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/xbot_monitoring/src/xbot_monitoring.cpp
🧰 Additional context used
🪛 Clang (14.0.6)
src/lib/xbot_monitoring/src/capabilities.h

[error] 3-3: 'nlohmann/json.hpp' file not found

(clang-diagnostic-error)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build (ubuntu-24.04, amd64, legacy, ./docker/Dockerfile.Legacy)
  • GitHub Check: build (ubuntu-24.04-arm, arm64, default, ./docker/Dockerfile)
  • GitHub Check: build (ubuntu-24.04, amd64, default, ./docker/Dockerfile)
  • GitHub Check: build (ubuntu-24.04-arm, arm64, legacy, ./docker/Dockerfile.Legacy)
🔇 Additional comments (3)
src/lib/xbot_monitoring/src/capabilities.h (3)

1-1: Excellent fix for the header guard issue!

Using #pragma once is a clean, modern solution that addresses the previous review concern about missing header guards.


3-3: Verify that the nlohmann/json library is available in the build environment.

The static analysis tool reports that the file cannot be found, which is likely a false positive since the analyzer doesn't have access to the full build environment. However, please confirm that the nlohmann/json library is properly included in your project's dependencies.


5-7: Great fix for the ODR violation!

The use of inline const (C++17) is the correct approach to define the constant in the header without causing linker errors when included in multiple translation units. The implementation looks clean and the use of ordered_json ensures consistent key ordering when published via MQTT.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/lib/xbot_monitoring/src/xbot_monitoring.cpp (1)

274-276: Consider BSON publishing for consistency.

The implementation is correct and follows the established pattern. However, other metadata functions (e.g., publish_version, publish_actions, publish_sensor_metadata) publish both JSON and BSON formats, while capabilities publishes only JSON.

This is likely intentional given the PR's emphasis on simplicity, but consider whether BSON publishing should be added for consistency with other metadata endpoints.

If BSON publishing is desired for consistency, apply this diff:

 void publish_capabilities() {
   try_publish("capabilities/json", CAPABILITIES.dump(2), true);
+  json data;
+  data["d"] = CAPABILITIES;
+  auto bson = json::to_bson(data);
+  try_publish_binary("capabilities/bson", bson.data(), bson.size(), true);
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12e0e1e and e745b3f.

📒 Files selected for processing (2)
  • src/lib/xbot_monitoring/src/capabilities.h (1 hunks)
  • src/lib/xbot_monitoring/src/xbot_monitoring.cpp (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: rovo89
Repo: ClemensElflein/open_mower_ros PR: 252
File: src/lib/xbot_rpc/msg/RpcRequest.msg:1-3
Timestamp: 2025-10-27T23:20:49.662Z
Learning: In the open_mower_ros xbot_rpc system, the xbot_monitoring node acts as the JSON-RPC 2.0 gateway between MQTT and internal ROS messaging. The RpcRequest.msg, RpcResponse.msg, and RpcError.msg are internal ROS message formats and do not need to include the "jsonrpc" field because xbot_monitoring handles JSON-RPC 2.0 protocol compliance at the MQTT boundary.
🪛 Clang (14.0.6)
src/lib/xbot_monitoring/src/capabilities.h

[error] 1-1: 'nlohmann/json.hpp' file not found

(clang-diagnostic-error)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build (ubuntu-24.04-arm, arm64, default, ./docker/Dockerfile)
  • GitHub Check: build (ubuntu-24.04, amd64, legacy, ./docker/Dockerfile.Legacy)
  • GitHub Check: build (ubuntu-24.04, amd64, default, ./docker/Dockerfile)
  • GitHub Check: build (ubuntu-24.04-arm, arm64, legacy, ./docker/Dockerfile.Legacy)
🔇 Additional comments (4)
src/lib/xbot_monitoring/src/xbot_monitoring.cpp (4)

29-29: LGTM!

The include is properly positioned and follows the existing include structure.


33-33: LGTM!

The forward declaration follows the existing pattern and is appropriately placed with other publish function declarations.


79-79: LGTM!

Calling publish_capabilities() on MQTT connection is the right approach, and placing it first ensures clients can discover capabilities before other data arrives.


269-269: LGTM!

Publishing version JSON to version/json improves consistency with the new capabilities/json topic while maintaining backward compatibility by continuing to publish BSON to version.

Comment thread src/lib/xbot_monitoring/src/capabilities.h
The idea is to have a map of capabilities that make it easy for apps to
check what the mower supports, without having to compare versions.

For simplicity in usage, the capabilities should be represented by a
simple, flat object with the respective capabilities as keys and the
"generation" as value. It starts with 1 when the capability gets added
and increases whenever a significant change was done.
@rovo89 rovo89 force-pushed the feat/capabilities branch from e745b3f to 7c2e841 Compare November 5, 2025 22:00
@rovo89 rovo89 merged commit a57cbd0 into main Nov 5, 2025
6 checks passed
@rovo89 rovo89 deleted the feat/capabilities branch November 5, 2025 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant