![]() |
BSB Developer Docs
|
MQTT & BUSY account service API. More...
Go to the source code of this file.
Data Structures | |
| struct | MqttProperty |
| Data type for a single MQTT property. More... | |
| struct | MqttEventLinkPinReceived |
Data type describing the event of type MqttEventTypeLinkPinReceived. More... | |
| struct | MqttEventStatusChanged |
Data type describing the event of type MqttEventTypeStatusChanged. More... | |
| struct | MqttEvent |
| Data type describing the generic MQTT service event, complete with type and specific data. More... | |
| struct | MqttSessionInfo |
| Data type for a linked account information. More... | |
Macros | |
| #define | RECORD_MQTT "mqtt" |
| The string key for MQTT instance access. | |
| #define | MQTT_LINK_PIN_LEN (4) |
| The length of the link PIN string. | |
Typedefs | |
| typedef struct Mqtt | Mqtt |
| Opaque data type for the MQTT service instance. | |
| typedef struct MqttMessage | MqttMessage |
| Opaque data type for the MQTT message object. | |
| typedef struct MqttSubscription | MqttSubscription |
| Opaque data type for the MQTT subscription object. | |
| typedef void(* | MqttSubscriptionCallback) (const MqttMessage *message, void *context) |
| Subscription callback function type. | |
Enumerations | |
| enum | MqttPropertyType { MqttPropertyTypeExpiryInterval , MqttPropertyTypeResponseTopic , MqttPropertyTypeCorrelationData , MqttPropertyTypeMax } |
| Enumeration of available property types. More... | |
| enum | MqttEventType { MqttEventTypeStatusChanged , MqttEventTypeLinkPinReceived , MqttEventTypeLinkDone , MqttEventTypeUnlinked , MqttEventTypeMax } |
| Enumeration of possible event types emitted by the MQTT service. More... | |
| enum | MqttStatus { MqttStatusError , MqttStatusNotConnected , MqttStatusConnectedNotLinked , MqttStatusConnectedLinked , MqttStatusMax } |
| Enumeration of possible states that the MQTT service can be in. More... | |
| enum | MqttQos { MqttQosAtMostOnce = 0 , MqttQosAtLeastOnce = 1 , MqttQosExactlyOnce = 2 , MqttQosMax } |
| Enumeration of possible MQTT QoS (Quality of Service) levels. More... | |
Functions | |
| FuriPubSub * | mqtt_get_pubsub (Mqtt *instance) |
| Get the pointer to the associated FuriPubSub object. | |
| MqttStatus | mqtt_get_status (Mqtt *instance) |
| Get the current status of the MQTT service. | |
| bool | mqtt_request_link_pin (Mqtt *instance) |
| Request the account linking PIN from the BUSY cloud. | |
| void | mqtt_unlink (Mqtt *instance) |
| Unlink the device from the BUSY account. | |
| void | mqtt_get_session_info (Mqtt *instance, MqttSessionInfo *info) |
| Get current session information. | |
| void | mqtt_get_config (Mqtt *instance, MqttConfig *config) |
| Get the current backend configuration. | |
| bool | mqtt_set_config (Mqtt *instance, const MqttConfig *config) |
| Set the backend configuration. | |
| bool | mqtt_publish (Mqtt *instance, MqttQos qos, const char *topic, const void *data, size_t data_size) |
| Publish a message to a topic on the MQTT broker. | |
| bool | mqtt_publish_ex (Mqtt *instance, MqttQos qos, const char *topic, const void *data, size_t data_size, const MqttProperty *props, uint32_t props_count) |
| Publish a message to a topic on the MQTT broker with additional properties. | |
| MqttSubscription * | mqtt_subscribe (Mqtt *instance, MqttQos qos, const char *topic, MqttSubscriptionCallback callback, void *context) |
| Subscribe to a topic on the MQTT broker and start receiving messages. | |
| void | mqtt_unsubscribe (Mqtt *instance, MqttSubscription *subscription) |
| Unsubscribe from a topic on the MQTT broker and stop receiving messages. | |
| const void * | mqtt_message_get_data (const MqttMessage *message, size_t *data_size) |
| Get the payload (data) contained in a MqttMessage object. | |
| bool | mqtt_message_get_string_property (const MqttMessage *message, MqttPropertyType property_type, FuriString *value) |
| Get the string property possibly attached to a MqttMessage object. | |
| bool | mqtt_message_get_integer_property (const MqttMessage *message, MqttPropertyType property_type, uint32_t *value) |
| Get the integer property possibly attached to a MqttMessage object. | |
MQTT & BUSY account service API.
The MQTT service is responsible for:
Limitations:
Topic format: With the below API, subscription/publishing is only possible on the session topic.
Internally, MQTT session topics have the following format:
sessions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/down/v1/topic/name for subscriptionssessions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/up/v1/topic/name for publishingwhere aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee is a unique session identifier.
The MQTT service API abstracts it so the application must use only the topic/name part when interacting with it. This rule also applies to some MQTT message properties such as Response Topic (see below).
Data lifetime:
| #define RECORD_MQTT "mqtt" |
The string key for MQTT instance access.
Get the instance pointer by calling furi_record_open(RECORD_MQTT);
| typedef struct Mqtt Mqtt |
Opaque data type for the MQTT service instance.
Get the instance pointer by calling furi_record_open(RECORD_MQTT);
| typedef void(* MqttSubscriptionCallback) (const MqttMessage *message, void *context) |
Subscription callback function type.
A function with this signature may be used to deliver MQTT messages via invoking the mqtt_subscribe() API.
message parameter is only valid within the context of the callback it was delivered in.| [in] | message | pointer to the delivered message |
| [in,out] | context | pointer to the user-specific object (set during subscribing) |
| enum MqttEventType |
Enumeration of possible event types emitted by the MQTT service.
| enum MqttPropertyType |
Enumeration of available property types.
See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901029 for reference.
| enum MqttQos |
Enumeration of possible MQTT QoS (Quality of Service) levels.
See https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718099 for reference.
| Enumerator | |
|---|---|
| MqttQosAtMostOnce | Deliver at most once (lowest) |
| MqttQosAtLeastOnce | Deliver at least once. |
| MqttQosExactlyOnce | Deliver exactly once (highest) |
| MqttQosMax | Special value, internal use. |
| enum MqttStatus |
Enumeration of possible states that the MQTT service can be in.
| void mqtt_get_config | ( | Mqtt * | instance, |
| MqttConfig * | config ) |
Get the current backend configuration.
| [in] | instance | pointer to the MQTT service instance to be queried |
| [out] | config | pointer to a MqttConfig structure to contain the result (must be allocated) |
| FuriPubSub * mqtt_get_pubsub | ( | Mqtt * | instance | ) |
Get the pointer to the associated FuriPubSub object.
Use furi_pubsub_subscribe() to subscribe to the MQTT service events. The delivered events will be of type MqttEvent.
| [in,out] | instance | pointer to the MQTT service instance |
| void mqtt_get_session_info | ( | Mqtt * | instance, |
| MqttSessionInfo * | info ) |
Get current session information.
| [in] | instance | pointer to the MQTT service instance to be queried |
| [in,out] | info | pointer to the MqttSessionInfo structure |
| MqttStatus mqtt_get_status | ( | Mqtt * | instance | ) |
Get the current status of the MQTT service.
| [in] | instance | pointer to the MQTT service instance to be queried |
| const void * mqtt_message_get_data | ( | const MqttMessage * | message, |
| size_t * | data_size ) |
Get the payload (data) contained in a MqttMessage object.
data_size may be NULL if it is not required.| [in] | message | pointer to the MqttMessage object to be queried |
| [out] | data_size | pointer to the value to contain the size (length) of the data |
| bool mqtt_message_get_integer_property | ( | const MqttMessage * | message, |
| MqttPropertyType | property_type, | ||
| uint32_t * | value ) |
Get the integer property possibly attached to a MqttMessage object.
property_type MUST correspond to the underlying integer data type.| [in] | message | pointer to the MqttMessage object to be queried |
| [in] | property_type | value from the MqttPropertyType enum denoting the property type |
| [out] | value | pointer to an integer variable to contain the value (must be allocated) |
property_type was found, false otherwise | bool mqtt_message_get_string_property | ( | const MqttMessage * | message, |
| MqttPropertyType | property_type, | ||
| FuriString * | value ) |
Get the string property possibly attached to a MqttMessage object.
property_type MUST correspond to the underlying string data type.| [in] | message | pointer to the MqttMessage object to be queried |
| [in] | property_type | value from the MqttPropertyType enum denoting the property type |
| [out] | value | pointer to a FuriString object to contain the value (must be allocated) |
property_type was found, false otherwise | bool mqtt_publish | ( | Mqtt * | instance, |
| MqttQos | qos, | ||
| const char * | topic, | ||
| const void * | data, | ||
| size_t | data_size ) |
Publish a message to a topic on the MQTT broker.
topic/name in the above example| [in,out] | instance | pointer to the MQTT service instance |
| [in] | qos | enum value from MqttQos corresponding to a QoS level |
| [in] | topic | C-string containing the specific topic part |
| [in] | data | pointer to arbitrary data to be published |
| [in] | data_size | size (or length) of the data to be published |
true if publishing was successful, false otherwise | bool mqtt_publish_ex | ( | Mqtt * | instance, |
| MqttQos | qos, | ||
| const char * | topic, | ||
| const void * | data, | ||
| size_t | data_size, | ||
| const MqttProperty * | props, | ||
| uint32_t | props_count ) |
Publish a message to a topic on the MQTT broker with additional properties.
topic/name in the above example| [in,out] | instance | pointer to the MQTT service instance |
| [in] | qos | enum value from MqttQos corresponding to a QoS level |
| [in] | topic | C-string containing the specific topic part |
| [in] | data | pointer to arbitrary data to be published |
| [in] | data_size | size (or length) of the data to be published |
| [in] | props | pointer to the array of MQTT message properties |
| [in] | props_count | number of properties contained in the props array |
true if publishing was successful, false otherwise | bool mqtt_request_link_pin | ( | Mqtt * | instance | ) |
Request the account linking PIN from the BUSY cloud.
MqttEventTypeLinkPinReceived event.| [in,out] | instance | pointer to the MQTT service instance |
| bool mqtt_set_config | ( | Mqtt * | instance, |
| const MqttConfig * | config ) |
Set the backend configuration.
| [in,out] | instance | pointer to the MQTT service instance to be modified |
| [in] | config | pointer to a MqttConfig structure containing the configuration to be set |
true if the configuration could be successfully set, false otherwise | MqttSubscription * mqtt_subscribe | ( | Mqtt * | instance, |
| MqttQos | qos, | ||
| const char * | topic, | ||
| MqttSubscriptionCallback | callback, | ||
| void * | context ) |
Subscribe to a topic on the MQTT broker and start receiving messages.
topic/name in the above example| [in,out] | instance | pointer to the MQTT service instance |
| [in] | qos | enum value from MqttQos corresponding to a QoS level |
| [in] | topic | C-string containing the specific topic part |
| [in] | callback | pointer to the function used to asynchronously deliver MQTT messages |
| [in,out] | context | pointer to a user-specific object (will be passed to the callback) |
| void mqtt_unlink | ( | Mqtt * | instance | ) |
Unlink the device from the BUSY account.
| [in,out] | instance | pointer to the MQTT service instance |
| void mqtt_unsubscribe | ( | Mqtt * | instance, |
| MqttSubscription * | subscription ) |
Unsubscribe from a topic on the MQTT broker and stop receiving messages.
| [in,out] | instance | pointer to the MQTT service instance |
| [in,out] | subscription | pointer to the target subscription object |