How-to
Send Ewon Flexy telemetry by REST POST with REQUESTHTTPX
Short answer
Build the JSON body from the tag, POST it with REQUESTHTTPX under Content-Type=application/json, save the request's ACTIONID, and match the ONSTATUS callback's EVTINFO against it before reading ACTIONSTAT. Confirm the write in the platform before trusting the timer: the example's timer value has no documented unit, and the script holds one global request ID.

On this page
Push Flexy tag values to a cloud platform over REST with one script pattern: build the JSON body from the tag, POST it with REQUESTHTTPX and a JSON content-type header, save the request ID that GETSYS PRG returns, and match the status callback's EVTINFO against that saved ID before you read ACTIONSTAT. Two things decide whether you can trust it in production. First, confirm the write on the platform side: the example sets INTERVAL% = 5 and nothing in the sources behind this article documents what that value is counted in, so measure the timer instead of assuming it. Second, the script holds one global request ID, so a send that outlasts the timer can be orphaned. The tag itself usually arrives over Modbus TCP or EtherNet/IP; the script picks up from the tag value. Below: the script, the steps, the worked example, and a decision per failure.
The full script #
This is the whole pattern trimmed to one tag and one endpoint. The token is an example value, not a real credential, and the base path is an example host; take both from the platform's device page. Some published copies of this script also print the URL and the body for debugging; this block leaves those lines out, and the steps below say why. It also passes the message argument into the send function instead of the global body string, so the function carries its own data.
Rem --- eWON start section: Init Section
eWON_init_section:
// Send period: the unit is not documented, so measure it (see below)
INTERVAL% = 5
// Device token from the platform's device page
// The value here is an example, not a real credential
DEVICE$ = "1234567890abcdef"
// Endpoint = base path + token + /telemetry
// The base path is an example; use the one your platform documents
URL$ = "https://app.example.com/api/v1/" + DEVICE$ + "/telemetry"
TSET 1, INTERVAL%
ONTIMER 1, "@Main()"
Function Main()
// One numeric tag, one JSON field
MSG$ = '{"Temperature" : ' + STR$(Temperature@) + '}'
@SendData(MSG$)
EndFn
Function SendData($message$)
REQUESTHTTPX URL$, "POST", "Content-Type=application/json", $message$
actionID% = GETSYS PRG, "ACTIONID"
ONSTATUS "@ResponseHandler()"
EndFn
Function ResponseHandler()
eventId% = GETSYS PRG, "EVTINFO"
IF (eventId% = actionID%) THEN
SETSYS PRG, "ACTIONID", eventId%
stat% = GETSYS PRG, "ACTIONSTAT"
PRINT "Response="; stat%
ENDIF
EndFn
Wire it up #
Work in this order; each step depends on the one before it.
- Create the device in the platform and copy its device token into DEVICE$. The token rides in the URL path on every send, so treat it as a credential: anything that echoes the URL echoes the token.
- Assemble the endpoint as one string in this order: the base path the platform documents, then the token, then /telemetry at the end.
- In the timer function, build the body as a single string: the JSON wrapper around the field name, then STR$ of the tag value, then the closing brace. The value is not quoted, so whatever STR$ returns must read as a valid JSON number.
- Send with REQUESTHTTPX in this argument order: endpoint, "POST", the Content-Type=application/json header, the body. Immediately after the call, save GETSYS PRG, "ACTIONID" into a global integer; that number is your only handle on this send.
- Register the status handler with ONSTATUS inside the send function, as the script does. In the handler, compare GETSYS PRG, "EVTINFO" with the saved ID; only on a match, select that event with SETSYS PRG, "ACTIONID" and read GETSYS PRG, "ACTIONSTAT" for it.
- If your working copy still prints the URL and the body for debugging, delete those lines before the Flexy ships, because the printed URL contains the token, and keep the response print, which shows only a status number.
Worked example: posting a 22-character temperature payload to a 57-character endpoint #
The inputs, and where each comes from:
- Tag:
Temperature@, numeric. The field name comes from the example integration's payload; the reading below is an example value. - Token:
1234567890abcdef, 16 characters. The example integration shows a 16-character token stand-in; take that as this example's length, not a documented platform limit. - Base path:
https://app.example.com/api/v1/, an example base that is 31 characters as written. - Suffix:
/telemetry, 10 characters. - Timer input: INTERVAL% = 5, unit undocumented in the sources behind this article.
The rule in words: the endpoint length is base plus token plus suffix; the body length is the JSON wrapper plus whatever STR$ makes of the tag plus the closing brace; and the handler only accounts for a send whose event ID equals the ID saved at send time.
The arithmetic: 31 + 16 + 10 = 57 characters for the endpoint. The wrapper {"Temperature" : is 17 characters. An example reading of 42.5 converts through STR$ to 42.5, 4 characters, and the closing brace adds 1: 17 + 4 + 1 = 22 characters, giving the body {"Temperature" : 42.5}.
The result: every cycle the script posts a 22-character body to a 57-character endpoint and files one request ID; the next status event whose EVTINFO matches that ID carries this send's ACTIONSTAT.
The decision: call the write proven only when both things have happened, the handler printed a status for that ID and the platform shows the 42.5 reading with a timestamp inside the current cycle. A body this size is negligible bandwidth; if the send-to-callback time ever approaches the timer period, the cause is the link or the timer, not the payload, and the overlap guard below applies.
Confirm the write and measure the real cycle #
The sources behind this article do not list which ACTIONSTAT values mean success, so do not hardcode a success number into the branch. The receiving side is the proof: open the platform's data view for the tag and watch the timestamp advance once per cycle with the value you just pushed.
The timer needs the same treatment. Published examples often call the TSET value seconds, but nothing in this article's sources documents the unit for this script, so measure it: take two consecutive timestamps for the tag in the platform's data view, and the gap between them is the true cycle. Scale the timer input by designed period divided by measured period, round to a whole number, and re-measure until the gap matches the design.
One adjacent failure has its own writeup: the script ticks once and then goes quiet. That cause and fix are covered step by step in the article on why a Flexy BASIC script publishes MQTT once then stops.
One request ID means one send in flight #
actionID% is a single global integer, and every REQUESTHTTPX call overwrites it. If the timer fires again before the handler has matched the previous ID, that ID is gone: the old request's callback arrives, fails the comparison, and the send is never accounted for.
Measure the send-to-callback gap once, meaning the time between the POST line and the response print. While that gap stays under half the timer period, overlap cannot occur. The decision: if the Flexy reaches the platform over LTE or any link that can stall, or if the measured gap ever crosses half the timer period, add an in-flight flag; set an integer flag before REQUESTHTTPX, clear it in the handler after a match, and skip the send while it is set. On a healthy LAN link with the gap well under half the period, the plain script is fine as it stands.
Decisions for each failure you will see #
No status event ever arrives: the request never completed. Work down the chain: DNS resolution, the https handshake, then the endpoint path, which must be base, token, and /telemetry in exactly that order. A single wrong character means the platform never sees the device this token names.
The handler prints a status but the platform shows nothing: the body was rejected. In this payload the value is not quoted, so an empty or non-numeric tag representation produces a body the endpoint cannot parse as JSON. Print the body once, paste it into a JSON validator, and make sure the tag holds a numeric value before the send runs. This is the same class of problem as a broker rejecting a JSON body, and the page on troubleshooting a platform that rejects JSON payloads walks that case in detail.
The value lands but looks wrong: print the STR$ output once and compare it against the tag; any formatting surprise shows up immediately there.
The destination is a historian database rather than a dashboard: the POST pattern still applies, but the receiver must expose an HTTP endpoint that accepts writes, and the article on why an edge gateway needs an HTTP endpoint to write a database covers that receiving side.
Run it like this: ship the script with the timer input you measured, not the one you assumed; keep the print that shows a status number and delete every print that shows the URL; and add the in-flight flag the moment the link is cellular or the gap crosses half the timer period. The write is real when the timestamp moves.
Questions asked
Does the REST push need an MQTT broker anywhere?
No. REQUESTHTTPX posts straight to the platform's HTTP endpoint, so the REST path needs no broker, no client ID and no topic. An MQTT outage elsewhere in the plant cannot stall this push, and this push cannot stall a separate MQTT publisher; the two paths are independent scripts that share only the Flexy and its tag values.
Which ACTIONSTAT value means the POST succeeded?
The sources behind this article do not publish the value list, so do not write a success number into the script's branch. Treat a send as confirmed when the handler matches your saved request ID and the platform's data view shows the new value with a fresh timestamp. If you must branch on the status anyway, log the numbers you see for a day and map each one against the data view before trusting any of them.
The cycle is wrong. How do I correct the timer?
Measure first: take two consecutive timestamps for the tag in the platform's data view; that gap is the real cycle. If you designed for 5 seconds but the gap reads 10, the script runs half as often as intended, so halve the timer input and round down, since the variable is an integer, then re-measure. Repeat until the measured gap matches the design.
What happens to samples while the WAN link is down?
Nothing is kept. This script has no store-and-forward: each cycle builds a body from the current tag value and posts it once, and a POST attempted while the link is down fails with a status event and one lost sample. If the platform needs gap-free history, that has to come from a buffering layer on the receiving side or a second collection path; this pattern will not provide it.


