diff --git a/docs/MQTTCommunication.md b/docs/MQTTCommunication.md index b052bc50..a17b628c 100644 --- a/docs/MQTTCommunication.md +++ b/docs/MQTTCommunication.md @@ -23,7 +23,8 @@ The payload contains the actual variable data in the `data` field. ```json { - "data": + "data": , + "msg_type": "Var" } ``` @@ -41,12 +42,15 @@ The following structure applies for command topics. Modules that provide (implem ```json { - "id": "", - "args": { - "arg1": "value1", - "arg2": "value2" + "data": { + "id": "", + "args": { + "arg1": "value1", + "arg2": "value2" + }, + "origin": "" }, - "origin": "" + "msg_type": "Cmd" } ``` @@ -66,13 +70,12 @@ The following structure applies for command response topics. These are used to s ```json { - "name": "", - "type": "result", "data": { - "id": "", - "retval": , - "origin": "" - } + "id": , + "origin": , + "retval": + }, + "msg_type": "CmdResult" } ``` @@ -80,16 +83,12 @@ The following structure applies for command response topics. These are used to s ```json { - "name": "", - "type": "result", "data": { - "id": "", - "error": { - "event": "", - "msg": "" - }, - "origin": "" - } + "id": , + "origin": , + "error": + }, + "msg_type": "CmdResult" } ``` @@ -111,24 +110,32 @@ The following structure applies for error topics. Errors are raised by modules a ### Topic Structure ```bash -{everest_prefix}modules/{module_id}/impl/{impl_id}/error/{error_type} +{everest_prefix}modules/{module_id}/impl/{impl_id}/error/{error_namespace}/{error_type} ``` ### Message Payload Structure ```json { - "type": "/", - "message": "", - "severity": "", - "origin": { - "module_id": "", - "implementation_id": "", - "evse": , - "connector": + "data": { + "description": "", + "message": "", + "origin": { + "implementation_id": "", + "mapping": { + "evse": 1 + }, + "module_id": "" + }, + "severity": "", + "state": "", + "sub_type": "", + "timestamp": "", + "type": "", + "uuid": "", + "vendor_id": "" }, - "state": "", - "timestamp": "", - "uuid": "" + "msg_type": "RaiseError" } ``` + diff --git a/lib/everest.cpp b/lib/everest.cpp index 559280c1..24fcab23 100644 --- a/lib/everest.cpp +++ b/lib/everest.cpp @@ -493,8 +493,7 @@ void Everest::publish_var(const std::string& impl_id, const std::string& var_nam const auto var_topic = fmt::format("{}/var/{}", this->config.mqtt_prefix(this->module_id, impl_id), var_name); - const json var_publish_data = {{"data", value}}; - MqttMessagePayload payload{MqttMessageType::Var, var_publish_data}; + MqttMessagePayload payload{MqttMessageType::Var, value}; // FIXME(kai): implement an efficient way of choosing qos for each variable this->mqtt_abstraction->publish(var_topic, payload, QOS::QOS2); @@ -976,9 +975,7 @@ void Everest::provide_cmd(const std::string& impl_id, const std::string& cmd_nam res_data["error"] = error.value(); } - const json res_publish_data = json::object({{"type", "result"}, {"data", res_data}}); - - MqttMessagePayload payload{MqttMessageType::CmdResult, res_publish_data}; + MqttMessagePayload payload{MqttMessageType::CmdResult, res_data}; const auto final_cmd_response_topic = fmt::format("{}/response/{}", cmd_topic, data.at("origin").get()); this->mqtt_abstraction->publish(final_cmd_response_topic, payload); diff --git a/lib/message_handler.cpp b/lib/message_handler.cpp index f1d044fe..348609a7 100644 --- a/lib/message_handler.cpp +++ b/lib/message_handler.cpp @@ -268,7 +268,7 @@ void MessageHandler::register_handler(const std::string& topic, std::shared_ptr< // Private message handler methods void MessageHandler::handle_var_message(const std::string& topic, const json& data) { execute_handlers_from_vector(var_handlers, topic, - [&](const auto& handler) { (*handler->handler)(topic, data.at("data")); }); + [&](const auto& handler) { (*handler->handler)(topic, data); }); } void MessageHandler::handle_cmd_message(const std::string& topic, const json& data) { @@ -306,7 +306,7 @@ void MessageHandler::handle_module_ready_message(const std::string& topic, const } void MessageHandler::handle_cmd_result(const std::string& topic, const json& payload) { - const auto& data = payload.at("data").at("data"); + const auto& data = payload.at("data"); const auto id = data.at("id").get(); std::shared_ptr handler_copy;