IMD SolutionComputing LibraryShop main store

Explainer

Why eWON Flexy BASIC cannot write to MySQL directly

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

Short answer

A Flexy BASIC script has no MySQL client, so no script opens the database directly. The documented route is PUTHTTP sending HTTP to a PHP receiver on a LAN host such as the XAMPP server, which alone speaks MySQL; eSync or DataMailbox with the DMWeb API replaces the custom code when maintenance, not BASIC, is the constraint.

On this page
  1. Can an eWON Flexy BASIC script open a MySQL connection?
  2. What can the BASIC environment send instead?
  3. Can the PHP receiver run on the Flexy's FTP folder?
  4. Where does the middle-man receiver run on a plant LAN?
  5. What must the Flexy send and the receiver promise back?
  6. How much data does a minute-batched push move each day?
  7. What if nobody wants to maintain the PHP receiver?
  8. Which failures leave the table empty on a new push?
  9. Which route should a LAN-only Flexy project take?
  10. Questions asked

A Flexy BASIC script cannot write to MySQL, because the BASIC interpreter ships no database client: no command opens a database connection or speaks its protocol. The documented route runs in two hops. PUTHTTP — documented on page 89 of the BASIC reference guide — pushes the values as HTTP across the LAN to a receiver, and a PHP receiver on a separate host such as the existing XAMPP server turns each request into SQL. Where nobody wants to own that PHP, eSync or the DataMailbox DMWeb API moves the same data with no custom device code. This article explains why the one-hop design is impossible, what the two-hop design costs, and which route fits which constraint.

Can an eWON Flexy BASIC script open a MySQL connection? #

No — the BASIC interpreter has no MySQL client command: nothing in its instruction set speaks the database's login handshake or query protocol, so no script of any length opens a connection to the database engine by itself.

The protocol gap explains why retyping the destination does not help. MySQL expects its own packet format from the first byte on the connection, and an HTTP request arriving at the database's service port is a protocol error, not a query. Pointing PUTHTTP at the database host's address changes where the bytes land, not what the bytes mean, because the interpreter has no vocabulary for login packets, authentication exchanges or SQL strings.

That wall stands in front of every device whose scripting offers file and web transfers only, and the architectural answer is the one set out in why an edge gateway needs an HTTP endpoint to write a database: the endpoint process owns the database session, and the device owns the measurement. The Flexy's job ends at the HTTP boundary.

What can the BASIC environment send instead? #

The documented outbound options are file transfers and HTTP calls — PUTHTTP is the command the BASIC reference guide documents for pushing data to a web service, on page 89 — plus the device's own eSync and DataMailbox services, and none of them opens a database session.

PUTHTTP sends an HTTP request to a URL the script builds, which makes a web service the only far end the command understands. Read its exact parameters — URL, authentication, payload placement — from the reference guide for the installed firmware rather than from memory, because the parameter list is where firmware revisions differ. PUTFTP moves files by the same logic, and moving a file is not executing one, which is exactly the next question.

Equally important is what the command set lacks: no database connector, nothing aimed at a protocol other than HTTP or FTP. The middle-man is not a detour around a missing option; with this command set it is the only route from script to database.

Can the PHP receiver run on the Flexy's FTP folder? #

No — the device's FTP folder stores files and hands them out; it contains no PHP interpreter and no web server that would execute one, so a receiver uploaded there never runs and never reaches the database.

PHP is a program that a web server loads and runs. Uploading a receiver script over FTP puts its text on the device's storage, where nothing executes it; a request sent to the Flexy expecting that file to run returns nothing useful. Storage and execution are different facilities, and the device offers only the first.

This settles the architecture argument before any code is written. LAN-only describes where the traffic travels, and a receiver on the plant LAN satisfies it completely. Execute-everything-inside-the-device describes where the program runs, and nothing in the BASIC environment satisfies that with a MySQL database at the end. Decide which requirement is the real one now, because the routes below diverge from this point.

Where does the middle-man receiver run on a plant LAN? #

On any PC on the plant LAN that runs a web server with PHP and a MySQL client library — the XAMPP host already in the office qualifies — as long as the Flexy can reach its LAN address and the receiver can reach the database.

Address the receiver by its LAN interface address, for example 192.168.1.50, never by the server's own loopback address: a browser test run on the server proves only that the local stack answers itself, and a loopback destination sent from the Flexy would name the Flexy instead. Test from a second authorized machine and read the web server's access log — an entry there moves the investigation past the network, while no entry keeps it on address, port, listener, firewall or route.

The receiver host also needs the database reachable from itself, on whatever host MySQL runs, through an account limited to the inserts the contract needs. When the office desktop that happens to host XAMPP is not a machine you want carrying plant history, this receiver role is the natural job for a fanless mini PC mounted in the cabinet instead. Keep the receiver and its database inside the plant network, and do not bridge them to the office or internet side without segmentation: an open web stack on a plant LAN is the shortest path from a convenience setup to an incident.

What must the Flexy send and the receiver promise back? #

Fix five things before either side is written: a device identifier, the measurement timestamps, tag names with units and decimal precision, the batching rule, and the single response string that means the transaction committed — every other response is a receipt, not a delivery guarantee.

Every batch carries its device identifier, the time each sample was measured rather than the time it was sent, tag names with their units, and a sequence marker that makes a duplicate delivery detectable; missing values get a defined representation instead of an empty slot. The form below is an illustrative contract — the device name, address and timestamp are examples, and PUTHTTP's own parameter syntax comes from your firmware's reference guide:

POST /receiver.php on 192.168.1.50
Content-Type: application/x-www-form-urlencoded

device=flexy01&seq=2025-03-04T08:12:00Z&count=600
data=600 rows of tag,timestamp,value, separated by semicolons

The response boundary is where data loss hides. A web server status of 200 proves only what the receiver chose to acknowledge. If the PHP replies before the database transaction commits and the commit then fails, the Flexy has discarded samples it believes are stored and will never send them again. The receiver says COMMITTED only after the commit returns clean, treats every other reply as not delivered so the script side can hold the batch for retry, and keeps the detail of any failure — anything that names the database, its account or its address — in its own server-side log.

How much data does a minute-batched push move each day? #

At 10 tags sampled every second and one request per minute, the Flexy moves 600 samples — about 105,000 bytes — per request, 1,440 requests and 864,000 database rows per day, and that cadence is the design point the receiver, the LAN and the table must absorb.

State the inputs and follow the arithmetic: 10 tags at 1-second intervals, batched one minute at a time, give 10 × 60 = 600 samples per request. Encode each sample as a 25-byte timestamp plus 10 values at 15 bytes each: 25 + (10 × 15) = 175 bytes, so 600 × 175 = 105,000 bytes per request. One request per minute is 86,400 ÷ 60 = 1,440 requests per day, the LAN carries 1,440 × 105,000 = 151,200,000 bytes — about 151 MB daily — and the database receives 600 × 1,440 = 864,000 rows per day.

Push per sample instead and the request count rises 60-fold to 86,400 per day, each request now carrying header overhead on just 175 bytes of payload, while the database load stays identical; per-sample pushing buys faster arrival and nothing else. Off the plant LAN the same traffic is about 4.5 GB every 30 days (151 MB × 30), which is why batching matters more on a cellular site than inside the cabinet row.

What if nobody wants to maintain the PHP receiver? #

Then do not write it: eSync or the DataMailbox pull through the DMWeb API moves the same values with no custom device code, at a documented pace of one synchronization or data lookup each minute on the Free DataMailbox plan.

eSync is the vendor's synchronization service: the Flexy pushes its data into DataMailbox and eSync delivers it onward to the target, with configuration on the device side instead of script. The DataMailbox route swaps the push for a pull — the Flexy synchronizes into DataMailbox as usual, and a short server-side poller calls the DMWeb API, reads what arrived, and writes MySQL from that. The API's transactionId parameter marks what a pull has already taken, so the next pull resumes where the last one stopped. One synchronization or data lookup each minute is the documented pacing on the Free plan, and that number decides the route: when one-minute freshness satisfies the process, the no-script route wins; when the application needs every second, the PUTHTTP receiver stays.

The pull-side pattern — a program beside the database that owns the writes — is the same one collector agents follow, as in routing Telegraf SNMP metrics to separate InfluxDB databases, where the agent sits next to the database and controls storage itself.

Which failures leave the table empty on a new push? #

When a new push leaves the table empty, check three faults in order: a destination set to a loopback address, a web listener bound to a local interface only, and a receiver that answered before its database commit.

The loopback fault hides behind a passing test: the receiver answers perfectly in a browser on its own host, so the stack looks healthy, while the Flexy's destination must be the LAN interface address to mean the same machine. The listener fault looks identical from outside: a web server bound to a local interface accepts only traffic that originates there, so compare the configured listening address and port with the destination the script targets before touching the script. The ordering fault is silent: the web server reports success, the table stays empty, and only the receiver's own log shows the failed commit — which is why the COMMITTED-only-after-commit rule above is not optional polish.

A fourth failure arrives as text instead of execution: when the web server returns PHP source rather than running it, the Flexy receives a file, the table stays empty, and the source — credentials included — has just left the server. Close that exposure immediately and repair the PHP handler before the next request. And when the receiver itself cannot open its database connection, that hop ends in a refused connection, whose diagnosis order — listener, account, port — is the one traced in fixing ECONNREFUSED when Node-RED connects to a remote SQL database.

Which route should a LAN-only Flexy project take? #

BASIC-only with no middle-man cannot be built; a LAN push through a PHP receiver is the documented PUTHTTP route; and when custom code is the blocker, eSync or the DataMailbox pull delivers at the DMWeb API's documented pace.

So the three cases close like this. If the requirement says every step must execute inside the device, the requirement cannot be met with this scripting environment — no wording of the script will conjure a MySQL client, and it is the requirement that needs rewriting, not the code. If a LAN receiver is acceptable, build the two-hop route as specified above: minute-sized batches, a COMMITTED reply only after the commit, device identifier and measurement timestamps in every row, and a table design that budgets the 864,000 rows per day of the example load. If writing and maintaining the receiver is the real obstacle, take eSync or the DataMailbox pull and treat its pacing as the freshness floor the process must tolerate.

The whole decision is three lines long: the Flexy measures and pushes HTTP, something with a MySQL client library writes the database, and the only remaining choice is whether that something is your PHP or the vendor's synchronization service.

Questions asked

Can PUTHTTP deliver data straight to MySQL on port 3306?

No. MySQL expects its own packet format from the first byte of the connection, so an HTTP request arriving on the database port, 3306 by default, dies as a protocol error before any login or query. PUTHTTP speaks HTTP only, which is why the far end must be a web service that holds the MySQL side of the conversation.

Does the receiver host need MySQL installed on the same machine?

No. The receiver needs a PHP MySQL client library and network reachability to the database server, wherever that server runs. MySQL on a dedicated host works as long as the receiver can open a connection to it and its account can insert into the target tables. Many plants keep the database on its own server and leave the receiver host running only the web stack.

What should the receiver do when a retried batch arrives twice?

Make duplicates harmless in the schema instead of in the script. Give the table a unique key over device identifier, tag name and sample timestamp, then write each row with INSERT IGNORE or an equivalent upsert, so a redelivered batch changes nothing. The key also enforces the contract: one value per tag per timestamp per device, guaranteed by the database rather than by the next maintainer of the PHP.

Can one receiver collect from several Flexy units at once?

Yes, and the contract already supports it, because every batch carries its device identifier and one receiver table can hold all units. Size the web server and the database for the combined rate rather than one device's: ten units at the example load mean ten times the request count and the rows. A separate database account per unit keeps each device's writes separable in the audit log.

Keep reading

  • How-to

    Connect Node-RED on ctrlX CORE to a MySQL server

    Send the SQL as msg.topic to a node-red-node-mysql node: create the table once as an administrator, prove one INSERT and SELECT from Inject nodes, then route Read Datalayer values into a multi-row insert. Grant the runtime account only SELECT and INSERT on db1, match its host part to the client address the server reports, and keep a local snap's data directory on external media.

    Edge computing and IIoT

  • Comparison

    Ignition to InfluxDB: REST, module or historian with SQL

    Ignition's Tag Historian and transaction groups write through JDBC connections, and InfluxDB offers only an HTTP write endpoint, so there is no standard history path between them. Choose gateway-side REST writes, a dedicated third-party InfluxDB module, or keep the historian on a supported relational database such as PostgreSQL or MySQL. A working live display proves tag acquisition, not a stored sample.

    Edge computing and IIoT

  • How-to

    Save Node-RED OPC UA values to MySQL through a template insert

    Wire the OPC UA client, a Template node and the MySQL node in series. The Template node builds INSERT INTO test.prosys_table (Counter, Time) VALUES from the measured value plus Now(), and places the finished statement on msg.topic, because the MySQL node reads its query from msg.topic and returns results in msg.payload. Then prove the row with a SELECT.

    Edge computing and IIoT

Configuring OPC UA to MySQL writes with a Template node