#include <stdio.h>
#include <string.h>
#include "sopc_atomic.h"
#include "sopc_mem_alloc.h"
#include "sopc_mutexes.h"
#include "sopc_pubsub_conf.h"
#include "sopc_pubsub_constants.h"
#include "sopc_threads.h"
#include "sopc_time_reference.h"
#include "sopc_types.h"
Go to the source code of this file.
|
SOPC_ReturnStatus | SOPC_MQTT_Send_Message (MqttContextClient *contextClient, const char *topic, SOPC_Buffer message) |
| Send message to topic destination with MQTT client, contextClient must be successfully initialized with SOPC_MQTT_InitializeAndConnect_Client before using this function.
|
|
SOPC_ReturnStatus | SOPC_MQTT_InitializeAndConnect_Client (MqttContextClient *contextClient, const char *uri, const char *username, const char *password, const char **subTopic, uint16_t nbSubTopic, FctMessageReceived *cbMessageReceived, SOPC_PubSub_OnFatalError *cbFatalError, void *userContext) |
| Initialize MQTT client and connection, Shall be called after SOPC_MQTT_Create_Client To use MQTT client as a subscriber, number of sub topic must be superior to 0 and Topics to subscribe can't be NULL.
|
|
SOPC_ReturnStatus | SOPC_MQTT_Create_Client (MqttContextClient **contextClient) |
| Allocate memory for MQTT context client. Must be freed with SOPC_MQTT_Release_Client.
|
|
void | SOPC_MQTT_Release_Client (MqttContextClient *contextClient) |
| Disconnect from server and free MQTT client context pointer.
|
|
bool | SOPC_MQTT_Client_Is_Connected (MqttContextClient *contextClient) |
| Return if client is connected or not.
|
|
MqttClientState | SOPC_MQTT_Client_Get_State (MqttContextClient *contextClient) |
| Return state of the client.
|
|
◆ MQTT_LIB_QOS
#define MQTT_LIB_QOS (2) /* QOS of publish, subscribe set to 2*/ |
◆ MQTT_LIB_MAX_SIZE_TOPIC_NAME
#define MQTT_LIB_MAX_SIZE_TOPIC_NAME (256) /* Maximum length of a topic */ |
◆ MQTT_LIB_MAX_NB_TOPIC_NAME
#define MQTT_LIB_MAX_NB_TOPIC_NAME (256) /* Maximum subscriber topics that can be handle by client */ |
◆ MQTT_LIB_CONNECTION_TIMEOUT
#define MQTT_LIB_CONNECTION_TIMEOUT (4) /* Connection lib timeout = 4 s*/ |
◆ MQTT_LIB_KEEPALIVE
#define MQTT_LIB_KEEPALIVE (4) /* Connection lost detection set to 4 s*/ |
◆ MqttContextClient
◆ MqttClientState
◆ FctMessageReceived
typedef void FctMessageReceived(uint8_t *data, uint16_t size, void *pUser) |
Connection context
- Parameters
-
data | Data received |
size | Size of data received in bytes |
◆ MQTT_CLIENT_STATE
Enumerator |
---|
SOPC_MQTT_CLIENT_UNITIALIZED | Client isn't initialized with function SOPC_MQTT_InitializeAndConnect_Client
|
SOPC_MQTT_CLIENT_INITIALIZED | Client is successfully initialized with function SOPC_MQTT_InitializeAndConnect_Client
|
SOPC_MQTT_CLIENT_DISCONNECTED | Client is disconnected
|
SOPC_MQTT_CLIENT_CONNECTED | Client is successfully connected
|
SOPC_MQTT_CLIENT_FAILED_CONNECT | Client failed to connect
|
SOPC_MQTT_CLIENT_LOST_CONNECTION | Client lost connection
|
◆ SOPC_MQTT_Send_Message()
Send message to topic destination with MQTT client, contextClient must be successfully initialized with SOPC_MQTT_InitializeAndConnect_Client before using this function.
- Parameters
-
contextClient | Context for MQTT library containing MQTT client |
topic | Topic destination |
message | Buffer with message information |
- Returns
- SOPC_STATUS_OK if succeed sending message, SOPC_STATUS_NOK otherwise
◆ SOPC_MQTT_InitializeAndConnect_Client()
Initialize MQTT client and connection, Shall be called after SOPC_MQTT_Create_Client To use MQTT client as a subscriber, number of sub topic must be superior to 0 and Topics to subscribe can't be NULL.
- Parameters
-
contextClient | Context for MQTT library containing MQTT client |
uri | Uri to broker endpoint |
username | Username identifier optional. Can be NULL |
password | Password required if identifier. Can be NULL |
subTopic | Array of topics to subscribe, can be NULL |
nbSubTopic | Number of topics to subscribe, can be NULL |
cbMessageReceived | Callback of message reception |
cbFatalError | Callback for broker disconnection |
userContext | Connection context of user (Passed to cbFatalError and cbMessageReceived) |
- Returns
- SOPC_STATUS_OK if succeed to initialize mqtt contextClient, SOPC_STATUS_NOK if failed to create a mqtt Client or failed to connect
◆ SOPC_MQTT_Create_Client()
◆ SOPC_MQTT_Release_Client()
Disconnect from server and free MQTT client context pointer.
- Parameters
-
contextClient | MQTT client context |
◆ SOPC_MQTT_Client_Is_Connected()
Return if client is connected or not.
- Parameters
-
- Returns
- true if client is connected
-
false if client is not connected or if parameters are invalid
◆ SOPC_MQTT_Client_Get_State()
Return state of the client.
- Parameters
-
- Returns
- MqttClientState state of client. Refers to enum description