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.

Return

lwespOK on success, member of lwespr_t otherwise

Parameters
  • [in] c: Cayenne handle

  • [in] evt: Event handle

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_RLWESP_OK

Response OK

enumerator LWESP_CAYENNE_RLWESP_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

Return

lwespOK on success, member of lwespr_t otherwise

Parameters
  • [in] c: Cayenne empty handle

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

  • [in] evt_fn: Event function

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

Subscribe to cayenne based topics and channels.

Return

lwespOK on success, member of lwespr_t otherwise

Parameters
  • [in] c: Cayenne handle

  • [in] topic: Cayenne topic

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

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)
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.

Return

lwespOK on success, member of lwespr_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 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