-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmqtt_connection.h
83 lines (72 loc) · 2.45 KB
/
mqtt_connection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. */
#pragma once
#include <applibs/eventloop.h>
#include <applibs/log.h>
#include <applibs/storage.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/select.h>
#include <wolfssl/ssl.h>
#include "mqtt.h"
#include "exitcodes.h"
/// <summary>
///
/// </summary>
typedef struct {
const char *hostname;
const char *port;
const char *subtopic;
uint8_t *sendbuf;
size_t sendbufsz;
uint8_t *recvbuf;
size_t recvbufsz;
} Mqtt_Reconnect_State;
/// <summary>
/// Function to initialize all parameters needed for connecting to Azure Event Grid.
/// </summary>
/// <param name="eventLoop">Event loop reference</param>
/// <param name="publish_callback">Function to call when a message is received on subscribe topic</param>
/// <param name="failureCallback"></param>
/// <param name="mqttContext">MQTT context which has all configuration parameters needed for MQTT
/// connection</param>
/// <returns></returns>
ExitCode InitializeMqtt(EventLoop *eventLoop,
void (*publish_callback)(void **unused,
struct mqtt_response_publish *published),
ExitCode_CallbackType failureCallback,
MQTT_Context *mqttContext);
/// <summary>
/// Send telemetry message to the publish topic. Sends the message only if MQTT is connected.
/// If network is not ready, logs a message and disconnects.
/// </summary>
/// <param name="data">Telemetry message to send</param>
/// <param name="data_length">Length of message to send</param>
/// <param name="topic">Topic to publish the message on</param>
void SendTelemetry(const void *data, size_t data_length, const char *topic);
/// <summary>
/// Disconnect the MQTT connection. Called when application is exiting, or if network is lost.
/// </summary>
/// <param name=""></param>
void DisconnectMqtt(void);
/// <summary>
/// Start the MQTT connection.
/// </summary>
/// <param name=""></param>
void ConnectMqtt(void);
/// <summary>
/// Dispose the timers created for the MQTT connection.
/// </summary>
/// <param name=""></param>
void DisposeMqttTimers(void);
/// <summary>
/// Create the timers needed for the MQTT connection.
/// </summary>
/// <param name=""></param>
void CreateMqttTimers(void);
/// <summary>
/// Get the topic to publish to.
/// </summary>
/// <param name=""></param>
const char *GetPublishTopicName(void);