Skip to content

Comments

Allow MQTT connection and processing in one every second iteration#1939

Open
protectivedad wants to merge 11 commits intoopenshwprojects:mainfrom
protectivedad:main-timing-mqtt
Open

Allow MQTT connection and processing in one every second iteration#1939
protectivedad wants to merge 11 commits intoopenshwprojects:mainfrom
protectivedad:main-timing-mqtt

Conversation

@protectivedad
Copy link
Contributor

Further to the discussion https://www.elektroda.com/rtvforum/viewtopic.php?p=21801342#21801342

The current MQTT every second loop allows only connect or process each turn. This PR allows both to occur in the same turn. It will only do this if the fast connect flag is selected. When the fast connect flag is selected after submitting the MQTT connect it will wait for up to 200 ms for a connection. If a connection occurs it will then continue and process MQTT messages.

In my testing this shaves a second off the post time.

Anthony Sepa added 4 commits January 6, 2026 19:33
- added timing lines to some routines
- added the ability to exclude timing, info, debug and extradebug code
- MQTT connecting and MQTT processing can now happen in the same
second loop.
- MQTT connecting will wait upto 200 ms for the connection to be
ready if has connect is enabled
@protectivedad
Copy link
Contributor Author

This is ready to be tested it is built on my main-timing PR. Without the timing PR there is no real way to test and make sure that the improvements really increase the speed of the system. Plus with the timing information you can see what is holding up the MQTT from working faster.

One thing I noticed was the original code, if the system triggered a reconnect it would force a disconnect in line 2235 but process MQTT messages as if the broker was still connected for the rest of the loop. I decided that didn't make any sense so the new behaviour is to force disconnect and exit.

That should be the only change in the original routine except for being able to process after a connect.

I do have one other enhancement I need for my non-TuyaMCU door sensor. Right now MQTT_ChannelPublish information is dropped if the broker is not connected. In this PR I have added code to check if the broker is ready and if not post to Queue.

I'm not sure about removing the /get from the publish.

Anthony Sepa added 5 commits January 10, 2026 08:20
- created MQTT_FastConnect() function for main to call
- mqtt_client_connect will retry on routing error
- just connected logic seperated
  - run from quick tick (if fastconnect)
  - publish queued items (if fastconnect)
  - run from everysecond next loop (if non-fastconnect)
@protectivedad
Copy link
Contributor Author

Tested on BK7238 TuyaMCU and BK7231N non-TuyaMCU door sensors.

Anthony Sepa added 2 commits February 2, 2026 15:20
- fix DHCP connections froze on MQTT Fast Connect
- loops disconnect only set if MQTT Fast Connect fails
- MQTT do connect's TCPIP lock scope now include error discount
- OTA is checked sooner and open access point stops processing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant