Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
lwip_mqtt.c File Reference
MQTT client. More...
Go to the source code of this file.
| Enumerations | |
| enum | |
| MQTT client connection states.More... | |
| enum | mqtt_message_type | 
| MQTT control message types.More... | |
| enum | mqtt_connect_flag | 
| MQTT connect flags, only used in CONNECT message.More... | |
| Functions | |
| static void | mqtt_cyclic_timer (void *arg) | 
| Interval timer, called every MQTT_CYCLIC_TIMER_INTERVAL seconds in MQTT_CONNECTING and MQTT_CONNECTED states. | |
| static const char * | mqtt_msg_type_to_str (u8_t msg_type) | 
| Message type value to string. | |
| static u16_t | msg_generate_packet_id (mqtt_client_t *client) | 
| Generate MQTT packet identifier. | |
| static void | mqtt_output_send (struct mqtt_ringbuf_t *rb, struct tcp_pcb *tpcb) | 
| Try send as many bytes as possible from output ring buffer. | |
| static struct mqtt_request_t * | mqtt_create_request (struct mqtt_request_t *r_objs, u16_t pkt_id, mqtt_request_cb_t cb, void *arg) | 
| Create request item. | |
| static void | mqtt_append_request (struct mqtt_request_t **tail, struct mqtt_request_t *r) | 
| Append request to pending request queue. | |
| static void | mqtt_delete_request (struct mqtt_request_t *r) | 
| Delete request item. | |
| static struct mqtt_request_t * | mqtt_take_request (struct mqtt_request_t **tail, u16_t pkt_id) | 
| Remove a request item with a specific packet identifier from request queue. | |
| static void | mqtt_request_time_elapsed (struct mqtt_request_t **tail, u8_t t) | 
| Handle requests timeout. | |
| static void | mqtt_clear_requests (struct mqtt_request_t **tail) | 
| Free all request items. | |
| static void | mqtt_init_requests (struct mqtt_request_t *r_objs) | 
| Initialize all request items. | |
| static void | mqtt_output_append_fixed_header (struct mqtt_ringbuf_t *rb, u8_t msg_type, u8_t dup, u8_t qos, u8_t retain, u16_t r_length) | 
| Append fixed header. | |
| static u8_t | mqtt_output_check_space (struct mqtt_ringbuf_t *rb, u16_t r_length) | 
| Check output buffer space. | |
| static void | mqtt_close (mqtt_client_t *client, mqtt_connection_status_t reason) | 
| Close connection to server. | |
| static err_t | pub_ack_rec_rel_response (mqtt_client_t *client, u8_t msg, u16_t pkt_id, u8_t qos) | 
| Send PUBACK, PUBREC or PUBREL response message. | |
| static void | mqtt_incomming_suback (struct mqtt_request_t *r, u8_t result) | 
| Subscribe response from server. | |
| static mqtt_connection_status_t | mqtt_message_received (mqtt_client_t *client, u8_t fixed_hdr_idx, u16_t length, u32_t remaining_length) | 
| Complete MQTT message received or buffer full. | |
| static mqtt_connection_status_t | mqtt_parse_incoming (mqtt_client_t *client, struct pbuf *p) | 
| MQTT incoming message parser. | |
| static err_t | mqtt_tcp_recv_cb (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) | 
| TCP received callback function. | |
| static err_t | mqtt_tcp_sent_cb (void *arg, struct tcp_pcb *tpcb, u16_t len) | 
| TCP data sent callback function. | |
| static void | mqtt_tcp_err_cb (void *arg, err_t err) | 
| TCP error callback function. | |
| static err_t | mqtt_tcp_poll_cb (void *arg, struct tcp_pcb *tpcb) | 
| TCP poll callback function. | |
| static err_t | mqtt_tcp_connect_cb (void *arg, struct tcp_pcb *tpcb, err_t err) | 
| TCP connect callback function. | |
| err_t | mqtt_publish (mqtt_client_t *client, const char *topic, const void *payload, u16_t payload_length, u8_t qos, u8_t retain, mqtt_request_cb_t cb, void *arg) | 
| MQTT publish function. | |
| err_t | mqtt_sub_unsub (mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_cb_t cb, void *arg, u8_t sub) | 
| MQTT subscribe/unsubscribe function. | |
| void | mqtt_set_inpub_callback (mqtt_client_t *client, mqtt_incoming_publish_cb_t pub_cb, mqtt_incoming_data_cb_t data_cb, void *arg) | 
| Set callback to handle incoming publish requests from server. | |
| mqtt_client_t * | mqtt_client_new (void) | 
| Create a new MQTT client instance. | |
| err_t | mqtt_client_connect (mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, mqtt_connection_cb_t cb, void *arg, const struct mqtt_connect_client_info_t *client_info) | 
| Connect to MQTT server. | |
| void | mqtt_disconnect (mqtt_client_t *client) | 
| Disconnect from MQTT server. | |
| u8_t | mqtt_client_is_connected (mqtt_client_t *client) | 
| Check connection with server. | |
Detailed Description
MQTT client.
Definition in file lwip_mqtt.c.
Enumeration Type Documentation
| anonymous enum | 
MQTT client connection states.
Definition at line 79 of file lwip_mqtt.c.
| enum mqtt_connect_flag | 
MQTT connect flags, only used in CONNECT message.
Definition at line 113 of file lwip_mqtt.c.
| enum mqtt_message_type | 
MQTT control message types.
Definition at line 89 of file lwip_mqtt.c.
Function Documentation
| static void mqtt_append_request | ( | struct mqtt_request_t ** | tail, | 
| struct mqtt_request_t * | r | ||
| ) |  [static] | 
Append request to pending request queue.
- Parameters:
- 
  tail Pointer to request queue tail pointer r Request to append 
Definition at line 283 of file lwip_mqtt.c.
| static void mqtt_clear_requests | ( | struct mqtt_request_t ** | tail ) |  [static] | 
Free all request items.
- Parameters:
- 
  tail Pointer to request queue tail pointer 
Definition at line 389 of file lwip_mqtt.c.
| static void mqtt_close | ( | mqtt_client_t * | client, | 
| mqtt_connection_status_t | reason | ||
| ) |  [static] | 
Close connection to server.
- Parameters:
- 
  client MQTT client reason Reason for disconnection 
Definition at line 505 of file lwip_mqtt.c.
| static struct mqtt_request_t* mqtt_create_request | ( | struct mqtt_request_t * | r_objs, | 
| u16_t | pkt_id, | ||
| mqtt_request_cb_t | cb, | ||
| void * | arg | ||
| ) |  [static, read] | 
Create request item.
- Parameters:
- 
  r_objs Pointer to request objects pkt_id Packet identifier of request cb Packet callback to call when requests lifetime ends arg Parameter following callback 
- Returns:
- Request or NULL if failed to create
Definition at line 257 of file lwip_mqtt.c.
| static void mqtt_cyclic_timer | ( | void * | arg ) |  [static] | 
Interval timer, called every MQTT_CYCLIC_TIMER_INTERVAL seconds in MQTT_CONNECTING and MQTT_CONNECTED states.
- Parameters:
- 
  arg MQTT client 
Definition at line 544 of file lwip_mqtt.c.
| static void mqtt_delete_request | ( | struct mqtt_request_t * | r ) |  [static] | 
Delete request item.
- Parameters:
- 
  r Request item to delete 
Definition at line 312 of file lwip_mqtt.c.
| static void mqtt_incomming_suback | ( | struct mqtt_request_t * | r, | 
| u8_t | result | ||
| ) |  [static] | 
Subscribe response from server.
- Parameters:
- 
  r Matching request result Result code from server 
Definition at line 624 of file lwip_mqtt.c.
| static void mqtt_init_requests | ( | struct mqtt_request_t * | r_objs ) |  [static] | 
Initialize all request items.
- Parameters:
- 
  r_objs Pointer to request objects 
Definition at line 404 of file lwip_mqtt.c.
| static mqtt_connection_status_t mqtt_message_received | ( | mqtt_client_t * | client, | 
| u8_t | fixed_hdr_idx, | ||
| u16_t | length, | ||
| u32_t | remaining_length | ||
| ) |  [static] | 
Complete MQTT message received or buffer full.
- Parameters:
- 
  client MQTT client fixed_hdr_idx header index length length received part remaining_length Remaining length of complete message 
Definition at line 640 of file lwip_mqtt.c.
| static const char* mqtt_msg_type_to_str | ( | u8_t | msg_type ) |  [static] | 
Message type value to string.
- Parameters:
- 
  msg_type see enum mqtt_message_type 
- Returns:
- Control message type text string
Definition at line 149 of file lwip_mqtt.c.
| static void mqtt_output_append_fixed_header | ( | struct mqtt_ringbuf_t * | rb, | 
| u8_t | msg_type, | ||
| u8_t | dup, | ||
| u8_t | qos, | ||
| u8_t | retain, | ||
| u16_t | r_length | ||
| ) |  [static] | 
Append fixed header.
- Parameters:
- 
  rb Output ring buffer msg_type see enum mqtt_message_type dup MQTT DUP flag qos MQTT QoS field retain MQTT retain flag r_length Remaining length after fixed header 
Definition at line 462 of file lwip_mqtt.c.
| static u8_t mqtt_output_check_space | ( | struct mqtt_ringbuf_t * | rb, | 
| u16_t | r_length | ||
| ) |  [static] | 
Check output buffer space.
- Parameters:
- 
  rb Output ring buffer r_length Remaining length after fixed header 
- Returns:
- 1 if message will fit, 0 if not enough buffer space
Definition at line 482 of file lwip_mqtt.c.
| static void mqtt_output_send | ( | struct mqtt_ringbuf_t * | rb, | 
| struct tcp_pcb * | tpcb | ||
| ) |  [static] | 
Try send as many bytes as possible from output ring buffer.
- Parameters:
- 
  rb Output ring buffer tpcb TCP connection handle 
Definition at line 205 of file lwip_mqtt.c.
| static mqtt_connection_status_t mqtt_parse_incoming | ( | mqtt_client_t * | client, | 
| struct pbuf * | p | ||
| ) |  [static] | 
MQTT incoming message parser.
- Parameters:
- 
  client MQTT client p PBUF chain of received data 
- Returns:
- Connection status
Definition at line 778 of file lwip_mqtt.c.
| static void mqtt_request_time_elapsed | ( | struct mqtt_request_t ** | tail, | 
| u8_t | t | ||
| ) |  [static] | 
Handle requests timeout.
- Parameters:
- 
  tail Pointer to request queue tail pointer t Time since last call in seconds 
Definition at line 361 of file lwip_mqtt.c.
| static struct mqtt_request_t* mqtt_take_request | ( | struct mqtt_request_t ** | tail, | 
| u16_t | pkt_id | ||
| ) |  [static, read] | 
Remove a request item with a specific packet identifier from request queue.
- Parameters:
- 
  tail Pointer to request queue tail pointer pkt_id Packet identifier of request to take 
- Returns:
- Request item if found, NULL if not
Definition at line 326 of file lwip_mqtt.c.
TCP connect callback function.
- See also:
- tcp_connected_fn
- Parameters:
- 
  arg MQTT client err Always ERR_OK, mqtt_tcp_err_cb is called in case of error 
- Returns:
- ERR_OK
Definition at line 971 of file lwip_mqtt.c.
| static void mqtt_tcp_err_cb | ( | void * | arg, | 
| err_t | err | ||
| ) |  [static] | 
TCP error callback function.
- See also:
- tcp_err_fn
- Parameters:
- 
  arg MQTT client err Error encountered 
Definition at line 936 of file lwip_mqtt.c.
TCP poll callback function.
- See also:
- tcp_poll_fn
- Parameters:
- 
  arg MQTT client tpcb TCP connection handle 
- Returns:
- err ERR_OK
Definition at line 954 of file lwip_mqtt.c.
| static err_t mqtt_tcp_recv_cb | ( | void * | arg, | 
| struct tcp_pcb * | pcb, | ||
| struct pbuf * | p, | ||
| err_t | err | ||
| ) |  [static] | 
TCP received callback function.
- See also:
- tcp_recv_fn
- Parameters:
- 
  arg MQTT client p PBUF chain of received data err Passed as return value if not ERR_OK 
- Returns:
- ERR_OK or err passed into callback
Definition at line 859 of file lwip_mqtt.c.
TCP data sent callback function.
- See also:
- tcp_sent_fn
- Parameters:
- 
  arg MQTT client tpcb TCP connection handle len Number of bytes sent 
- Returns:
- ERR_OK
Definition at line 903 of file lwip_mqtt.c.
| static u16_t msg_generate_packet_id | ( | mqtt_client_t * | client ) |  [static] | 
Generate MQTT packet identifier.
- Parameters:
- 
  client MQTT client 
- Returns:
- New packet identifier, range 1 to 65535
Definition at line 166 of file lwip_mqtt.c.
| static err_t pub_ack_rec_rel_response | ( | mqtt_client_t * | client, | 
| u8_t | msg, | ||
| u16_t | pkt_id, | ||
| u8_t | qos | ||
| ) |  [static] | 
Send PUBACK, PUBREC or PUBREL response message.
- Parameters:
- 
  client MQTT client msg PUBACK, PUBREC or PUBREL pkt_id Packet identifier qos QoS value 
- Returns:
- ERR_OK if successful, ERR_MEM if out of memory
Definition at line 603 of file lwip_mqtt.c.
Generated on Fri Jul 22 2022 04:54:07 by
 1.7.2
 1.7.2 
    