From fdc85d16f95993fe9a9d0905e3f3eff7945dfe13 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 10 Jun 2018 22:59:46 +0200 Subject: [PATCH] const vars --- src/examples/mqttBridge/MqttMeshBridge.h | 27 +++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/examples/mqttBridge/MqttMeshBridge.h b/src/examples/mqttBridge/MqttMeshBridge.h index e331259..7fff530 100644 --- a/src/examples/mqttBridge/MqttMeshBridge.h +++ b/src/examples/mqttBridge/MqttMeshBridge.h @@ -7,10 +7,13 @@ #include "App.h" #include "MeshNet.h" -#define MQTT_CLIENT_NAME "meshBridge" -#define MQTT_BROKER_HOST "citadel.lan" -#define MQTT_BROKER_PORT 1883 -#define MQTT_TOPIC_ROOT "mesh" +#define MQTT_CLIENT_NAME "meshBridge" +#define MQTT_BROKER_HOST "citadel.lan" +#define MQTT_BROKER_PORT 1883 +#define MQTT_TOPIC_ROOT "mesh" +#define MQTT_TOPIC_FROM "mesh/from/" +#define MQTT_TOPIC_FROM_GATEWAY "mesh/from/gateway" +#define MQTT_TOPIC_TO_ALL "mesh/to/#" using namespace std; using namespace std::placeholders; @@ -19,12 +22,12 @@ WiFiClient wifiClient; class MqttMeshBridge : public App { public: - Task connectTask; - Task processTask; MeshNet* net; PubSubClient* client; + Task connectTask; + Task processTask; - MqttMeshBridge() /* : App(sprkt) */ { + MqttMeshBridge() { } void activate(Scheduler* scheduler, Network* network) { @@ -58,15 +61,15 @@ class MqttMeshBridge : public App { if (!client->connected()) { if (client->connect(MQTT_CLIENT_NAME)) { Serial.println("MQTT connected"); - client->publish("mesh/from/gateway","Ready!"); - client->subscribe("mesh/to/#"); + client->publish(MQTT_TOPIC_FROM_GATEWAY,"Ready!"); + client->subscribe(MQTT_TOPIC_TO_ALL); } } } void receivedCallback( uint32_t from, String &msg ) { Serial.printf("bridge: Received from %u msg=%s\n", from, msg.c_str()); - String topic = "mesh/from/" + String(from); + String topic = MQTT_TOPIC_FROM + String(from); client->publish(topic.c_str(), msg.c_str()); } @@ -82,7 +85,7 @@ class MqttMeshBridge : public App { if(targetStr == "gateway"){ if(msg == "getNodes") { - client->publish("mesh/from/gateway", net->mesh.subConnectionJson().c_str()); + client->publish(MQTT_TOPIC_FROM_GATEWAY, net->mesh.subConnectionJson().c_str()); } } else if(targetStr == "broadcast") { net->mesh.sendBroadcast(msg); @@ -91,7 +94,7 @@ class MqttMeshBridge : public App { if(net->mesh.isConnected(target)){ net->mesh.sendSingle(target, msg); } else { - client->publish("mesh/from/gateway", "Client not connected!"); + client->publish(MQTT_TOPIC_FROM_GATEWAY, "Client not connected!"); } } }