mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 05:24:30 +01:00
const vars
This commit is contained in:
@@ -7,10 +7,13 @@
|
|||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include "MeshNet.h"
|
#include "MeshNet.h"
|
||||||
|
|
||||||
#define MQTT_CLIENT_NAME "meshBridge"
|
#define MQTT_CLIENT_NAME "meshBridge"
|
||||||
#define MQTT_BROKER_HOST "citadel.lan"
|
#define MQTT_BROKER_HOST "citadel.lan"
|
||||||
#define MQTT_BROKER_PORT 1883
|
#define MQTT_BROKER_PORT 1883
|
||||||
#define MQTT_TOPIC_ROOT "mesh"
|
#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;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
@@ -19,12 +22,12 @@ WiFiClient wifiClient;
|
|||||||
|
|
||||||
class MqttMeshBridge : public App {
|
class MqttMeshBridge : public App {
|
||||||
public:
|
public:
|
||||||
Task connectTask;
|
|
||||||
Task processTask;
|
|
||||||
MeshNet* net;
|
MeshNet* net;
|
||||||
PubSubClient* client;
|
PubSubClient* client;
|
||||||
|
Task connectTask;
|
||||||
|
Task processTask;
|
||||||
|
|
||||||
MqttMeshBridge() /* : App(sprkt) */ {
|
MqttMeshBridge() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void activate(Scheduler* scheduler, Network* network) {
|
void activate(Scheduler* scheduler, Network* network) {
|
||||||
@@ -58,15 +61,15 @@ class MqttMeshBridge : public App {
|
|||||||
if (!client->connected()) {
|
if (!client->connected()) {
|
||||||
if (client->connect(MQTT_CLIENT_NAME)) {
|
if (client->connect(MQTT_CLIENT_NAME)) {
|
||||||
Serial.println("MQTT connected");
|
Serial.println("MQTT connected");
|
||||||
client->publish("mesh/from/gateway","Ready!");
|
client->publish(MQTT_TOPIC_FROM_GATEWAY,"Ready!");
|
||||||
client->subscribe("mesh/to/#");
|
client->subscribe(MQTT_TOPIC_TO_ALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void receivedCallback( uint32_t from, String &msg ) {
|
void receivedCallback( uint32_t from, String &msg ) {
|
||||||
Serial.printf("bridge: Received from %u msg=%s\n", from, msg.c_str());
|
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());
|
client->publish(topic.c_str(), msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +85,7 @@ class MqttMeshBridge : public App {
|
|||||||
|
|
||||||
if(targetStr == "gateway"){
|
if(targetStr == "gateway"){
|
||||||
if(msg == "getNodes") {
|
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") {
|
} else if(targetStr == "broadcast") {
|
||||||
net->mesh.sendBroadcast(msg);
|
net->mesh.sendBroadcast(msg);
|
||||||
@@ -91,7 +94,7 @@ class MqttMeshBridge : public App {
|
|||||||
if(net->mesh.isConnected(target)){
|
if(net->mesh.isConnected(target)){
|
||||||
net->mesh.sendSingle(target, msg);
|
net->mesh.sendSingle(target, msg);
|
||||||
} else {
|
} 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