Cayenne MQTT API

group LWESP_APP_CAYENNE_API

MQTT client API for Cayenne.

Defines

LWESP_CAYENNE_API_VERSION

Cayenne API version in string.

LWESP_CAYENNE_HOST

Cayenne host server.

LWESP_CAYENNE_PORT

Cayenne port number.

LWESP_CAYENNE_NO_CHANNEL

No channel macro

LWESP_CAYENNE_ALL_CHANNELS

All channels macro

Typedefs

typedef lwespr_t (*lwesp_cayenne_evt_fn)(struct lwesp_cayenne *c, lwesp_cayenne_evt_t *evt)

Cayenne event callback function.

Parameters
  • c[in] Cayenne handle

  • evt[in] Event handle

Returns

lwespOK on success, member of lwespr_t otherwise

Enums

enum lwesp_cayenne_topic_t

List of possible cayenne topics.

Values:

enumerator LWESP_CAYENNE_TOPIC_DATA

Data topic

enumerator LWESP_CAYENNE_TOPIC_COMMAND

Command topic

enumerator LWESP_CAYENNE_TOPIC_CONFIG
enumerator LWESP_CAYENNE_TOPIC_RESPONSE
enumerator LWESP_CAYENNE_TOPIC_SYS_MODEL
enumerator LWESP_CAYENNE_TOPIC_SYS_VERSION
enumerator LWESP_CAYENNE_TOPIC_SYS_CPU_MODEL
enumerator LWESP_CAYENNE_TOPIC_SYS_CPU_SPEED
enumerator LWESP_CAYENNE_TOPIC_DIGITAL
enumerator LWESP_CAYENNE_TOPIC_DIGITAL_COMMAND
enumerator LWESP_CAYENNE_TOPIC_DIGITAL_CONFIG
enumerator LWESP_CAYENNE_TOPIC_ANALOG
enumerator LWESP_CAYENNE_TOPIC_ANALOG_COMMAND
enumerator LWESP_CAYENNE_TOPIC_ANALOG_CONFIG
enumerator LWESP_CAYENNE_TOPIC_END

Last entry

enum lwesp_cayenne_rlwesp_t

Cayenne response types.

Values:

enumerator LWESP_CAYENNE_RESP_OK

Response OK

enumerator LWESP_CAYENNE_RESP_ERROR

Response error

enum lwesp_cayenne_evt_type_t

Cayenne events.

Values:

enumerator LWESP_CAYENNE_EVT_CONNECT

Connect to Cayenne event

enumerator LWESP_CAYENNE_EVT_DISCONNECT

Disconnect from Cayenne event

enumerator LWESP_CAYENNE_EVT_DATA

Data received event

Functions

lwespr_t lwesp_cayenne_create(lwesp_cayenne_t *c, const lwesp_mqtt_client_info_t *client_info, lwesp_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

Parameters
  • c[in] Cayenne empty handle

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

  • evt_fn[in] Event function

Returns

lwespOK on success, member of lwespr_t otherwise

lwespr_t lwesp_cayenne_subscribe(lwesp_cayenne_t *c, lwesp_cayenne_topic_t topic, uint16_t channel)

Subscribe to cayenne based topics and channels.

Parameters
  • c[in] Cayenne handle

  • topic[in] Cayenne topic

  • channel[in] Optional channel number. Use LWESP_CAYENNE_NO_CHANNEL when channel is not needed or LWESP_CAYENNE_ALL_CHANNELS to subscribe to all channels

Returns

lwespOK on success, member of lwespr_t otherwise

lwespr_t lwesp_cayenne_publish_data(lwesp_cayenne_t *c, lwesp_cayenne_topic_t topic, uint16_t channel, const char *type, const char *unit, const char *data)

Publish data to cayenne cloud.

Parameters
  • c[in] Cayenne handle

  • topic[in] Cayenne specific topic to publish on

  • channel[in] Device channel to publish on

  • type[in] Data type, string format, for example temp for temperature. Set to NULL if not used

  • unit[in] Data unit, string format, for example c for celcius. Set to NULL if not used

  • data[in] Actual data, for example 127 for 127 degrees

Returns

lwespOK on success, member of lwespr_t otherwise

lwespr_t lwesp_cayenne_publish_float(lwesp_cayenne_t *c, lwesp_cayenne_topic_t topic, uint16_t channel, const char *type, const char *unit, float f)
lwespr_t lwesp_cayenne_publish_response(lwesp_cayenne_t *c, lwesp_cayenne_msg_t *msg, lwesp_cayenne_rlwesp_t resp, const char *message)

Publish response message to command.

Parameters
  • c[in] Cayenne handle

  • msg[in] Received message with command topic

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

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

Returns

lwespOK on success, member of lwespr_t otherwise

struct lwesp_cayenne_key_value_t
#include <lwesp_cayenne.h>

Key/Value pair structure.

Public Members

const char *key

Key string

const char *value

Value string

struct lwesp_cayenne_msg_t
#include <lwesp_cayenne.h>

Cayenne message.

Public Members

lwesp_cayenne_topic_t topic

Message topic

uint16_t channel

Message channel, optional, based on topic type

const char *seq

Sequence string on command

lwesp_cayenne_key_value_t values[2]

Key/Value pair of values

size_t values_count

Count of valid pairs in values member

struct lwesp_cayenne_evt_t
#include <lwesp_cayenne.h>

Cayenne event.

Public Members

lwesp_cayenne_evt_type_t type

Event type

lwesp_cayenne_msg_t *msg

Pointer to data message

struct lwesp_cayenne_evt_t::[anonymous]::[anonymous] data

Data event, used with LWESP_CAYENNE_EVT_DATA event

union lwesp_cayenne_evt_t::[anonymous] evt

Event union

struct lwesp_cayenne_t
#include <lwesp_cayenne.h>

Cayenne handle.

Public Members

lwesp_mqtt_client_api_p api_c

MQTT API client

const lwesp_mqtt_client_info_t *info_c

MQTT Client info structure

lwesp_cayenne_msg_t msg

Received data message

lwesp_cayenne_evt_t evt

Event handle

lwesp_cayenne_evt_fn evt_fn

Event callback function

lwesp_sys_thread_t thread

Cayenne thread handle

lwesp_sys_sem_t sem

Sync semaphore handle