mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 06:32:06 +00:00
Remove status topic (#4305)
This commit is contained in:
parent
f9d79964ef
commit
dadf9234e5
@ -10,6 +10,8 @@ typedef uint32_t NodeNum;
|
|||||||
typedef uint32_t PacketId; // A packet sequence number
|
typedef uint32_t PacketId; // A packet sequence number
|
||||||
|
|
||||||
#define NODENUM_BROADCAST UINT32_MAX
|
#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_OK 0
|
||||||
#define ERRNO_NO_INTERFACES 33
|
#define ERRNO_NO_INTERFACES 33
|
||||||
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
|
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
|
||||||
|
@ -188,12 +188,10 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
|
|||||||
mqtt = this;
|
mqtt = this;
|
||||||
|
|
||||||
if (*moduleConfig.mqtt.root) {
|
if (*moduleConfig.mqtt.root) {
|
||||||
statusTopic = moduleConfig.mqtt.root + statusTopic;
|
|
||||||
cryptTopic = moduleConfig.mqtt.root + cryptTopic;
|
cryptTopic = moduleConfig.mqtt.root + cryptTopic;
|
||||||
jsonTopic = moduleConfig.mqtt.root + jsonTopic;
|
jsonTopic = moduleConfig.mqtt.root + jsonTopic;
|
||||||
mapTopic = moduleConfig.mqtt.root + mapTopic;
|
mapTopic = moduleConfig.mqtt.root + mapTopic;
|
||||||
} else {
|
} else {
|
||||||
statusTopic = "msh" + statusTopic;
|
|
||||||
cryptTopic = "msh" + cryptTopic;
|
cryptTopic = "msh" + cryptTopic;
|
||||||
jsonTopic = "msh" + jsonTopic;
|
jsonTopic = "msh" + jsonTopic;
|
||||||
mapTopic = "msh" + mapTopic;
|
mapTopic = "msh" + mapTopic;
|
||||||
@ -216,7 +214,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
|
|||||||
enabled = true;
|
enabled = true;
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
reconnectCount = 0;
|
reconnectCount = 0;
|
||||||
publishStatus();
|
publishNodeInfo();
|
||||||
}
|
}
|
||||||
// preflightSleepObserver.observe(&preflightSleep);
|
// preflightSleepObserver.observe(&preflightSleep);
|
||||||
} else {
|
} else {
|
||||||
@ -281,7 +279,7 @@ void MQTT::reconnect()
|
|||||||
runASAP = true;
|
runASAP = true;
|
||||||
reconnectCount = 0;
|
reconnectCount = 0;
|
||||||
|
|
||||||
publishStatus();
|
publishNodeInfo();
|
||||||
return; // Don't try to connect directly to the server
|
return; // Don't try to connect directly to the server
|
||||||
}
|
}
|
||||||
#if HAS_NETWORKING
|
#if HAS_NETWORKING
|
||||||
@ -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,
|
LOG_INFO("Attempting to connect directly to MQTT server %s, port: %d, username: %s, password: %s\n", serverAddr,
|
||||||
serverPort, mqttUsername, mqttPassword);
|
serverPort, mqttUsername, mqttPassword);
|
||||||
|
|
||||||
auto myStatus = (statusTopic + owner.id);
|
bool connected = pubSub.connect(owner.id, mqttUsername, mqttPassword);
|
||||||
bool connected = pubSub.connect(owner.id, mqttUsername, mqttPassword, myStatus.c_str(), 1, true, "offline");
|
|
||||||
if (connected) {
|
if (connected) {
|
||||||
LOG_INFO("MQTT connected\n");
|
LOG_INFO("MQTT connected\n");
|
||||||
enabled = true; // Start running background process again
|
enabled = true; // Start running background process again
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
reconnectCount = 0;
|
reconnectCount = 0;
|
||||||
|
|
||||||
publishStatus();
|
publishNodeInfo();
|
||||||
sendSubscriptions();
|
sendSubscriptions();
|
||||||
} else {
|
} else {
|
||||||
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
||||||
@ -437,14 +434,10 @@ int32_t MQTT::runOnce()
|
|||||||
return 30000;
|
return 30000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FIXME, include more information in the status text
|
void MQTT::publishNodeInfo()
|
||||||
void MQTT::publishStatus()
|
|
||||||
{
|
{
|
||||||
auto myStatus = (statusTopic + owner.id);
|
// TODO: NodeInfo broadcast over MQTT only (NODENUM_BROADCAST_NO_LORA)
|
||||||
bool ok = publish(myStatus.c_str(), "online", true);
|
|
||||||
LOG_INFO("published online=%d\n", ok);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MQTT::publishQueuedMessages()
|
void MQTT::publishQueuedMessages()
|
||||||
{
|
{
|
||||||
if (!mqttQueue.isEmpty()) {
|
if (!mqttQueue.isEmpty()) {
|
||||||
|
@ -81,10 +81,9 @@ class MQTT : private concurrency::OSThread
|
|||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string statusTopic = "/2/stat/"; // For "online"/"offline" message
|
std::string cryptTopic = "/2/e/"; // msh/2/e/CHANNELID/NODEID
|
||||||
std::string cryptTopic = "/2/e/"; // msh/2/e/CHANNELID/NODEID
|
std::string jsonTopic = "/2/json/"; // msh/2/json/CHANNELID/NODEID
|
||||||
std::string jsonTopic = "/2/json/"; // msh/2/json/CHANNELID/NODEID
|
std::string mapTopic = "/2/map/"; // For protobuf-encoded MapReport messages
|
||||||
std::string mapTopic = "/2/map/"; // For protobuf-encoded MapReport messages
|
|
||||||
|
|
||||||
// For map reporting (only applies when enabled)
|
// For map reporting (only applies when enabled)
|
||||||
const uint32_t default_map_position_precision = 14; // defaults to max. offset of ~1459m
|
const uint32_t default_map_position_precision = 14; // defaults to max. offset of ~1459m
|
||||||
@ -110,9 +109,10 @@ class MQTT : private concurrency::OSThread
|
|||||||
/// Called when a new publish arrives from the MQTT server
|
/// Called when a new publish arrives from the MQTT server
|
||||||
std::string meshPacketToJson(meshtastic_MeshPacket *mp);
|
std::string meshPacketToJson(meshtastic_MeshPacket *mp);
|
||||||
|
|
||||||
void publishStatus();
|
|
||||||
void publishQueuedMessages();
|
void publishQueuedMessages();
|
||||||
|
|
||||||
|
void publishNodeInfo();
|
||||||
|
|
||||||
// Check if we should report unencrypted information about our node for consumption by a map
|
// Check if we should report unencrypted information about our node for consumption by a map
|
||||||
void perhapsReportToMap();
|
void perhapsReportToMap();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user