Skip to content

Commit

Permalink
Remove status topic
Browse files Browse the repository at this point in the history
  • Loading branch information
thebentern committed Jul 21, 2024
1 parent f25644e commit 1dc542b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/mesh/MeshTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ typedef uint32_t NodeNum;
typedef uint32_t PacketId; // A packet sequence number

#define NODENUM_BROADCAST UINT32_MAX
#define NODENUM_BROADCAST_NO_LORA \
1 // Reserved to only deliver packets over high speed (non-lora) transports, such as MQTT or BLE mesh (not yet implemented)
#define ERRNO_OK 0
#define ERRNO_NO_INTERFACES 33
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
Expand Down
19 changes: 6 additions & 13 deletions src/mqtt/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,10 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
mqtt = this;

if (*moduleConfig.mqtt.root) {
statusTopic = moduleConfig.mqtt.root + statusTopic;
cryptTopic = moduleConfig.mqtt.root + cryptTopic;
jsonTopic = moduleConfig.mqtt.root + jsonTopic;
mapTopic = moduleConfig.mqtt.root + mapTopic;
} else {
statusTopic = "msh" + statusTopic;
cryptTopic = "msh" + cryptTopic;
jsonTopic = "msh" + jsonTopic;
mapTopic = "msh" + mapTopic;
Expand All @@ -216,7 +214,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
enabled = true;
runASAP = true;
reconnectCount = 0;
publishStatus();
publishNodeInfo();
}
// preflightSleepObserver.observe(&preflightSleep);
} else {
Expand Down Expand Up @@ -281,7 +279,7 @@ void MQTT::reconnect()
runASAP = true;
reconnectCount = 0;

publishStatus();
publishNodeInfo();
return; // Don't try to connect directly to the server
}
#if HAS_NETWORKING
Expand Down Expand Up @@ -330,15 +328,14 @@ void MQTT::reconnect()
LOG_INFO("Attempting to connect directly to MQTT server %s, port: %d, username: %s, password: %s\n", serverAddr,
serverPort, mqttUsername, mqttPassword);

auto myStatus = (statusTopic + owner.id);
bool connected = pubSub.connect(owner.id, mqttUsername, mqttPassword, myStatus.c_str(), 1, true, "offline");
bool connected = pubSub.connect(owner.id, mqttUsername, mqttPassword);
if (connected) {
LOG_INFO("MQTT connected\n");
enabled = true; // Start running background process again
runASAP = true;
reconnectCount = 0;

publishStatus();
publishNodeInfo();
sendSubscriptions();
} else {
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
Expand Down Expand Up @@ -437,14 +434,10 @@ int32_t MQTT::runOnce()
return 30000;
}

/// FIXME, include more information in the status text
void MQTT::publishStatus()
void MQTT::publishNodeInfo()
{
auto myStatus = (statusTopic + owner.id);
bool ok = publish(myStatus.c_str(), "online", true);
LOG_INFO("published online=%d\n", ok);
// TODO: NodeInfo broadcast over MQTT only (NODENUM_BROADCAST_NO_LORA)
}

void MQTT::publishQueuedMessages()
{
if (!mqttQueue.isEmpty()) {
Expand Down
10 changes: 5 additions & 5 deletions src/mqtt/MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ class MQTT : private concurrency::OSThread
virtual int32_t runOnce() override;

private:
std::string statusTopic = "/2/stat/"; // For "online"/"offline" message
std::string cryptTopic = "/2/e/"; // msh/2/e/CHANNELID/NODEID
std::string jsonTopic = "/2/json/"; // msh/2/json/CHANNELID/NODEID
std::string mapTopic = "/2/map/"; // For protobuf-encoded MapReport messages
std::string cryptTopic = "/2/e/"; // msh/2/e/CHANNELID/NODEID
std::string jsonTopic = "/2/json/"; // msh/2/json/CHANNELID/NODEID
std::string mapTopic = "/2/map/"; // For protobuf-encoded MapReport messages

// For map reporting (only applies when enabled)
const uint32_t default_map_position_precision = 14; // defaults to max. offset of ~1459m
Expand All @@ -110,9 +109,10 @@ class MQTT : private concurrency::OSThread
/// Called when a new publish arrives from the MQTT server
std::string meshPacketToJson(meshtastic_MeshPacket *mp);

void publishStatus();
void publishQueuedMessages();

void publishNodeInfo();

// Check if we should report unencrypted information about our node for consumption by a map
void perhapsReportToMap();

Expand Down

0 comments on commit 1dc542b

Please sign in to comment.