spiderlive-bridge
v0.2.0
Published
Modbus TCP <-> WebSocket bridge connecting OpenPLC to the SpiderLive web simulator (virtual plant)
Downloads
298
Maintainers
Readme
SpiderLive Bridge
Connects OpenPLC (the real PLC runtime, Modbus TCP master) to the SpiderLive web simulator (the virtual plant, in the browser).
[OpenPLC Runtime] ──Modbus TCP──▶ [bridge] ──WebSocket──▶ [SpiderLive browser]
runs your ladder master slave/relay plant cylinders + sensorsOpenPLC runs your program and treats SpiderLive as its field I/O: it writes the solenoids (coils) and reads the sensors/buttons (discrete inputs). The bridge exists because a browser cannot speak raw Modbus TCP.
Run it
Requires Node.js 18+. No clone needed — run it straight from npm:
npx spiderlive-bridge…or install it as a command:
npm install -g spiderlive-bridge
spiderlive-bridgeIt starts the Modbus slave (:502) and the WebSocket server (:8080).
Ports are configurable: MODBUS_PORT, WS_PORT, MODBUS_HOST, UNIT_ID.
From source (dev):
git clone https://github.com/JohanWences/spiderlive-bridge
cd spiderlive-bridge && npm install
npm start # the bridge
npm run mock # (second terminal) a stand-in plant to test the loopI/O map
Coils — PLC outputs → plant (OpenPLC writes):
| Coil | Signal | PLC addr | |----|--------|------| | 0–5 | Solenoid, cylinder A–F | Q0.0–Q0.5 | | 6 | Signal tower green (running) | Q0.6 | | 7 | Signal tower red (emergency) | Q0.7 |
Discrete inputs — plant → PLC (OpenPLC reads):
| Input | Signal | PLC addr | |----|--------|------| | 0 | START button | I0.0 | | 1 | STOP 1 | I0.1 | | 2 | STOP 2 | I0.2 | | 3 | EMERGENCY | I0.3 | | 4–9 | a1 — extended, cylinder A–F | I0.4–I1.1 | | 10–15 | a0 — retracted, cylinder A–F | I1.2–I8.1 |
Configure OpenPLC
Automatic (OpenPLC Runtime v4)
v4 has no UI for the Modbus master, so the bridge configures it for you. Run once:
npx spiderlive-bridge --setup-openplcThis locates your OpenPLC Runtime install, writes the full I/O map (16 discrete
inputs + 8 coils, the table above) into the modbus_master plugin config, and
enables the plugin. Then restart the runtime (just restart — don't re-upload)
and npx spiderlive-bridge.
The config is the same for everyone — it maps the PLC's whole fixed address space,
so any program works as long as it uses %IX0.0–%IX1.5 / %IX8.0–8.1 and
%QX0.0–%QX0.7. Only the install path differs per machine, and it's auto-detected
(pass --path "<dir>" if it isn't found).
v4 re-disables the master when you re-upload a program. Re-run
--setup-openplcafter re-uploading (a plain restart keeps it).
Manual (OpenPLC v3 / others)
If your runtime has the Slave Devices UI, add a device pointing at the bridge:
- Protocol: Modbus TCP
- IP:
127.0.0.1(same machine) · Port:502· Slave ID:1 - Discrete Inputs: start
0, size16→ mapped to%IX(sensors + buttons) - Coils: start
0, size8→ mapped to%QX(solenoids + tower)
Then write your ladder against those %I / %Q and run it. OpenPLC polls the bridge
every scan; SpiderLive reacts in real time.
Next step: the SpiderLive browser app connects to
ws://localhost:8080in "Connected (Modbus)" mode — solenoid coils drive the cylinders, and the a0/a1 sensors + buttons are sent back to OpenPLC.
