IMD SolutionComputing LibraryShop main store

Comparison

HTTP REST or MQTT for Flexy tag pushes to an IoT platform

Edge computing and IIoT Published 9 min read By IMD Solution engineering team

Short answer

Use MQTT when a Flexy publishes several group-D tags on a fixed timer, because one JSON object carries every value over one persistent connection. Use REQUESTHTTPX with POST when each update must land on one known variable ID and the response body is part of your acceptance test.

On this page
  1. HTTP REST or MQTT: which one should the Flexy use?
  2. What does each method actually send?
  3. How much traffic does each method cost for the same values?
  4. How do you confirm the platform stored the data?
  5. What must work before either method can publish?
  6. When does the MQTT connection need retry logic of its own?
  7. Which method fits which job on your floor?
  8. Questions asked

Both methods ship the same tag values from a Flexy to an IoT platform, but they solve different jobs. Use MQTT when you publish several group-D tags on a repeating timer: one JSON object over one persistent connection. Use REQUESTHTTPX with POST when every update must land on one known variable ID and the response body is part of your acceptance test. This comparison sets out the decision criteria, the traffic arithmetic for a concrete example, the checks that separate a connected client from stored data, and the decision for each case.

HTTP REST or MQTT: which one should the Flexy use? #

Use MQTT when you publish several tags on a repeating timer, because one JSON object on one persistent connection carries them all; use REQUESTHTTPX with POST when every update must target one known variable ID and the response body forms part of your acceptance test.

MQTT wins on data shape and connection economy. The publisher selects tags from the gateway's own tag table and sends them all in one JSON object, so adding a tag costs nothing in script routing. HTTP REST wins on targeting and evidence: the URL names one variable, and the response body tells you the platform created the value.

The vendor's data-sharing example chooses POST over GET for the HTTP path on security grounds: the token and the value travel in the encrypted body instead of the URL. Apply the same reasoning on any platform.

Criterion HTTP REST (REQUESTHTTPX, POST) MQTT
Publishing unit One variable per POST One JSON object with every selected tag
Routing key on the platform Variable ID in the URL Topic, device label and JSON property names
Connection model A new asynchronous HTTP action per call One persistent session with a keepalive interval
Transport check ACTIONSTAT equals 0 MQTT STATUS shows the connected state
Storage proof Timestamp in the response body None at QoS 0; check the destination
Script routing One URL branch per variable ID One group-D flag per tag, no ID table
Best fit Targeted single-value updates with proof Periodic multi-tag publication

What does each method actually send? #

Both methods start in the same place: the BASIC runtime reads a value from the gateway's local tag table, and the two paths differ in how many values travel in one transmission and which identifier routes each value on the platform side.

On the HTTP side, the script builds a URL around one variable ID, attaches a content-type header and the platform's token header (X-Auth-Token in the published pattern), and sends a body such as {"value": 21.4}. REQUESTHTTPX runs asynchronously: it returns an action ID through GETSYS PRG,"ACTIONID", an ONSTATUS handler fires when the action completes, and only by tracking that action ID — setting it with SETSYS PRG,"ACTIONID" before reading ACTIONSTAT and RESPONSEHTTPX "RESPONSE-BODY" — do you get the response the server actually sent.

On the MQTT side, the script opens one connection and publishes on a timer:

SETSYS INF, "LOAD"
SerNum$ = GETSYS INF, "SERNUM"
MQTTBrokerURL$ = "mqtt.example-platform.com"    // example endpoint
MQTTPort$ = "1883"
MQTT_Token$ = "REPLACE-AT-DEPLOYMENT"           // your active token, not an example one
MQTT_DeviceLabel$ = "flexy-line1"               // example device label
TopicToPublishOn$ = "/v1.6/devices/" + MQTT_DeviceLabel$
MQTT "OPEN", SerNum$, MQTTBrokerURL$
MQTT "SETPARAM", "PORT", MQTTPort$
MQTT "SETPARAM", "KEEPALIVE", "10"
MQTT "SETPARAM", "USERNAME", MQTT_Token$
MQTT "SETPARAM", "PASSWORD", ""
MQTT "CONNECT"

The serial number read with GETSYS INF, "SERNUM" serves as the client identifier. Many platforms authenticate with the token as username and an empty password; confirm your platform's scheme before relying on it. Do not copy a token from example code: insert the active token at deployment, and rotate any token that has appeared in a log, a screenshot or a shared script.

The published HTTP example pushes on a 60-second timer and the MQTT example on a 5-second one; either period works with either method, and the traffic arithmetic below assumes the same period for both so the comparison is fair. If you assemble the JSON object by hand, the same construction rules apply as when building MQTT JSON payloads from PLC tags for a cloud platform.

How much traffic does each method cost for the same values? #

For ten numeric tags delivered once each 60-second cycle, the HTTP path moves roughly 3.5 kB in ten separate POST round trips, while one MQTT publish moves roughly 280 bytes, so MQTT carries the same data for about 92 percent less traffic.

This is a worked example with illustrative sizes, not a measurement. Basis: ten numeric tags, each delivered once per 60-second cycle, on both paths.

HTTP REST, per cycle:

  • Each POST carries a URL of roughly 70 characters, headers of roughly 250 bytes (the content-type line plus the token header) and a JSON body of roughly 25 bytes: 70 + 250 + 25 = 345 bytes per POST.
  • Ten POSTs: 10 × 345 = 3,450 bytes, about 3.5 kB per cycle. Each action is standalone, so connection setup repeats per POST; MQTT pays its setup once at connect.
  • Over an hour (60 cycles): 60 × 3,450 = 207,000 bytes, about 207 kB, for 600 delivered values.

MQTT, per cycle:

  • One PUBLISH carries a 2-byte fixed header, a 2-byte topic length, the 22-byte topic plant/cell3/flexy-data and a payload of ten name-value pairs at roughly 25 bytes each: 2 + 2 + 22 + 250 = 276, call it 280 bytes.
  • Over an hour: 60 × 280 = 16,800 bytes, about 17 kB, for the same 600 delivered values.

Decision from these inputs: MQTT moves the same data for roughly 92 percent less application traffic, because 1 − 16,800 / 207,000 ≈ 0.92. What moves the numbers: a longer token adds its length in bytes to every single POST, tag count moves both figures linearly, and repeated connection setup widens the HTTP gap further.

How do you confirm the platform stored the data? #

An HTTP POST gives you an application-level answer every time: read ACTIONSTAT, and only a zero status plus a body that contains a creation timestamp proves the platform stored the value; MQTT STATUS 5 proves only that the broker connection is up.

For HTTP, the acceptance test is three steps: the callback fires, ACTIONSTAT reads 0, and RESPONSEHTTPX "RESPONSE-BODY" contains a creation timestamp such as created_at. Any nonzero ACTIONSTAT is a transport fault. A zero status with no timestamp means the transport worked but the platform rejected the value or never created it — read the body instead of celebrating the transport result. A POST to a JSON API that ends with no stored value usually fails at the payload or header level, and the guide to resolving JSON API POST errors on REQUESTHTTPX walks those cases one by one.

For MQTT, the honest statement is negative: STATUS showing the connected state proves the session, not the message. At QoS 0 nothing comes back at all, so the only real verification is at the destination — the dashboard value changes and its timestamp matches the publish. Print the topic and the complete payload at the publish call, so a mismatch is visible on the gateway side first.

What must work before either method can publish? #

Layer the checks in order: an active WAN interface with a usable route, name resolution for the chosen endpoint, an open outbound port — 1883 in the MQTT example — and only after those, tokens, identifiers and JSON.

  1. Confirm the tags hold valid, changing values in the gateway's tag table.
  2. Confirm the WAN interface is active and has a usable route.
  3. Confirm DNS resolves the chosen endpoint hostname.
  4. Confirm the outbound path permits the protocol and port: 1883 for the MQTT example.
  5. Only then check tokens, variable IDs, device labels, topics and JSON.

The two methods use different endpoints in the published examples, so reachability to one proves nothing about the other.

Observed result Stopping point Next check
MQTT connect logs error 28 WAN interface not ready Restore the WAN link, then rerun the connect routine
STATUS never reaches the connected state WAN, DNS, port, broker or token Trace those stages in order
Connected, but values stay stale Topic, payload, device label or tag selection Print the topic and the full JSON payload
ACTIONSTAT is nonzero The HTTP transport action Read the status, header and response body
ACTIONSTAT is 0, no timestamp in the body The platform rejected the value Read the returned body instead of trusting the transport result
Only some MQTT tags arrive Group-D selection or JSON construction Check the flag, the names, the values and the emitted JSON

When does the MQTT connection need retry logic of its own? #

The MQTT client connects once at startup in the common pattern, so if the WAN interface is not ready when the script runs the connect routine and the last error reads 28, the client stays disconnected until your own logic retries; HTTP avoids this because every POST stands alone.

Enable RESUMENEXT only around the connect call, read the last error with GETSYS PRG,"LSTERR", and restore normal error handling immediately afterward. A 28 there is a WAN-readiness failure, not a broker or credential problem, and the Flexy AWS IoT connect failure at error 28 walks that case in detail.

The fix is a controlled retry: when the timer finds the client disconnected, log the state and rerun the connect routine on later ticks until the session comes back — not an unconditional connect on every scan, which stacks attempts on a dead interface. The keepalive setting catches the opposite failure, a session that dies mid-run: with keepalive 10, a broker drops a silent session after about 15 seconds, and the script notices on its next status read. HTTP needs none of this machinery, because every POST is self-contained.

Which method fits which job on your floor? #

Commit by data shape: several periodically published group-D tags belong on MQTT in one JSON object, while single-value updates that must land on a known variable ID and be proven by the response body belong on HTTP REST with POST.

The MQTT path enumerates the local tag table and publishes only the tags whose group-D flag is set to 1, so the platform's variable list is maintained by flagging tags, not by editing script. The HTTP path needs one URL branch per accepted variable name — the published pattern maps each data name to its ID with a chain of comparisons — and the configured device name never enters the URL, so it cannot rescue a wrong variable ID. When you must trim what leaves the gateway, the same selection idea is what publishing select tags over MQTT to cut message costs applies.

Commit per data set, not per gateway: tags that feed a periodic multi-value dashboard go MQTT; a single value whose storage must be proven inside the exchange goes HTTP REST with POST. If several gateways later converge on one broker, check when one edge PC can host the MQTT broker for the rest before splitting the roles. And if the aggregation job outgrows the gateway's scripting entirely, that role fits an industrial mini PC.

Questions asked

Does MQTT STATUS 5 prove the platform stored my values?

No. STATUS 5 confirms the broker connection only, and a publish at QoS 0 receives no acknowledgment, so a stale dashboard value can come from a wrong topic, device label or tag name. Print the topic and the complete JSON payload right at the publish call and compare them character for character with what the platform expects. If you need storage proof in the exchange itself, the HTTP path's response body provides it.

How quickly does the keepalive expose a dead broker link?

With the keepalive interval set to 10 seconds, a broker treats the session as lost after about 15 seconds of silence, one and a half times the interval, which is standard MQTT behavior. Your script notices on its next timer tick when MQTT STATUS stops showing the connected state, and a controlled retry then rebuilds the session instead of a connect attempt on every scan.

Can both methods run on the same gateway at once?

Yes. The two paths use separate script calls, endpoints and connections, so they can run concurrently. Keep one method per data set, though: pushing the same tag through both creates duplicate values on the platform, and a dashboard bound to both can show the value twice or disagree with itself. Decide per tag whether the variable-ID route or the bulk JSON route owns it.

Which tags does the MQTT publisher include?

Only the tags flagged into group D. The publisher walks the local tag table and includes a tag in the JSON object when its group-D flag is set to 1; everything else stays local. Because that flag, not a script-side list, is the whole selection mechanism, review group-D membership before trusting the platform's tag list to mirror the gateway.

Keep reading

  • How-to

    Checking MQTT connection status in an Ewon Flexy BASIC script

    On an Ewon Flexy with firmware 14.x or later, a BASIC script reads the MQTT link state with the MQTT Status command: a returned 5 means the connection is operational and any other value means it is not. The firmware owns disconnection and reconnection, so the script only monitors and logs, and you investigate the internet path when the broker never comes back on its own.

    Edge computing and IIoT

  • How-to

    How Geo SCADA publishes values to MQTT

    Geo SCADA Expert publishes outbound values as control writes to MQTT Text driver points: the topic lives in each point's Control settings and the control value becomes the payload, while the point's readback is irrelevant. Sparkplug payloads need the Sparkplug B driver. Data arriving from Node-RED proves only the inbound path.

    Edge computing and IIoT

  • Comparison

    PLC MQTT direct publishing versus an IoT gateway

    For publishing process data to an MQTT broker for web monitoring, put the MQTT client in a gateway and leave the S7-1500 out of broker session logic. Keep the LMQTT_Client block in the PLC only when publication must be coordinated with control logic or the gateway cannot meet your topic, payload and delivery requirements. A green MQTT status proves the broker connection only, never the S7 data behind it.

    Edge computing and IIoT

Reading Ignition historian data from MATLAB or Python