Watch a fleet, command it over a Web API
Read robot records over WAMP and pause a robot with a Web API route, on the practice fleet.
The body template
The practice fleet's pauseRobot route sends this body. jsonrpc, id and method are locked. robot_id is marked fixed as AMR1, and the instruction fills only paused.
{ "jsonrpc": "2.0", "id": 1, "method": "pauseRobot",
"params": { "robot_id": "AMR1", "paused": true } }paused on pauses the robot. paused off resumes it. An answer with an error member, such as an unknown robot, is a failed request.
Set it up
- Start the Connection Service. Stop the PLC and add a WebSocket Link. Set Protocol to WAMP, click Practice server, and keep the Realm practice.
- Click Import catalog… and tick Robot states. Add a receive tag with Topic robots.states, Record where id Equals AMR1, and Field paused. Add another on Field battery.
- Add a Web API Link. Click Import API document and choose the practice fleet document: with the Connection Service running, save http://localhost:8766/openapi.json as a file and choose it. pauseRobot in the Commands module is already ticked: leave it ticked and click Import.
- In the route Body, click Mark fixed on robot_id and type AMR1. Leave paused for the instruction.
- In a rung, run a WEB API instruction on the pauseRobot route. Send paused on when your cell input is off and off when it returns, and send only when the received paused differs. Put a Rising Edge (ONS) before the instruction so it sends once for each change, not on every scan.
- Turn the cell input off. Watch the WAMP paused tag go on, then turn the input on and watch it go off.
Check before you run
- The lesson sends commands only to the practice fleet. A Web API route sends the request you defined, and it never decides what a real fleet does.
- The fleet system keeps its own traffic control and safety. A paused flag is a request the fleet answers, not a safety function.
- This rung resumes any paused AMR1. A real program should resume only a pause it asked for.
- A WAMP Link only receives. It has no send tags, so every command goes through the Web API Link.
- Wait for the paused tag to change before you send the opposite value, or a quick resume can be lost.
- A failed request leaves paused unchanged and PauseRequest on, so the Rising Edge never fires again. Turn the cell input on, then off, to retry.
If it will not connect
Check the Connection Service indicator, the device or server address, and the Link’s diagnostics. A saved mapping does not mean the device is connected. Stop the PLC before changing the Link.