Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
shell_mqtt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 G-Technologies Sdn. Bhd.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_SHELL_MQTT_H_
14#define ZEPHYR_INCLUDE_SHELL_MQTT_H_
15
16#include <zephyr/kernel.h>
17#include <zephyr/shell/shell.h>
18#include <zephyr/net/socket.h>
19#include <zephyr/net/net_mgmt.h>
22#include <zephyr/net/mqtt.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#define RX_RB_SIZE CONFIG_SHELL_MQTT_RX_BUF_SIZE
30#define TX_BUF_SIZE CONFIG_SHELL_MQTT_TX_BUF_SIZE
31#define SH_MQTT_BUFFER_SIZE 64
32#define DEVICE_ID_BIN_MAX_SIZE 3
33#define DEVICE_ID_HEX_MAX_SIZE ((DEVICE_ID_BIN_MAX_SIZE * 2) + 1)
34#define SH_MQTT_TOPIC_RX_MAX_SIZE DEVICE_ID_HEX_MAX_SIZE + sizeof(CONFIG_SHELL_MQTT_TOPIC_RX_ID)
35#define SH_MQTT_TOPIC_TX_MAX_SIZE DEVICE_ID_HEX_MAX_SIZE + sizeof(CONFIG_SHELL_MQTT_TOPIC_TX_ID)
36
38
46
113
114#define SHELL_MQTT_DEFINE(_name) \
115 static struct shell_mqtt _name##_shell_mqtt; \
116 struct shell_transport _name = { .api = &shell_mqtt_transport_api, \
117 .ctx = (struct shell_mqtt *)&_name##_shell_mqtt }
118
128
141bool shell_mqtt_get_devid(char *id, int id_max_len);
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif /* ZEPHYR_INCLUDE_SHELL_MQTT_H_ */
API for monitoring network connections and interfaces.
void(* shell_transport_handler_t)(enum shell_transport_evt evt, void *context)
Definition shell.h:795
Public kernel APIs.
MQTT Client Implementation.
BSD Sockets compatible API definitions.
Network Events code public header.
Network Management API public header.
#define SH_MQTT_TOPIC_TX_MAX_SIZE
Definition shell_mqtt.h:35
#define TX_BUF_SIZE
Definition shell_mqtt.h:30
#define RX_RB_SIZE
Definition shell_mqtt.h:29
const struct shell_transport_api shell_mqtt_transport_api
#define DEVICE_ID_HEX_MAX_SIZE
Definition shell_mqtt.h:33
bool shell_mqtt_get_devid(char *id, int id_max_len)
Function to define the device ID (devid) for which the shell mqtt backend uses as a client ID when it...
const struct shell * shell_backend_mqtt_get_ptr(void)
This function provides pointer to shell mqtt backend instance.
#define SH_MQTT_BUFFER_SIZE
Definition shell_mqtt.h:31
#define SH_MQTT_TOPIC_RX_MAX_SIZE
Definition shell_mqtt.h:34
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Kernel mutex structure.
Definition kernel.h:3437
A structure used to submit work after a delay.
Definition kernel.h:4603
Kernel workqueue structure.
Definition kernel.h:4759
A structure used to submit work.
Definition kernel.h:4561
MQTT Client definition to maintain information relevant to the client.
Definition mqtt.h:899
Parameters for a publish message (PUBLISH).
Definition mqtt.h:501
Network Management event callback structure Used to register a callback into the network management e...
Definition net_mgmt.h:163
A structure to represent a ring buffer.
Definition ring_buffer.h:50
Definition shell_mqtt.h:69
uint8_t tx[64]
Definition shell_mqtt.h:71
uint8_t rx[64]
Definition shell_mqtt.h:70
Definition shell_mqtt.h:39
uint16_t len
Current tx buf length.
Definition shell_mqtt.h:44
char buf[CONFIG_SHELL_MQTT_TX_BUF_SIZE]
tx buffer.
Definition shell_mqtt.h:41
MQTT-based shell transport.
Definition shell_mqtt.h:48
struct shell_mqtt_tx_buf tx_buf
Definition shell_mqtt.h:60
struct k_work_delayable subscribe_dwork
Definition shell_mqtt.h:91
struct k_work net_disconnected_work
Definition shell_mqtt.h:89
struct ring_buf rx_rb
Definition shell_mqtt.h:56
struct k_work_delayable publish_dwork
Definition shell_mqtt.h:93
char pub_topic[((3 *2)+1)+sizeof(CONFIG_SHELL_MQTT_TOPIC_TX_ID)]
Definition shell_mqtt.h:51
void * shell_context
Context registered by shell.
Definition shell_mqtt.h:63
struct k_work_delayable connect_dwork
Definition shell_mqtt.h:90
struct net_sockaddr_storage broker
MQTT Broker details.
Definition shell_mqtt.h:77
struct net_mgmt_event_callback mgmt_cb
Definition shell_mqtt.h:85
struct zsock_addrinfo * haddr
Definition shell_mqtt.h:79
struct k_work_delayable process_dwork
Definition shell_mqtt.h:92
uint8_t * rx_rb_ptr
Definition shell_mqtt.h:58
char device_id[((3 *2)+1)]
Definition shell_mqtt.h:49
shell_transport_handler_t shell_handler
Handler function registered by shell.
Definition shell_mqtt.h:54
enum shell_mqtt::sh_mqtt_transport_state transport_state
char sub_topic[((3 *2)+1)+sizeof(CONFIG_SHELL_MQTT_TOPIC_RX_ID)]
Definition shell_mqtt.h:50
sh_mqtt_network_state
Network states.
Definition shell_mqtt.h:108
@ SHELL_MQTT_NETWORK_DISCONNECTED
Definition shell_mqtt.h:109
@ SHELL_MQTT_NETWORK_CONNECTED
Definition shell_mqtt.h:110
struct mqtt_client mqtt_cli
The mqtt client struct.
Definition shell_mqtt.h:66
enum shell_mqtt::sh_mqtt_network_state network_state
struct shell_mqtt::buffer buf
struct mqtt_publish_param pub_data
Definition shell_mqtt.h:83
uint8_t rx_rb_buf[CONFIG_SHELL_MQTT_RX_BUF_SIZE]
Definition shell_mqtt.h:57
enum shell_mqtt::sh_mqtt_subscribe_state subscribe_state
struct zsock_pollfd fds[1]
Definition shell_mqtt.h:80
sh_mqtt_subscribe_state
MQTT subscription states.
Definition shell_mqtt.h:102
@ SHELL_MQTT_NOT_SUBSCRIBED
Definition shell_mqtt.h:103
@ SHELL_MQTT_SUBSCRIBED
Definition shell_mqtt.h:104
sh_mqtt_transport_state
MQTT connection states.
Definition shell_mqtt.h:96
@ SHELL_MQTT_TRANSPORT_DISCONNECTED
Definition shell_mqtt.h:97
@ SHELL_MQTT_TRANSPORT_CONNECTED
Definition shell_mqtt.h:98
int nfds
Definition shell_mqtt.h:81
struct k_mutex lock
Definition shell_mqtt.h:74
struct k_work_q workq
work
Definition shell_mqtt.h:88
Unified shell transport interface.
Definition shell.h:818
Shell instance internals.
Definition shell.h:1063
Definition used when querying address information.
Definition socket.h:314
Definition of the monitored socket/file descriptor.
Definition socket_poll.h:31