Embedded Wireless Framework
ewf_adapter_api_mqtt.h
Go to the documentation of this file.
1 /************************************************************************/
9 #ifndef __ewf_adapter_mqtt__h__included__
10 #define __ewf_adapter_mqtt__h__included__
11 
12 #include "ewf.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /************************************************************************/
27 struct ewf_socket_mqtt;
28 typedef struct ewf_socket_mqtt ewf_socket_mqtt;
29 
31 typedef enum _ewf_adapter_mqtt_qos ewf_adapter_mqtt_qos;
32 
35 
43 typedef ewf_result(*ewf_adapter_mqtt_state_callback)(ewf_socket_mqtt* socket_ptr, const char* state_cstr, const char* param_cstr);
44 
50 typedef ewf_result(*ewf_adapter_mqtt_message_callback)(ewf_socket_mqtt* socket_ptr, const char* topic_str, ewf_adapter_mqtt_message* message_ptr);
51 
54 {
55  void* data_ptr;
56  ewf_adapter* adapter_ptr;
57  ewf_adapter_mqtt_state_callback state_callback;
58  ewf_adapter_mqtt_message_callback message_callback;
59 };
60 
63 {
64  ewf_adapter_mqtt_qos_0 = 0,
65  ewf_adapter_mqtt_qos_1 = 1,
66  ewf_adapter_mqtt_qos_2 = 2,
67 
68  ewf_adapter_mqtt_qos_error = -1,
69 };
70 
73 {
74  uint16_t ID;
75  uint8_t DUP;
76  ewf_adapter_mqtt_qos QoS;
77  uint8_t RETAIN;
78  uint32_t payload_length;
79  void* payload_ptr;
80 };
81 
83 typedef struct _ewf_adapter_api_mqtt
84 {
85  ewf_result(*control)(ewf_socket_mqtt* socket_ptr, const char* command_cstr, const char* param_cstr);
86  ewf_result(*query)(ewf_socket_mqtt* socket_ptr, const char* command_cstr, uint8_t* buffer_ptr, uint32_t* buffer_length_ptr);
87 
88  ewf_result(*open)(ewf_adapter* adapter_ptr, ewf_socket_mqtt* socket_ptr);
89  ewf_result(*close)(ewf_socket_mqtt* socket_ptr);
90  ewf_result(*set_tls_configuration)(ewf_socket_mqtt* socket_ptr, uint32_t tls_configuration_id);
91  ewf_result(*connect)(ewf_socket_mqtt* socket_ptr, const char* server_str, uint32_t port, const char* clientid_str, const char* username_str, const char* password_str);
92  ewf_result(*disconnect)(ewf_socket_mqtt* socket_ptr);
93  ewf_result(*publish_string)(ewf_socket_mqtt* socket_ptr, const char* topic_str, const char* message_str);
94  ewf_result(*publish_buffer)(ewf_socket_mqtt* socket_ptr, const char* topic_str, const uint8_t* message_ptr, uint32_t message_size);
95  ewf_result(*publish_message)(ewf_socket_mqtt* socket_ptr, const char* topic_str, const ewf_adapter_mqtt_message* message_ptr);
96  ewf_result(*subscribe)(ewf_socket_mqtt* socket_ptr, const char* topic);
97  ewf_result(*unsubscribe)(ewf_socket_mqtt* socket_ptr, const char* topic);
98 
99  ewf_result(*set_message_state)(ewf_socket_mqtt* socket_ptr, ewf_adapter_mqtt_state_callback callback);
100  ewf_result(*set_message_callback)(ewf_socket_mqtt* socket_ptr, ewf_adapter_mqtt_message_callback callback);
101 
103 
111 
118 
124 ewf_result ewf_adapter_mqtt_set_tls_configuration(ewf_socket_mqtt* socket_ptr, uint32_t tls_configuration_id);
125 
131 ewf_result ewf_adapter_mqtt_connect(ewf_socket_mqtt* socket_ptr, const char * server_str, uint32_t port, const char * clientid_str, const char * username_str, const char * password_str);
132 
139 
145 ewf_result ewf_adapter_mqtt_publish_string(ewf_socket_mqtt* socket_ptr, const char* topic_str, const char* message_str);
146 
152 ewf_result ewf_adapter_mqtt_publish_buffer(ewf_socket_mqtt* socket_ptr, const char* topic_str, const uint8_t* message_ptr, uint32_t message_size);
153 
159 ewf_result ewf_adapter_mqtt_publish_message(ewf_socket_mqtt* socket_ptr, const char* topic_str, const ewf_adapter_mqtt_message* message_ptr);
160 
168 ewf_result ewf_adapter_mqtt_subscribe(ewf_socket_mqtt* socket_ptr, const char * topic_str, ewf_adapter_mqtt_qos qos);
169 
177 ewf_result ewf_adapter_mqtt_subscribe_with_result(ewf_socket_mqtt* socket_ptr, const char* topic_str, ewf_adapter_mqtt_qos* qos_ptr);
178 
184 ewf_result ewf_adapter_mqtt_unsubscribe(ewf_socket_mqtt* socket_ptr, const char * topic_str);
185 
193 
201 
202 /************************************************************************/
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 #endif /* __ewf_adapter_mqtt__h__included__ */
The Embedded Wireless Framework.
ewf_result ewf_adapter_mqtt_publish_message(ewf_socket_mqtt *socket_ptr, const char *topic_str, const ewf_adapter_mqtt_message *message_ptr)
Publish a message to to a topic.
ewf_result(* ewf_adapter_mqtt_message_callback)(ewf_socket_mqtt *socket_ptr, const char *topic_str, ewf_adapter_mqtt_message *message_ptr)
A function pointer type for MQTT message callbacks.
Definition: ewf_adapter_api_mqtt.h:50
ewf_result ewf_adapter_mqtt_subscribe(ewf_socket_mqtt *socket_ptr, const char *topic_str, ewf_adapter_mqtt_qos qos)
Subscribe to a topic.
ewf_result ewf_adapter_mqtt_state_callback_set(ewf_socket_mqtt *socket_ptr, ewf_adapter_mqtt_state_callback callback)
Register a callback for state changes.
ewf_result ewf_adapter_mqtt_open(ewf_adapter *adapter_ptr, ewf_socket_mqtt *socket_ptr)
Open an MQTT socket.
ewf_result ewf_adapter_mqtt_publish_buffer(ewf_socket_mqtt *socket_ptr, const char *topic_str, const uint8_t *message_ptr, uint32_t message_size)
Publish a message to to a topic.
ewf_result ewf_adapter_mqtt_publish_string(ewf_socket_mqtt *socket_ptr, const char *topic_str, const char *message_str)
Publish a message to to a topic.
ewf_result ewf_adapter_mqtt_subscribe_with_result(ewf_socket_mqtt *socket_ptr, const char *topic_str, ewf_adapter_mqtt_qos *qos_ptr)
Subscribe to a topic.
struct _ewf_adapter_api_mqtt ewf_adapter_api_mqtt
ewf_result ewf_adapter_mqtt_connect(ewf_socket_mqtt *socket_ptr, const char *server_str, uint32_t port, const char *clientid_str, const char *username_str, const char *password_str)
Connect to an MQTT server.
ewf_result ewf_adapter_mqtt_unsubscribe(ewf_socket_mqtt *socket_ptr, const char *topic_str)
Unsubscribe from a topic.
ewf_result ewf_adapter_mqtt_disconnect(ewf_socket_mqtt *socket_ptr)
Disconnect from an MQTT server.
_ewf_adapter_mqtt_qos
The MQTT QoS enumeration definition.
Definition: ewf_adapter_api_mqtt.h:63
ewf_result ewf_adapter_mqtt_set_tls_configuration(ewf_socket_mqtt *socket_ptr, uint32_t tls_configuration_id)
Set the TLS context for the socket.
ewf_result ewf_adapter_mqtt_close(ewf_socket_mqtt *socket_ptr)
Close an MQTT socket.
ewf_result ewf_adapter_mqtt_message_callback_set(ewf_socket_mqtt *socket_ptr, ewf_adapter_mqtt_message_callback callback)
Register a callback for subscribed messages.
ewf_result(* ewf_adapter_mqtt_state_callback)(ewf_socket_mqtt *socket_ptr, const char *state_cstr, const char *param_cstr)
A function pointer type for MQTT basic API state callbacks.
Definition: ewf_adapter_api_mqtt.h:43
enum _ewf_result ewf_result
Success and error result codes specific to the EWF API.
Definition: ewf_adapter_api_mqtt.h:84
The MQTT Message structure definition.
Definition: ewf_adapter_api_mqtt.h:73
The EWF network adapter control structure definition.
Definition: ewf_adapter.h:50
The MQTT socket structure definition.
Definition: ewf_adapter_api_mqtt.h:54