Your first device in 5 minutes
What you’ll build
Section titled “What you’ll build”A Modbus TCP PLC simulator in Docker, and the tedge-dot command line reading its registers,
writing a coil and printing the samples the connector would publish. It runs on Linux and macOS
and needs no MQTT broker, no thin-edge.io and no cloud account: the read and write commands
talk to the device directly.
You need Docker, just and a checkout of the repository:
git clone https://github.com/thin-edge/tedge-dot.gitcd tedge-dotRead the PLC
Section titled “Read the PLC”-
Start the simulator.
just sim modbusstarts the pymodbus simulator used by the Modbus test stack and maps its port 502 to127.0.0.1:5020:Terminal window just sim modbus -
Get the
tedge-dotbinary.With a stable Rust toolchain:
Terminal window cargo build --manifest-path impl/rust/Cargo.tomlalias tedge-dot="$PWD/impl/rust/target/debug/tedge-dot"Download the
tedge-dot-rsarchive for your OS and architecture from the releases page, unpack it, and put thetedge-dotbinary on yourPATH. -
Say where the point lists are. The demo config holds only the simulator’s address; its points come from a point library,
demo/points.d/modbus/demo-sim.toml. An installed package finds its libraries by itself, a checkout has to point at them:Terminal window export TEDGE_DOT_POINT_LIBRARY_PATH=$PWD/demo/points.d -
Read everything. Without
-dand-p,readreads every readable point of every device in the config, once:Terminal window tedge-dot read -c demo/config/modbus.tomlThe simulator is seeded with known values:
temp_u16is17001,count_u32is617001,level_f32is404.17, andtemp_scaledapplies its own scaling to the same register to give17.001°C.boiler_statemaps that register to the labelheating, andbad_pointreads an address the simulator answers with an exception, so it shows bad quality. -
Pick points, and keep polling.
-dand-ptake a name or a wildcard, and-pcan be repeated.--jsonprints the sample envelopes exactly as the connector publishes them:Terminal window tedge-dot read -c demo/config/modbus.toml -d plc1 -p temp_u16 -p level_f32 --jsontedge-dot read -c demo/config/modbus.toml -p 'temp_*' --interval 500ms --count 5
Write to it
Section titled “Write to it”coil_rw and temp_u16 are writable (access = "read_write" in the library). Write a value and
read it back:
tedge-dot write -c demo/config/modbus.toml -d plc1 -p coil_rw --value truetedge-dot write -c demo/config/modbus.toml -d plc1 -p temp_u16 --value 1234tedge-dot read -c demo/config/modbus.toml -d plc1 -p temp_u16 -p boiler_stateboiler_state now reads standby: its value map labels everything up to 9999 that way.
Run the connector without a broker
Section titled “Run the connector without a broker”run is what the service does on a gateway. With --output stdout it prints each sample
envelope as a JSON line instead of publishing it, so you can see the reporting policy at work:
temp_scaled has a deadband and is published only when it moves.
tedge-dot run -c demo/config/modbus.toml --output stdout --duration 10sThe config you just used
Section titled “The config you just used”The [[device]] entry is all there is to a device whose type has a point library: its name, its
address and the library to take the points from.
[[device]]name = "plc1"protocol_address = { transport = "tcp", host = "127.0.0.1", port = 5020, unit_id = 1 }default_mode = "typed"points_from = ["demo-sim"]demo/config/modbus.toml on GitHubWhen you are done, stop the simulator:
just sim-down modbus