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:
- Open the file in EasyBuilder Pro.
- Enter your AWS IoT endpoint, private key, certificate, etc.
- 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