Cayenne MQTT API

group ESP_APP_CAYENNE_API

MQTT client API for Cayenne.

Defines

ESP_CAYENNE_API_VERSION

Cayenne API version in string.

ESP_CAYENNE_HOST

Cayenne host server.

ESP_CAYENNE_PORT

Cayenne port number.

ESP_CAYENNE_NO_CHANNEL

No channel macro

ESP_CAYENNE_ALL_CHANNELS

All channels macro

Typedefs

typedef espr_t (*esp_cayenne_evt_fn)(struct esp_cayenne *c, esp_cayenne_evt_t *evt)

Cayenne event callback function.

Return

espOK on success, member of espr_t otherwise

Parameters
  • [in] c: Cayenne handle

  • [in] evt: Event handle

Enums

enum esp_cayenne_topic_t

List of possible cayenne topics.

Values:

ESP_CAYENNE_TOPIC_DATA

Data topic

ESP_CAYENNE_TOPIC_COMMAND

Command topic

ESP_CAYENNE_TOPIC_CONFIG
ESP_CAYENNE_TOPIC_RESPONSE
ESP_CAYENNE_TOPIC_SYS_MODEL
ESP_CAYENNE_TOPIC_SYS_VERSION
ESP_CAYENNE_TOPIC_SYS_CPU_MODEL
ESP_CAYENNE_TOPIC_SYS_CPU_SPEED
ESP_CAYENNE_TOPIC_DIGITAL
ESP_CAYENNE_TOPIC_DIGITAL_COMMAND
ESP_CAYENNE_TOPIC_DIGITAL_CONFIG
ESP_CAYENNE_TOPIC_ANALOG
ESP_CAYENNE_TOPIC_ANALOG_COMMAND
ESP_CAYENNE_TOPIC_ANALOG_CONFIG
ESP_CAYENNE_TOPIC_END

Last entry

enum esp_cayenne_resp_t

Cayenne response types.

Values:

ESP_CAYENNE_RESP_OK

Response OK

ESP_CAYENNE_RESP_ERROR

Response error

enum esp_cayenne_evt_type_t

Cayenne events.

Values:

ESP_CAYENNE_EVT_CONNECT

Connect to Cayenne event

ESP_CAYENNE_EVT_DISCONNECT

Disconnect from Cayenne event

ESP_CAYENNE_EVT_DATA

Data received event

Functions

espr_t esp_cayenne_create(esp_cayenne_t *c, const esp_mqtt_client_info_t *client_info, esp_cayenne_evt_fn evt_fn)

Create new instance of cayenne MQTT connection.

Note

Each call to this functions starts new thread for async receive processing. Function will block until thread is created and successfully started

Return

espOK on success, member of espr_t otherwise

Parameters
  • [in] c: Cayenne empty handle

  • [in] client_info: MQTT client info with username, password and id

  • [in] evt_fn: Event function

espr_t esp_cayenne_subscribe(esp_cayenne_t *c, esp_cayenne_topic_t topic, uint16_t channel)

Subscribe to cayenne based topics and channels.

Return

espOK on success, member of espr_t otherwise

Parameters
  • [in] c: Cayenne handle

  • [in] topic: Cayenne topic

  • [in] channel: Optional channel number. Use ESP_CAYENNE_NO_CHANNEL when channel is not needed or ESP_CAYENNE_ALL_CHANNELS to subscribe to all channels

espr_t esp_cayenne_publish_data(esp_cayenne_t *c, esp_cayenne_topic_t topic, uint16_t channel, const char *type, const char *unit, const char *data)
espr_t esp_cayenne_publish_float(esp_cayenne_t *c, esp_cayenne_topic_t topic, uint16_t channel, const char *type, const char *unit, float f)
espr_t esp_cayenne_publish_response(esp_cayenne_t *c, esp_cayenne_msg_t *msg, esp_cayenne_resp_t resp, const char *message)

Publish response message to command.

Return

espOK on success, member of espr_t otherwise

Parameters
  • [in] c: Cayenne handle

  • [in] msg: Received message with command topic

  • [in] resp: Response type, either OK or ERROR

  • [in] message: Message text in case of error to be displayed to Cayenne dashboard

struct esp_cayenne_key_value_t
#include <esp_cayenne.h>

Key/Value pair structure.

Public Members

const char *key

Key string

const char *value

Value string

struct esp_cayenne_msg_t
#include <esp_cayenne.h>

Cayenne message.

Public Members

esp_cayenne_topic_t topic

Message topic

uint16_t channel

Message channel, optional, based on topic type

const char *seq

Sequence string on command

esp_cayenne_key_value_t values[2]

Key/Value pair of values

size_t values_count

Count of valid pairs in values member

struct esp_cayenne_evt_t
#include <esp_cayenne.h>

Cayenne event.

Public Members

esp_cayenne_evt_type_t type

Event type

esp_cayenne_msg_t *msg

Pointer to data message

struct esp_cayenne_evt_t::[anonymous]::[anonymous] data

Data event, used with ESP_CAYENNE_EVT_DATA event

union esp_cayenne_evt_t::[anonymous] evt

Event union

struct esp_cayenne_t
#include <esp_cayenne.h>

Cayenne handle.

Public Members

esp_mqtt_client_api_p api_c

MQTT API client

const esp_mqtt_client_info_t *info_c

MQTT Client info structure

esp_cayenne_msg_t msg

Received data message

esp_cayenne_evt_t evt

Event handle

esp_cayenne_evt_fn evt_fn

Event callback function

esp_sys_thread_t thread

Cayenne thread handle

esp_sys_sem_t sem

Sync semaphore handle