Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,17 @@ The expected command payload is :
{
"faulted": false
}
```
```


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": "<cmd>"
}
```
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
42 changes: 42 additions & 0 deletions src/chargepoint/mqtt/MqttManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<ocpp::types::CiStringType<50u>> keys;
std::vector<ocpp::types::KeyValue> values;
std::vector<ocpp::types::CiStringType<50u>> 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<rapidjson::StringBuffer> 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<ConnectorData>& connectors)
{
Expand Down
5 changes: 5 additions & 0 deletions src/chargepoint/mqtt/MqttManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class MqttManager : public IMqttClient::IListener
/** @brief Publish the data of the connectors */
void publishData(const std::vector<ConnectorData>& connectors);

/** @brief Publish the ocpp config of the charge point */
void publishOcppConfig();

private:
/** @brief Configuration */
SimulatedChargePointConfig& m_config;
Expand All @@ -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;

Expand Down