diff --git a/README.md b/README.md index a9b8856..df8d631 100644 --- a/README.md +++ b/README.md @@ -348,4 +348,17 @@ The expected command payload is : { "faulted": false } - ``` \ No newline at end of file + ``` + + +Each simulated Charge Point are listening to the following topic to execute a certain command: **cp_simu/cps/simu_cp_XXX/cmd**. + +The expected command payload is : + ``` + { + "type": "" + } + ``` +So far there are 2 commands: +* close: ask to end the application +* ocpp_config: ask to send on MQTT topic **cp_simu/cps/simu_cp_XXX/ocpp_config** all the OCPP config of the Charge Point \ No newline at end of file diff --git a/src/chargepoint/mqtt/MqttManager.cpp b/src/chargepoint/mqtt/MqttManager.cpp index 018f092..a791d75 100644 --- a/src/chargepoint/mqtt/MqttManager.cpp +++ b/src/chargepoint/mqtt/MqttManager.cpp @@ -99,6 +99,10 @@ void MqttManager::mqttMessageReceived(const char* topic, const std::string& mess std::cout << "Close command received" << std::endl; m_end = true; } + else if (strcmp(type, "ocpp_config") == 0) + { + publishOcppConfig(); + } } else { @@ -205,6 +209,7 @@ void MqttManager::start(unsigned int nb_phases, unsigned int max_charge_point_cu std::string chargepoint_tag_topics = chargepoint_topic + "connectors/+/id_tag"; std::string chargepoint_faulted_topics = chargepoint_topic + "connectors/+/faulted"; m_status_topic = chargepoint_topic + "status"; + m_ocpp_config_topic = chargepoint_topic + "ocpp_config"; m_connectors_topic = chargepoint_topic + "connectors/"; // MQTT client @@ -326,6 +331,43 @@ bool MqttManager::publishStatus(const std::string& status, unsigned int nb_phase return ret; } +/** @brief Publish the ocpp config of the connectors */ +void MqttManager::publishOcppConfig() +{ + // Check connectivity + if (m_mqtt->isConnected()) + { + // Compute topic name + std::stringstream topic; + topic << m_ocpp_config_topic; + + // Get vector of key/value for ocpp config + std::vector> keys; + std::vector values; + std::vector> unknown_values; + m_config.ocppConfig().getConfiguration(keys, values, unknown_values); + + // Create the JSON message + rapidjson::Document msg; + msg.Parse("{}"); + for (const ocpp::types::KeyValue keyValue : values) + { + if (!keyValue.value.value().empty()) + { + rapidjson::Value key(keyValue.key.c_str(), msg.GetAllocator()); + rapidjson::Value value(keyValue.value.value().c_str(), msg.GetAllocator()); + msg.AddMember(key, value, msg.GetAllocator()); + } + } + rapidjson::StringBuffer buffer; + rapidjson::Writer writer(buffer); + msg.Accept(writer); + + // Publish + m_mqtt->publish(topic.str(), buffer.GetString(), IMqttClient::QoS::QOS_0, true); + } +} + /** @brief Publish the data of the connectors */ void MqttManager::publishData(const std::vector& connectors) { diff --git a/src/chargepoint/mqtt/MqttManager.h b/src/chargepoint/mqtt/MqttManager.h index bb28920..1531795 100644 --- a/src/chargepoint/mqtt/MqttManager.h +++ b/src/chargepoint/mqtt/MqttManager.h @@ -77,6 +77,9 @@ class MqttManager : public IMqttClient::IListener /** @brief Publish the data of the connectors */ void publishData(const std::vector& connectors); + /** @brief Publish the ocpp config of the charge point */ + void publishOcppConfig(); + private: /** @brief Configuration */ SimulatedChargePointConfig& m_config; @@ -92,6 +95,8 @@ class MqttManager : public IMqttClient::IListener IMqttClient* m_mqtt; /** @brief Status topic */ std::string m_status_topic; + /** @brief Config topic */ + std::string m_ocpp_config_topic; /** @brief Connectors topic */ std::string m_connectors_topic;