255 Commits

Author SHA1 Message Date
56799069af Enables cypher suite configurations on IDF => 5.5
Merges https://github.com/espressif/esp-mqtt/pull/298
2025-05-21 15:24:19 +02:00
dhb
00cc9dbd9a feat(mqtt): enable custom TLS cipher suites for MQTTs
- Add `ciphersuites_list` to `esp_mqtt_client_config_t` for specifying TLS cipher suites.
- Update SSL transport configuration to use the provided cipher suites.
- Users are responsible for managing the cipher suites list memory.
2025-05-21 10:05:00 +02:00
9c76b7054a fix: Multiple event data
Fix a regression introduced when adding the presence of topic in all
event data.
2025-05-20 10:33:37 +02:00
b35a69121c feat(mqtt): Add support for ECDSA signing
Added support for ECDSA signing in MQTT.
2025-05-14 12:14:43 +05:30
f38a5fcee1 fix: pubrel message resending when pubcomp not received
For the case when pubcomp wasn't received we should retry sending
pubrel.
2025-04-28 13:56:34 +02:00
470cb93049 mqtt_client: Manage disconnect packet
In the mqtt5 protocol the broker can disconnect the client with
a disconnect packet. This packet contains a reason value that can be
useful for certain applications in which it is important to know
the reason of disconnection.
While the client is connected is possible that a disconnect packet
is reaceived by the broker to force a disconnection. Before this
patch this approach causes a generic error on transport in case of
disconnection from the broker. If the packet is managed before getting
an error it is possible to save the reason code in the
disconnect_return_code variable in the error_handle, and dispatch
the disconnect event that can be managed by the application event
loop, that now can know the reason of disconnection from the broker.
Reset the variable in case of error.

Signed-off-by: Flavia Caforio <flavia.caforio@amarulasolutions.com>
2025-02-18 16:24:13 +01:00
cea7e959ee Merge branch 'fix/deleted_msg_event' into 'master'
When MQTT_REPORT_DELETED_MESSAGES, delete QOS messages with id 0

Closes IDFGH-14022 and IDFGH-14021

See merge request espressif/esp-mqtt!225
2024-11-18 17:49:39 +08:00
b82c8f6c87 When MQTT_REPORT_DELETED_MESSAGES, delete QOS messages with id 0 2024-11-07 10:08:56 +11:00
44292cc2c4 fix: Race condition when using destroy
In a case were destroy is being called by a higher priority task set the
STOPPED_BIT before seting the state would lead to a crash.
2024-10-14 12:57:05 +02:00
9de024ca53 Merge branch 'feature/tcp_keepalive' into 'master'
feat: Add TCP keepalive configuration

Closes IDF-8049

See merge request espressif/esp-mqtt!220
2024-09-25 17:20:52 +08:00
82017e9bcc feat: Include message topic in all data events for big messages.
When message is larger than the buffer, and must produce several events include topic where it came from in each of those events
2024-08-22 12:48:43 +02:00
7c3227a24d feat: Add TCP keepalive configuration 2024-08-22 11:18:43 +02:00
b5b80336b7 Merge branch 'fix/clean_transport' into 'master'
fix: set TCP transport every time when setting the config

See merge request espressif/esp-mqtt!218
2024-07-10 22:07:55 +08:00
97dc85a080 feat: Allow users to get the transport in use 2024-07-10 15:17:41 +08:00
c3c4cb9a2a fix: set TCP transport every time when setting the config 2024-07-01 16:54:47 +10:00
2285726229 clean: Remove expired deletion from publish
Since expired messages deletion are now handled in all states this call
is unnecessary.
2024-06-17 15:23:17 +02:00
6bb5a5bab0 fix: clang analyzer unknown pragma warning 2024-06-10 20:08:47 +07:00
b5272039fe fix: gcc analyzer unknown pragma warning 2024-06-10 19:34:48 +07:00
a0f4ce85de Merge branch 'Improve-handling-of-expired-messages' into 'master'
feat: Moves deletion of expired messages to run at all states

Closes IDFGH-12831

See merge request espressif/esp-mqtt!213
2024-06-03 20:48:47 +08:00
32dada47ff feat: Moves deletion of expired messages to run at all states
Process expiration of messages in all states removing messages from the
outbox even in disconnected scenarios.

Closes https://github.com/espressif/esp-mqtt/issues/278
2024-05-27 10:56:40 +02:00
739cb2dd32 fix: Handling of state in the outbox for enqueued QoS 0 messages
If a QoS 0 was handled by the enqueued messages transmission, it could
lead to set incorrectly another QoS 0 as transmitted.

Closes https://github.com/espressif/esp-mqtt/issues/276
2024-05-27 16:36:14 +08:00
8bc3bff757 fix: gcc -fanalyzer warnings 2024-05-22 22:15:48 +08:00
aa6f889fb4 Merge branch 'fix/error_codes' into 'master'
fix: regard reason codes greater than 0x80 as failures.

See merge request espressif/esp-mqtt!205
2024-04-05 17:09:50 +08:00
c06f1540fe set last_retransmit to now when first connected
when published before connected, the msg will be always retransmitted immediately even it is  send right now
2024-04-02 10:48:45 +02:00
e7b9aa5e6a fix: regard reason codes greater than 0x80 as failures. 2024-04-01 10:37:42 +08:00
37cb056c5f Merge branch 'feature/atomic_state' into 'master'
Make state and size atomic

See merge request espressif/esp-mqtt!199
2024-03-22 15:26:15 +08:00
5c17fc4a1a fix: Adjust the log level on few messages to avoid cluthering the logs 2024-03-21 14:11:57 +01:00
891380bdf5 feat: Make state and size atomic
This makes the mqtt client state atomic to reduce the scope of locking in
some parts of the code.
2024-03-12 08:49:36 +01:00
ddde502782 client: Report failure on timeout in mid-message timeout
Fixes error processing on network reads:

1) Treat EOF as an error, since the connection is closed (FIN) from the
server side. If we didn't we would try to read (in the next iteration)
from the same socket that has been already closed and get an error
ENOTCONN.
Before the fix:
D (13760) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read(): EOF
E (13800) transport_base: tcp_read error, errno=Socket is not connected
E (13800) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read() error: errno=128
D (13810) esp_mqtt_demo: Event dispatched from event loop base=MQTT_EVENTS, event_id=0
I (13820) esp_mqtt_demo: MQTT_EVENT_ERROR
E (13830) esp_mqtt_demo: Last error reported from esp-tls: 0x8008
E (13830) esp_mqtt_demo: Last error captured as transport's socket errno: 0x80
I (13840) esp_mqtt_demo: Last errno string (Socket is not connected)
E (13850) mqtt_client: mqtt_process_receive: mqtt_message_receive() returned -1
D (13860) mqtt_client: Reconnect after 10000 ms
D (13860) esp_mqtt_demo: Event dispatched from event loop base=MQTT_EVENTS, event_id=2
I (13870) esp_mqtt_demo: MQTT_EVENT_DISCONNECTED
After the fix:
E (12420) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read(): EOF
E (12420) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read() error: errno=128
D (12430) esp_mqtt_demo: Event dispatched from event loop base=MQTT_EVENTS, event_id=0
I (12440) esp_mqtt_demo: MQTT_EVENT_ERROR
E (12450) esp_mqtt_demo: Last error reported from esp-tls: 0x8008
I (12450) esp_mqtt_demo: Last errno string (Success)
E (12460) mqtt_client: mqtt_process_receive: mqtt_message_receive() returned -1
D (12470) mqtt_client: Reconnect after 10000 ms
D (12470) esp_mqtt_demo: Event dispatched from event loop base=MQTT_EVENTS, event_id=2
I (12480) esp_mqtt_demo: MQTT_EVENT_DISCONNECTED

2) Treat timeouts in the middle of MQTT message reading as errors (if
timeouted for the second time and didn't read a byte)
Before the fix:
D (9160) mqtt_client: mqtt_message_receive: read "remaining length" byte: 0x2
D (9170) mqtt_client: mqtt_message_receive: total message length: 4 (already read: 2)
D (19190) mqtt_client: mqtt_message_receive: read_len=0
D (19190) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read(): call timed out before data was ready!
E (19200) mqtt_client: esp_mqtt_connect: mqtt_message_receive() returned 0
E (19210) mqtt_client: MQTT connect failed
D (19220) mqtt_client: Reconnect after 10000 ms
D (19220) esp_mqtt_demo: Event dispatched from event loop base=MQTT_EVENTS, event_id=2
I (19230) esp_mqtt_demo: MQTT_EVENT_DISCONNECTED
After the fix:
D (19190) mqtt_client: mqtt_message_receive: read_len=0
E (19190) mqtt_client: Network timeout while reading MQTT message
E (19200) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read() error: errno=119
D (19210) esp_mqtt_demo: Event dispatched from event loop base=MQTT_EVENTS, event_id=0
I (19220) esp_mqtt_demo: MQTT_EVENT_ERROR
I (19220) esp_mqtt_demo: Last errno string (Success)
E (19230) mqtt_client: esp_mqtt_connect: mqtt_message_receive() returned -1
E (19240) mqtt_client: MQTT connect failed
D (19240) mqtt_client: Reconnect after 10000 ms
D (19240) esp_mqtt_demo: Event dispatched from event loop base=MQTT_EVENTS, event_id=2
I (19250) esp_mqtt_demo: MQTT_EVENT_DISCONNECTED
(Note that the above log is from mid-message timeout of CONNECT message,
which was hadled before the fix. If the mid-message timeout ocurs with
for example SUBACK, the current version would repeatably resend
susbscribe message)

Merges https://github.com/espressif/esp-mqtt/pull/232
2023-11-10 15:40:44 +01:00
ea0df31e00 fix: Move buffer initialization to set config
When calling set config message buffers were not affected because the
creation was handled on init.

Closes https://github.com/espressif/esp-mqtt/issues/267
2023-10-25 07:47:05 +00:00
67800569de fix: Deliver publish verifies if message was created only for QoS >0
The previous version depends on a sucessful message being created prior
to that check. The check only makes sense for the case where puback or
pubrec messages should be created.
2023-10-10 06:47:07 +00:00
c0b40b1293 fix: using return value of asprintf now 2023-09-14 19:46:26 +08:00
cc41d1b852 fix: Added missing update to message data
When handling big messages the refactoring introduced a regression when
handling big messages, messages larger than the message buffer.
2023-08-24 09:52:00 +02:00
cd81773bd1 Merge branch 'fix/format_log_messages' into 'master'
fix: LOG format strings

See merge request espressif/esp-mqtt!187
2023-07-10 17:28:55 +08:00
395aa141c8 Merge branch 'fix/stop_only_if_started' into 'master'
Fix: Stop client only if it's running.

See merge request espressif/esp-mqtt!183
2023-07-10 15:55:33 +08:00
a3b04f2d0a fix: LOG format strings
Fix log format strings and remove no-format warning configuration.
2023-06-30 10:17:32 +02:00
585e3ba2e0 fix: Error on publish message creation was ignored.
In the case of make_publish failure the client would just continue and
the error was ignored and not propagated to caller.
2023-06-27 15:13:54 +02:00
36eec6f625 Fix: Stop client only if it's running.
Check for client run instead of lock to call esp_mqtt_client_stop
when destroying the client.
2023-06-21 09:39:42 +02:00
4050df4caf Adds mqtt host tests to Ci
- New job to run host tests
- Fix leak in case of usage of interface name
- Fix host tests to expect a call to `transport_destroy` and add an
  extra case
2023-06-19 10:34:18 +02:00
363fbf7dab feat: Add option to bind interface of use
Enable user to set which interface should be used for client network,
allowing client to be binded to the interface selected by user forcing
it to go through the selected interface.

Closes https://github.com/espressif/esp-mqtt/issues/253
2023-06-14 14:48:44 +02:00
372ab7b374 feat: Introduces outbox limit
A memory limit for the outbox can be configured.
User will not be able to publish or enqueue if the new message goes
beyond the configured limit.
2023-06-13 15:59:55 +02:00
122875bf8a refactor: Group access to output buffer in mqtt_connection_t
- Moves mqtt_connect_info to mqtt_connection_t.
  - Removes outbound_message in favor of accessing it trough connection.
2023-06-13 11:56:05 +02:00
ed628098a1 Merge branch 'feature/custom_transport' into 'master'
Add custom transport configuration

See merge request espressif/esp-mqtt!169
2023-06-13 14:30:24 +08:00
a492935951 Removes leftover calls to event_handler
The possibility to add a callback as custom handler was removed from
the client in favor of esp_event. These removes the older alternative
that wasn't possible to use.
2023-06-09 10:44:50 +02:00
6195762d28 Added support to set server common name. 2023-06-08 08:46:41 +02:00
a5c1b441dc feat: Add custom transport configuration
Today there is no way to add a new transport without applying
modifications to the transport list. This impose limitations on the
client usage. Adding the custom configuration we enable user defined
transports.
2023-06-08 06:38:53 +00:00
5bd9724c69 Merge branch 'bugfix/return_on_qos0_disconnected' into 'master'
bug: Incorrect return on disconnect qos0 publish

See merge request espressif/esp-mqtt!172

(cherry picked from commit fa40f44695fc4a0cde14a31a01b8a03da14dd702)

58c25577 bug: Incorrect return on disconnect qos0 publish
2023-06-01 17:03:03 +08:00
da6d38a17e Removes pending message count
The information was used only to log remaining messages on debug log.
It was checked on writing but updated prior to every call making the
verification meaningless.
2023-04-21 08:40:12 +02:00
5729048683 Bugfix: Dispatch transport error on all write operations
- During connect the error wasn't dispatched.
- Merged esp_mqtt_write with mqtt_write_data since the only difference
  was the error dispatched.
2023-04-20 09:29:33 +02:00
72833c7f8a Merge enqueue functions
- enqueue and oversized enqueue did the same work with small differences
  this clean up the extra unnecessary function
2023-04-20 09:29:33 +02:00