firmware/src/mqtt/MQTT.h

45 lines
1.3 KiB
C
Raw Normal View History

#pragma once
#include "configuration.h"
2021-04-03 14:27:06 +00:00
#include "concurrency/OSThread.h"
#include "mesh/Channels.h"
#include <PubSubClient.h>
#include <WiFiClient.h>
/**
* 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.
*/
2021-04-03 14:27:06 +00:00
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
// WiFiClientSecure wifiClient;
WiFiClient mqttClient;
PubSubClient pubSub;
public:
MQTT();
/**
* Publish a packet on the glboal MQTT server.
* This hook must be called **after** the packet is encrypted (including the channel being changed to a hash).
* @param chIndex the index of the channel for this message
*
* Note: for messages we are forwarding on the mesh that we can't find the channel for (because we don't have the keys), we
* can not forward those messages to the cloud - becuase no way to find a global channel ID.
*/
void onSend(const MeshPacket &mp, ChannelIndex chIndex);
2021-04-03 14:27:06 +00:00
protected:
virtual int32_t runOnce();
private:
2021-04-03 08:06:40 +00:00
const char *getCryptTopic(const char *channelId);
};
void mqttInit();
extern MQTT *mqtt;