IMD SolutionComputing LibraryShop main store

Troubleshooting

Why an S7 endpoint shows ECONNREFUSED 127.0.0.1 in Node-RED

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

Short answer

The refused connection is a stale S7 endpoint configuration node still targeting the gateway's own loopback address on TCP port 102, and Node-RED retries it after every deploy even when no node in the flow uses it. Delete that endpoint under configuration nodes, or point it at the PLC's real address. The -1 digital-input readings are a separate fault: validate them against the add-on's documented return values and never coerce a failed read to true.

On this page
  1. Two faults in one debug pane
  2. Decoding the deploy error connect ECONNREFUSED 127.0.0.1:102
  3. Delete or re-address the stale endpoint
  4. Diagnosing the -1 digital inputs on their own
  5. Never turn a failed read into a sensor state
  6. Checks that close each fault
  7. Questions asked

The refused connection and the -1 input values are two separate faults, and fixing one proves nothing about the other. Error connecting to PLC: Error: connect ECONNREFUSED 127.0.0.1:102 arriving right after a deploy means a saved S7 endpoint configuration node still targets the loopback address of the machine Node-RED runs on, with the S7 protocol's TCP port as its destination. Node-RED retries such an endpoint on every deploy even when no node on the sheet uses it, so the fix sits in the configuration-node list, not in the flow: delete the endpoint or point it at the controller's plant address. The -1 readings belong to the input read path and need their own diagnosis against the wiring, the channel mapping and the add-on's documented return values.

Two faults in one debug pane #

In the case behind this article, two light barriers are wired to terminals DI0 and DI1 of the Input/Output add-on module, and the flow polls them as channels DI12 and DI11 to match the module's channel layout. The -1 values appear either immediately after a deploy or after a few sensor transitions, and the S7 connection error arrives right after redeployment. Read the observations as separate evidence:

  • -1 on an input channel — the read returned something other than a discrete state. Interpret it against the input add-on's documented return values before any logic consumes it.
  • Connection refused right after a deploy — a TCP connection attempt was actively refused by the destination. For this destination the cause is the endpoint's address, not the sensors.
  • Node-RED unusable after a fault — a stopped runtime and an unresponsive editor are different failures. The runtime log and the process state at the failure time tell you which one you have.
  • No change between the 1000 ms and 100 ms update intervals — polling speed is not the cause, so stop tuning the interval and move to the read path.

Clearing the endpoint error will not change the input readings, and repairing the inputs will not remove the connection error. Each fault gets its own acceptance check at the end of this article.

Decoding the deploy error connect ECONNREFUSED 127.0.0.1:102 #

Inputs. The debug pane shows Error connecting to PLC: Error: connect ECONNREFUSED 127.0.0.1:102 immediately after a redeploy. From that line come the two facts that matter: destination address 127.0.0.1 and destination port 102. The documented context around them: the S7 protocol runs over TCP port 102 at the controller, and the IPv4 loopback block is 127.0.0.0/8, covering 127.0.0.0 through 127.255.255.255. The controller in this worked example sits on the plant network at 192.168.1.50 — an example address; substitute your own.

Rule. Split the destination into address and port. An address whose first octet is 127 lies inside the loopback block and can only mean the machine the runtime itself runs on; no external device can hold such an address. Port 102 identifies the S7 service. ECONNREFUSED means the target machine actively refused the TCP connection: the address was reachable, but nothing was listening on that port.

Arithmetic. First octet of the destination: 127. The block 127.0.0.0/8 leaves 32 − 8 = 24 host bits, so it holds 2^24 = 16,777,216 addresses and every one of them is loopback; the destination is the second address in that range. The example controller address begins with 192, outside the block. The endpoint therefore aims at no controller at all — it aims at the gateway running Node-RED.

Result. The gateway runs Node-RED but no S7 server, so nothing listens on TCP 102 locally and the TCP stack refuses the attempt. The message appears right after a deploy because the saved endpoint reconnects at deploy time, which is also why the error shows up when no S7 node sits anywhere on the sheet.

Decision. An S7 endpoint whose address begins with 127 is pointed at the machine itself, which for a plant-network controller is always wrong. If the flow needs S7 data, set the endpoint address to the controller's plant address — 192.168.1.50 in this example — and confirm nothing between gateway and controller blocks that port. If the flow needs no S7 data, delete the endpoint. The only legitimate loopback endpoint is a deliberate S7 server on the same machine.

Delete or re-address the stale endpoint #

S7 nodes keep their connection as a separate configuration node. The node-red-contrib-s7 package and its S7+ variant both work this way — in the S7+ node you create the endpoint in the node's settings with the PLC IP address — and the endpoint stays in the project once created, even after you delete every node that used it. That is why the flow sheet alone never shows the culprit.

  1. Save a copy of the flow first, so the endpoint settings and the flow can be restored if the wrong object gets deleted.
  2. Open the menu bar and choose the Configuration nodes view. Entries no longer referenced from the sheet still appear here.
  3. Double-click the S7 endpoint. Read its configured address and note which nodes, if any, still reference it.
  4. Delete the endpoint when the flow does no S7 communications. If it does, replace the loopback address with the controller's plant address, unless a local S7 server is a deliberate part of the design, and set the endpoint's timeout and TSAP fields to what your controller connection requires.
  5. Deploy and read only the fresh debug output, comparing new entries against old ones by timestamp.

Deleting is the right call when the flow genuinely does no S7 work; if controller data is still needed but not over S7, the overview of how Node-RED reads PLC data covers the OPC UA, MQTT and Modbus routes that replace it.

Expected result: no further connection attempt to the loopback address, or a connection to the controller that completes. A correctly addressed endpoint can still be refused when a firewall blocks that port, the controller is powered down or the TSAP pair does not match — ordinary faults, but now at the right destination. Refusal is also not the only way a Node-RED link breaks: a name that never resolve looks different, as in the article on a Node-RED MQTT node that shows connecting when the host cannot resolve, and the same refusal pattern appears away from S7 when a local OPC UA historian endpoint refuses connections for its own reasons.

Diagnosing the -1 digital inputs on their own #

Removing the endpoint changes nothing about the input readings, so work the read path separately. The first suspect is the mapping: the two sensors sit on terminals DI0 and DI1 while the flow polls channels DI12 and DI11, a choice made to match the module's channel layout. A polled identifier that does not correspond to the wired terminal produces readings that look arbitrary, so confirm that layer before anything else.

  • Wiring reference. The module common M0 is connected to 0 V in this installation, giving the input circuit its electrical reference. With the sensor supply in place, measure each sensor output against that reference in both sensor states and compare the levels with the module documentation's input-state ranges. The common's presence alone proves neither the sensors nor the terminal choice.
  • Terminal-to-channel mapping. Trigger one sensor at a time and watch the debug pane: exactly one polled channel must change, and it must be the channel you expect for that terminal.
  • Isolated read path. Trim the flow to the input read plus debug output, leaving downstream processing disconnected. A failure that survives the trim lives in the read path; one that appears only after a stage is reconnected belongs to that stage.
  • Complete messages. Capture the whole message around a transition — payload, data type, node status and any error output — and read the input add-on's documentation for what -1 means for its nodes. A read library commonly returns a negative value for a failed or incomplete read, but the package's own documentation decides for its return values.
  • What actually stops. When the fault hits, note whether the runtime exits, restarts, keeps logging, or only the editor freezes. The runtime log line from that moment names the failing component; keep it with any report you file or post.

Interval tuning is already exhausted: the tried settings ran from 1000 ms down to 100 ms with no improvement, so changing the interval again is not part of this diagnosis.

Never turn a failed read into a sensor state #

A digital input has exactly two electrical states, and -1 is neither. Logic that treats any nonzero number as true can convert a failed read into a detection, so route values outside the documented states to diagnostics and let the application state explicitly what a failed read means. If these light barriers take part in anything that protects a person or stops a machine, that protective function stays with the barrier's validated safety function: a polled value on a Node-RED gateway is not a safety signal, and a -1 must never stand in for either barrier state.

Checks that close each fault #

Run the two faults against separate acceptance criteria — a clean connection log proves nothing about the sensors, and correct readings prove nothing about the endpoint.

  • Deploy check: after the next deploy the fresh debug output shows no connection attempt to a loopback address; the endpoint you kept connects to the controller address you set.
  • Channel check: trigger each light barrier separately. Only its mapped channel changes, and the value matches the documented state representation.
  • Transition check: repeat several transitions at the update interval you actually run. No unexplained -1 readings, no runtime exit, no frozen editor.
  • Restore check: bring back any trimmed stages one at a time; each stage preserves valid input handling.
  • Log check: at every later failure, capture the runtime log line from that moment. A report that names the failing component and its log line is answerable; a symptom without one is a guess.

The decisions, one per fault: a connection refused to a loopback address on the S7 port is a stale endpoint — delete it or re-address it under Configuration nodes and confirm the connection to the real controller. Input channels returning -1 are a read-path fault — verify the wiring reference and the channel mapping against the module documentation, read the add-on's documented return values, and keep failed reads out of every state decision.

Questions asked

Why does the S7 connection error appear when no S7 node is in my flow?

Configuration nodes live outside the flow sheet. Once an S7 endpoint has been created, it stays in the project, and every deploy makes it reconnect even when no node on the sheet still references it. Open the menu bar, choose Configuration nodes, double-click the S7 endpoint and delete it if the flow does no S7 communications.

What address and port should a working S7 endpoint use?

Use the controller's own plant-network address, not the loopback address of the machine Node-RED runs on, for example 192.168.1.50 instead of 127.0.0.1. The S7 protocol runs over TCP port 102 at the controller, so that port must be open on the controller and not blocked by any firewall between it and the gateway. Check the endpoint's timeout and TSAP fields against your controller connection as well.

Does deleting the endpoint also fix the -1 input readings?

No. The endpoint fix only stops the refused connection attempts. The -1 values come from the input read path: verify the module common wiring such as M0 to 0 V, confirm each polled channel identifier matches the wired terminal, and compare every returned value against the input add-on's documented return values before trusting it.

Can I convert a -1 input to false, or just ignore it?

Treat -1 as a failed or unknown read, not as a state. A digital input has two documented electrical states; -1 is neither, and logic that treats any nonzero number as true can turn a failed read into a false detection. Route out-of-range values to diagnostics and make the application's handling of a failed read explicit.

The fault did not change when I adjusted the update interval. What now?

In the installation behind this article, intervals from 1000 ms down to 100 ms made no difference, which rules out polling speed as the cause. Move from the interval to the layers that actually produce the value: the wiring reference at the module common, the terminal-to-channel mapping, and the runtime log entry recorded at the moment the fault occurs.

Keep reading

  • Troubleshooting

    Fix ECONNREFUSED when Node-RED connects to a remote SQL database

    ECONNREFUSED 127.0.0.1:3306 means the MySQL node dialed loopback on the machine running Node-RED, so the database computer was never contacted. Put the database computer's LAN address in the node's Host field, confirm MariaDB listens on that interface with TCP 3306 open, and create the account with the edge device's address as its host part.

    Edge computing and IIoT

  • Troubleshooting

    node-red-industrial snap upload failed with exit status 1

    The exit status 1 upload error on a ctrlX CORE almost always means the snap is built for amd64 instead of arm64. Confirm the cause in the device diagnostic log, download with UBUNTU_STORE_ARCH=arm64, verify meta/snap.yaml lists arm64, then enable unknown sources and re-upload.

    Edge computing and IIoT

  • Selection guide

    Selecting a Revolution Pi Connect gateway for S7-1500 and Azure MQTT

    A RevPi Connect covers both jobs: two Ethernet ports separate the PLC network from the Azure uplink, up to five extension modules carry the analog and fieldbus hardware, and Node-RED is preinstalled. Size the analog side by counting 4-20 mA loops against the AIO's current-capable channels, and take Modbus TCP for the read-only feed so the S7-1500 keeps PUT/GET closed.

    Edge computing and IIoT

Extract single InfluxDB fields from Node-RED for a dashboard chart