S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_mqtt_transport_layer.h
Go to the documentation of this file.
1/*
2 * Licensed to Systerel under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work
4 * for additional information regarding copyright ownership.
5 * Systerel licenses this file to you under the Apache
6 * License, Version 2.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain
8 * a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/* This module implements MQTT Transport Protocol */
21
22#ifndef SOPC_MQTT
23#define SOPC_MQTT
24
25#include <stdio.h>
26#include <string.h>
27
28#include "sopc_atomic.h"
29#include "sopc_mem_alloc.h"
30#include "sopc_mutexes.h"
31#include "sopc_pubsub_conf.h"
33#include "sopc_threads.h"
34#include "sopc_time_reference.h"
35#include "sopc_types.h"
36
37/* MQTT connection hard coded configuration */
38
39#define MQTT_LIB_QOS (2) /* QOS of publish, subscribe set to 2*/
40#define MQTT_LIB_MAX_SIZE_TOPIC_NAME (256) /* Maximum length of a topic */
41#define MQTT_LIB_MAX_NB_TOPIC_NAME (256) /* Maximum subscriber topics that can be handle by client */
42#define MQTT_LIB_CONNECTION_TIMEOUT (4) /* Connection lib timeout = 4 s*/
43#define MQTT_LIB_KEEPALIVE (4) /* Connection lost detection set to 4 s*/
44
45typedef struct MQTT_CONTEXT_CLIENT MqttContextClient; /* MQTT context client */
46
58
59/* Callback called to notify a message reception. */
60
61typedef void FctMessageReceived(uint8_t* data,
62 uint16_t size,
63 void* pUser);
74SOPC_ReturnStatus SOPC_MQTT_Send_Message(MqttContextClient* contextClient, const char* topic, SOPC_Buffer message);
75
93 const char* uri,
94 const char* username,
95 const char* password,
96 const char** subTopic,
97 uint16_t nbSubTopic,
98 FctMessageReceived* cbMessageReceived,
99 SOPC_PubSub_OnFatalError* cbFatalError,
100 void* userContext);
101
109
116
125
133
134#endif
A platform independent API for atomic integer operations.
enum _SOPC_ReturnStatus SOPC_ReturnStatus
Common enumerations for S2OPC.
S2OPC memory allocation wrappers.
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 wi...
void FctMessageReceived(uint8_t *data, uint16_t size, void *pUser)
Definition sopc_mqtt_transport_layer.h:61
MQTT_CLIENT_STATE
Definition sopc_mqtt_transport_layer.h:48
@ SOPC_MQTT_CLIENT_CONNECTED
Definition sopc_mqtt_transport_layer.h:54
@ SOPC_MQTT_CLIENT_UNITIALIZED
Definition sopc_mqtt_transport_layer.h:49
@ SOPC_MQTT_CLIENT_INITIALIZED
Definition sopc_mqtt_transport_layer.h:51
@ SOPC_MQTT_CLIENT_FAILED_CONNECT
Definition sopc_mqtt_transport_layer.h:55
@ SOPC_MQTT_CLIENT_DISCONNECTED
Definition sopc_mqtt_transport_layer.h:53
@ SOPC_MQTT_CLIENT_LOST_CONNECTION
Definition sopc_mqtt_transport_layer.h:56
struct MQTT_CONTEXT_CLIENT MqttContextClient
Definition sopc_mqtt_transport_layer.h:45
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 clie...
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.
SOPC_ReturnStatus SOPC_MQTT_Create_Client(MqttContextClient **contextClient)
Allocate memory for MQTT context client. Must be freed with SOPC_MQTT_Release_Client.
enum MQTT_CLIENT_STATE MqttClientState
void SOPC_MQTT_Release_Client(MqttContextClient *contextClient)
Disconnect from server and free MQTT client context pointer.
void SOPC_PubSub_OnFatalError(void *userContext, const char *message)
Definition sopc_pubsub_conf.h:73
A platform independent API to handle time reference management.
Bytes buffer structure.
Definition sopc_buffer.h:38