diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bc0045f15..102782696 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -15,15 +15,9 @@
-
-
-
-
-
-
-
-
+
+
@@ -55,11 +49,6 @@
-
-
-
-
-
@@ -78,6 +67,11 @@
+
+
+
+
+
@@ -112,6 +106,7 @@
+
@@ -144,9 +139,14 @@
- file://$USER_HOME$/.platformio/packages/framework-portduino/libraries/WiFi/src/WiFiClient.cpp
- 49
-
+ file://$PROJECT_DIR$/src/mqtt/MQTT.cpp
+ 84
+
+
+
+ file://$PROJECT_DIR$/.pio/libdeps/native/PubSubClient/src/PubSubClient.cpp
+ 468
+
diff --git a/bin/mqtt-listen.sh b/bin/mqtt-listen.sh
index f7d8458c0..60779ec7e 100755
--- a/bin/mqtt-listen.sh
+++ b/bin/mqtt-listen.sh
@@ -1 +1 @@
-mosquitto_sub -h test.mosquitto.org -v -t mesh/\#
+mosquitto_sub -h test.mosquitto.org -v -t mesh/\# -F "%j"
diff --git a/docs/software/TODO.md b/docs/software/TODO.md
index 2ae568069..e3d768093 100644
--- a/docs/software/TODO.md
+++ b/docs/software/TODO.md
@@ -53,6 +53,10 @@ You probably don't care about this section - skip to the next one.
## MQTT
+* reply to MC
+* reply to question about MQTT
+* add test case of preencrypting in the python tool (and sending through a node that lacks keys)
+* leave encrypted messages as forwarded (need fixes on both tx and rx sides)
* DONE have sim provide a fake wifi connection status saying connected
* DONE don't start MQTT if we don't have wifi connected
* have plugin send uplinks from mesh
diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp
index 6a731f7ea..40e0938b9 100644
--- a/src/mqtt/MQTT.cpp
+++ b/src/mqtt/MQTT.cpp
@@ -1,6 +1,7 @@
#include "MQTT.h"
#include "MQTTPlugin.h"
#include "NodeDB.h"
+#include "main.h"
#include "mesh/generated/mqtt.pb.h"
#include
#include
@@ -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...
diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h
index 39652a11d..f3e7b2639 100644
--- a/src/mqtt/MQTT.h
+++ b/src/mqtt/MQTT.h
@@ -2,6 +2,7 @@
#include "configuration.h"
+#include "concurrency/OSThread.h"
#include
#include
@@ -9,7 +10,7 @@
* Our wrapper/singleton for sending/receiving MQTT "udp" packets. This object isolates the MQTT protocol implementation from
* the two components that use it: MQTTPlugin and MQTTSimInterface.
*/
-class MQTT
+class MQTT : private concurrency::OSThread
{
// supposedly the current version is busted:
// http://www.iotsharing.com/2017/08/how-to-use-esp32-mqtts-with-mqtts-mosquitto-broker-tls-ssl.html
@@ -25,6 +26,9 @@ class MQTT
*/
void publish(const MeshPacket &mp);
+ protected:
+ virtual int32_t runOnce();
+
private:
const char *getCryptTopic(const char *channelId);
};