we now send packets to mqtt server

This commit is contained in:
Kevin Hester
2021-04-03 22:27:06 +08:00
parent f3f09f0dcf
commit 638cec7f25
5 changed files with 39 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
#include "MQTT.h"
#include "MQTTPlugin.h"
#include "NodeDB.h"
#include "main.h"
#include "mesh/generated/mqtt.pb.h"
#include <WiFi.h>
#include <assert.h>
@@ -30,7 +31,7 @@ void mqttInit()
}
}
MQTT::MQTT() : pubSub(mqttClient)
MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient)
{
assert(!mqtt);
mqtt = this;
@@ -50,6 +51,8 @@ MQTT::MQTT() : pubSub(mqttClient)
bool connected = pubSub.connect(owner.id, myStatus.c_str(), 1, true, "offline");
if (connected) {
DEBUG_MSG("MQTT connected\n");
enabled = true; // Start running background process again
runASAP = true;
static char subsStr[64]; /* We keep this static because the mqtt lib
might not be copying it */
@@ -62,6 +65,15 @@ MQTT::MQTT() : pubSub(mqttClient)
}
}
int32_t MQTT::runOnce()
{
// If connected poll rapidly, otherwise sleep forever
if (!pubSub.loop())
enabled = false;
return 20;
}
void MQTT::publish(const MeshPacket &mp)
{
// don't bother sending if not connected...