41 #include <picofuse/net/types.h> 54 #define NET_MQTT_PORT 1883 62 #ifndef NET_MQTT_TOPIC_CAPACITY 63 #define NET_MQTT_TOPIC_CAPACITY 8 75 #ifndef NET_MQTT_TOPIC_FILTER_SIZE 76 #define NET_MQTT_TOPIC_FILTER_SIZE 128 122 const char *username;
124 const char *password;
126 uint16_t keepalive_s;
517 const void *payload,
size_t payload_len,
518 net_mqtt_qos_t qos,
bool retain);
net_mqtt_t * net_mqtt_init(const net_addr_t *addr, uint16_t port, uint32_t timeout_ms, const net_mqtt_config_t *config)
Initialize an MQTT client instance.
A well-formed reply arrived that doesn't match anything currently pending (wrong packet id...
const char * topic
Topic the message was published to - may be more specific than the net_mqtt_subscribe() filter that m...
size_t net_mqtt_error_to_string(const net_mqtt_error_t *error, char *buf, size_t buf_size)
Format a net_mqtt_event_error payload as a human-readable string.
bool net_mqtt_connect(net_mqtt_t *mqtt)
Open the MQTT connection.
uint32_t net_mqtt_subscribe(net_mqtt_t *mqtt, const char *topic, net_mqtt_qos_t qos)
Stage a subscription to a topic filter, waiting for room to do so.
net_mqtt_qos_t
Delivery guarantee for a published or subscribed message.
Payload for a net_mqtt_event_unsubscribed event.
Not tied to a specific operation - a packet this client doesn't recognize at all arrived on the wire...
The broker sent something this client couldn't parse as a valid packet.
net_mqtt_event_type_t
Event payload tag for net_mqtt_event_t.
uint32_t message_id
The id net_mqtt_publish() returned for the call this event completes - lets a caller with several pub...
void net_mqtt_default_config(net_mqtt_config_t *config)
Fill an MQTT config struct with safe defaults.
Payload for a net_mqtt_event_received event.
uint32_t message_id
The id net_mqtt_publish()/net_mqtt_subscribe()/ net_mqtt_unsubscribe() returned for the call this err...
const char * topic
Topic that was published to.
void net_mqtt_disconnect(net_mqtt_t *mqtt)
Close the MQTT connection.
bool retain
True if this is a retained message delivered because of the subscription itself rather than a live pu...
uint32_t net_mqtt_publish(net_mqtt_t *mqtt, const char *topic, const void *payload, size_t payload_len, net_mqtt_qos_t qos, bool retain)
Stage a message to publish to a topic, waiting for room to do so.
Payload for a net_mqtt_event_sent event.
Exactly once - slowest, a four-way handshake under the hood.
void(* net_mqtt_event_callback_t)(net_mqtt_t *mqtt, const net_mqtt_event_t *event, void *userdata)
Called for every event on an MQTT client instance.
Delivery of an incoming PUBLISH (see net_mqtt_event_received) - not tied to any of this client's own ...
net_mqtt_subscribe()'s own write, or its SUBACK reply.
Payload for a net_mqtt_event_subscribed event.
net_mqtt_publish()'s own write, or its PUBACK/PUBREC/PUBREL/PUBCOMP reply chain.
bool net_mqtt_unsubscribe(net_mqtt_t *mqtt, uint32_t topic_id)
Stage removal of a confirmed subscription, waiting for room to do so.
net_mqtt_error_kind_t kind
Coarse category - see net_mqtt_error_kind_t.
net_mqtt_connect() succeeded - carries no payload.
A single MQTT client event.
void net_mqtt_deinit(net_mqtt_t *mqtt)
Release a handle from net_mqtt_init().
net_mqtt_unsubscribe()'s own write, or its UNSUBACK reply.
void net_mqtt_set_callback(net_mqtt_t *mqtt, net_mqtt_event_callback_t callback, void *userdata)
Register the callback for events on an MQTT client instance.
A net_mqtt_subscribe() call completed - see net_mqtt_subscribed_t.
The connection closed, whether from net_mqtt_disconnect() or an unexpected drop noticed during net_po...
uint32_t topic_id
The topic_id that was passed to net_mqtt_unsubscribe() - not that call's own (now-spent) return value...
net_mqtt_qos_t granted_qos
The QoS the broker actually granted for.
This client's own automatic keepalive PINGREQ/PINGRESP.
Payload for a net_mqtt_event_error event.
A write to the connection itself failed.
const char * client_id
MQTT client identifier sent in CONNECT.
At least once - acknowledged, but may be delivered more than once.
struct net_mqtt_t net_mqtt_t
Opaque handle identifying an MQTT client instance.
net_mqtt_error_action_t
Which operation a net_mqtt_event_error event happened during.
A net_mqtt_publish() call completed - see net_mqtt_sent_t.
net_mqtt_event_type_t type
Event payload tag.
const char * net_mqtt_topic_to_string(net_mqtt_t *mqtt, uint32_t topic_id)
Look up the topic filter behind a confirmed subscription.
At most once - fire and forget, no acknowledgment.
The broker explicitly rejected the request (e.g.
A message arrived on a subscribed topic - see net_mqtt_received_t.
net_mqtt_error_kind_t
Coarse category for a net_mqtt_event_error event.
Something failed - see net_mqtt_error_t.
A net_mqtt_unsubscribe() call completed - see net_mqtt_unsubscribed_t.
No reply arrived within timeout_ms.
net_mqtt_error_action_t action
Which operation - see net_mqtt_error_action_t.