How do I limit the batch sending rate via MQTT?

How do I limit the batch sending rate via MQTT?
none 0.0 0

Hi everyone,
I’m using a Weintek cMT2078 HMI connected to a plc to send data via MQTT to an external broker.

When the internet connection drops, the HMI stores the messages in a buffer. Once the connection is restored, all buffered messages are sent at once, which exceeds the broker’s limit of 30 messages per minute.

If this rate is exceeded, the broker forcibly closes the connection as a security measure. The problem is that the connection is only re-established about an hour later, by which time another 30 messages have been buffered. This creates an endless loop where the connection is closed again every time it tries to resend.

I’d like to know if there’s a way to control the sending rate of these buffered messages to avoid overloading the broker when the connection comes back.

Thanks in advance for any help!

Hi @JonatasLiasch

One approach is to use the recipe database as a temporary buffer before forwarding messages via MQTT. By leveraging macros to introduce delays, monitor connection status, and manage the buffered data, you can throttle your message flow and prevent broker overload that might otherwise cause connection losses.

Flow Overview

This is the Youtube video referenced start testing this project: How to use the “Normal” MQTT cloud service to connect to an AWS IoT server - EasyBuilder Pro

To run the demo:

  1. Open the file in EasyBuilder Pro.
  2. Enter your AWS IoT endpoint, private key, certificate, etc.
  3. Deploy to your cMT/HMI and start testing the buffered-publish logic.

Demo Download

Macro Used
Note: I have used placeholder values from EB pro objects for this demo. Please modify the code to fit your project.


macro_command main()
short data = 0
short status=0
short count = 0
short del = 3
short add =1 



// Get data and place in recipe address: use RecipeSetData()



GetData(status, "Local HMI", LW, 0, 1)// getting the status of the connections

if status == 2 then

// Get count, if count within recipe is above 0 then publish data
GetData(count, "Local HMI", RECIPE, "Demo2.Count")
while count > 0
	// pusblish everything within the recipe data base aka the buffer:
	
	
	GetData(data, "Local HMI", RECIPE, "Demo2.Num1")// Get the result from the recipe database to later push to MQTT
	SetData(data, "Local HMI", LW, 2, 1) // placing data from recipe database to the MQTT for a push
	SetData(del, "Local HMI", RECIPE, "Demo2.Command")// Delete the line from the recipe database 
	DELAY(250)
	GetData(count, "Local HMI", RECIPE, "Demo2.Count") // get the count of the recipe database for the update. 
	GetData(status, "Local HMI", LW, 0, 1)// getting the status of the connections
wend 


// pushing out of MQTT from the recipe database
else if  status == 1 then // when status is 1, connection is disconnected. 

// get the data from a source for now LW - 100 and push to recipe database

short temp = 0

GetData(temp, "Local HMI", LW, 100, 1) // random num to add to recipe database for testing from LW -100

SetData(temp, "Local HMI", RECIPE, "Demo2.Num1") // sets it in there
DELAY(250)
SetData(add, "Local HMI", RECIPE, "Demo2.Command") // pushes the command out
GetData(status, "Local HMI", LW, 0, 1)// getting the status of the connections

end if






end macro_command