Skip to content

Commit 8180b04

Browse files
authored
Merge pull request #13 from c-jimenez/dev/mqtt_send_ocpp_config
add new command to Charge Point to send on MQTT its OCPP config
2 parents afb8523 + 5031971 commit 8180b04

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,17 @@ The expected command payload is :
348348
{
349349
"faulted": false
350350
}
351-
```
351+
```
352+
353+
354+
Each simulated Charge Point are listening to the following topic to execute a certain command: **cp_simu/cps/simu_cp_XXX/cmd**.
355+
356+
The expected command payload is :
357+
```
358+
{
359+
"type": "<cmd>"
360+
}
361+
```
362+
So far there are 2 commands:
363+
* close: ask to end the application
364+
* ocpp_config: ask to send on MQTT topic **cp_simu/cps/simu_cp_XXX/ocpp_config** all the OCPP config of the Charge Point

src/chargepoint/mqtt/MqttManager.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ void MqttManager::mqttMessageReceived(const char* topic, const std::string& mess
9999
std::cout << "Close command received" << std::endl;
100100
m_end = true;
101101
}
102+
else if (strcmp(type, "ocpp_config") == 0)
103+
{
104+
publishOcppConfig();
105+
}
102106
}
103107
else
104108
{
@@ -205,6 +209,7 @@ void MqttManager::start(unsigned int nb_phases, unsigned int max_charge_point_cu
205209
std::string chargepoint_tag_topics = chargepoint_topic + "connectors/+/id_tag";
206210
std::string chargepoint_faulted_topics = chargepoint_topic + "connectors/+/faulted";
207211
m_status_topic = chargepoint_topic + "status";
212+
m_ocpp_config_topic = chargepoint_topic + "ocpp_config";
208213
m_connectors_topic = chargepoint_topic + "connectors/";
209214

210215
// MQTT client
@@ -326,6 +331,43 @@ bool MqttManager::publishStatus(const std::string& status, unsigned int nb_phase
326331
return ret;
327332
}
328333

334+
/** @brief Publish the ocpp config of the connectors */
335+
void MqttManager::publishOcppConfig()
336+
{
337+
// Check connectivity
338+
if (m_mqtt->isConnected())
339+
{
340+
// Compute topic name
341+
std::stringstream topic;
342+
topic << m_ocpp_config_topic;
343+
344+
// Get vector of key/value for ocpp config
345+
std::vector<ocpp::types::CiStringType<50u>> keys;
346+
std::vector<ocpp::types::KeyValue> values;
347+
std::vector<ocpp::types::CiStringType<50u>> unknown_values;
348+
m_config.ocppConfig().getConfiguration(keys, values, unknown_values);
349+
350+
// Create the JSON message
351+
rapidjson::Document msg;
352+
msg.Parse("{}");
353+
for (const ocpp::types::KeyValue keyValue : values)
354+
{
355+
if (!keyValue.value.value().empty())
356+
{
357+
rapidjson::Value key(keyValue.key.c_str(), msg.GetAllocator());
358+
rapidjson::Value value(keyValue.value.value().c_str(), msg.GetAllocator());
359+
msg.AddMember(key, value, msg.GetAllocator());
360+
}
361+
}
362+
rapidjson::StringBuffer buffer;
363+
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
364+
msg.Accept(writer);
365+
366+
// Publish
367+
m_mqtt->publish(topic.str(), buffer.GetString(), IMqttClient::QoS::QOS_0, true);
368+
}
369+
}
370+
329371
/** @brief Publish the data of the connectors */
330372
void MqttManager::publishData(const std::vector<ConnectorData>& connectors)
331373
{

src/chargepoint/mqtt/MqttManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class MqttManager : public IMqttClient::IListener
7777
/** @brief Publish the data of the connectors */
7878
void publishData(const std::vector<ConnectorData>& connectors);
7979

80+
/** @brief Publish the ocpp config of the charge point */
81+
void publishOcppConfig();
82+
8083
private:
8184
/** @brief Configuration */
8285
SimulatedChargePointConfig& m_config;
@@ -92,6 +95,8 @@ class MqttManager : public IMqttClient::IListener
9295
IMqttClient* m_mqtt;
9396
/** @brief Status topic */
9497
std::string m_status_topic;
98+
/** @brief Config topic */
99+
std::string m_ocpp_config_topic;
95100
/** @brief Connectors topic */
96101
std::string m_connectors_topic;
97102

0 commit comments

Comments
 (0)