mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-06 01:48:13 +00:00
we now send packets to mqtt server
This commit is contained in:
@@ -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...
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "configuration.h"
|
||||
|
||||
#include "concurrency/OSThread.h"
|
||||
#include <PubSubClient.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user