mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 05:02:21 +01:00
const vars
This commit is contained in:
@@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user