Communication Protocols for MachineLogic and MachineMotion AI

Prev Next

Introduction to MQTT

Definitions

  • Client: Device that can send (publish) and receive (subscribe) data

  • Packet: Data sent by a client

  • Topic: Subject line through which packets are sent

  • Broker: Piece of software running on a computer which acts as the transit between another device or another broker

Message Queuing Telemetry Transport (MQTT) is a bi-directional lightweight message protocol which consists of a set of rules that defines how Internet of things (IoT) devices can publish and subscribe to data over the Internet. MQTT is used for messaging and data exchange between IoT and industrial IoT (IIoT) devices, such as embedded devices, sensors, industrial PLCs, and now, MachineMotion.

Each client can produce and/or receive data by publishing and/or subscribing. A client can publish a packet for a given topic, and anyone who subscribes to it can receive a copy of all messages for that topic. Multiple clients can subscribe to a topic from a single broker, and a single client can register subscriptions to topics with multiple brokers. This helps in both sharing data and managing and controlling devices. A client cannot broadcast the same data to a range of topics and must publish multiple messages to the broker, each with a single topic given. With MQTT broker architecture, the client devices and server application become decoupled. This allows clients to communicate with a single common recipient, and therefore funnel all information from the same place.

Programming

MachineLogic allows you to easily program your machine through its graphical interface and its low-code infrastructure. When it comes to MQTT communication, the same simple programming approach applies.  see the examples below showing how to create a MachineLogic program using MQTT communication.

For more information on MachineLogic code-free programming, click here

To subscribe to a given topic, the State Machine or Wait For command can be used.

State machine diagram showing transitions between idle and homing states.

State Machine example in MachineLogic

Configuration settings for waiting for an MQTT message and assigning it to a variable.

Wait For Instruction in MachineLogic

Interface for sending MQTT events with topic and message input fields.

Send MQTT event instruction example

For more complex applications, you can also include payloads via the Variables and Functions features:

Figure 6: Variables and functions feature on MachineLoigc

Variables and function in MachineLogic


Internal MQTT Topics Used in the MachineMotion AI

the MachineMotion AI uses MQTT internally to monitor controller states. It can be convenient to use these topics in your programs when needing to react to an e-stop event, for example.

Safety PLC MQTT Interface

This service monitors the safety PLC within the MachineMotion AI and reports its status.

Broker Address: tcp://machinemotion.local:1883

Topic Summary

All topics listed below are published by the MachineMotion controller. Clients should subscribe to these topics to receive updates.

Topic

Data Type

Description & Values

machine-motion/safety-state

JSON Object

Global Safety State

Reports the overall safety status. Updates on change or startup.


Payload Schema: {"safety_state": <int>}

Values:

-1: ERROR

0: None (Initial/Startup)

1: EMERGENCY_STOP

2: NORMAL

safety-plc/safety-out

Integer

Safety Output Feedback

Provides near-instant feedback when entering an Emergency Stop or Error state.


Values:

1: System OK

0: ERROR or EMERGENCY_STOP state

safety-plc/reset

Integer

Reset State

Monitors the status of the reset port.


Values:

0: OK / Inactive (Assumed default)

1: Active

safety-plc/robot-in

Integer

Robot Input State

Monitors the status of the robot input port.


Values:

0: OK (Assumed default)

1: Active/Triggered

safety-plc/estop-in

Integer

E-Stop Input State

Monitors the status of the physical E-Stop input port.


Values:

0: OK (Assumed default)

1: Active/Triggered

safety-plc/safety-in

Integer

Safety Input State

Monitors the status of the general safety input port.


Values:

0: OK (Assumed default)

1: Active/Triggered

safety-plc/error

JSON Array

Error Reporting

Reports active error codes and descriptions.


Payload Schema: Array of Objects (See Error Object Definition below).


Schema Definitions

Error Object Definition

Used in the safety-plc/error topic.

Format: Array<Object>

JSON

[
  {
    "code": 0,
    "description": "plc-disconnected"
  }
]

Field Details:

  • code (Integer):

    • Range: 0 .. 3

  • description (String):

    • "plc-disconnected"

    • "error-estop"

    • "error-mmai"

    • "error-other"

Motion

Description: MQTT topics pertaining to motors, actuators, and drive configuration.

Broker Connection: tcp://machinemotion.local:1883

Topic Summary

All topics listed below are published by the MachineMotion server.

Topic Variables:

  • {port}: The 1-indexed motor port number.

  • {index}: The 1-indexed motor index (daisy-chain position).

Topic

Data Type

Description & Values

motion-server/state

Integer

Global Motion Server State

Indicates if the server will accept motion/configuration requests.

Values:

0: Disabled

1: Enabled/Ready

drive/{port}/{index}/operational

Integer

Drive Ready Status

Indicates whether a specific drive is ready to move.

Values:

0: Not Ready

1: Ready

drive/{port}/{index}/target-reached

Integer

Target Reached

Indicates if the drive has reached its most recent target (speed, torque, or position).

Values:

0: Moving / Not Reached

1: Target Reached

drive/{port}/{index}/brake-locked

Integer

Brake Status

Indicates whether the drive is currently locking the brake.

Values:

0: Unlocked

1: Locked

drive/{port}/{index}/sensor/home

Integer

Home Sensor Status

Values: 0 (Inactive) or 1 (Triggered)

drive/{port}/{index}/sensor/end

Integer

End Sensor Status

Values: 0 (Inactive) or 1 (Triggered)

drive/{port}/{index}/sensor/A

Integer

Aux Sensor A Status

Values: 0 (Inactive) or 1 (Triggered)

drive/{port}/{index}/sensor/B

Integer

Aux Sensor B Status

Values: 0 (Inactive) or 1 (Triggered)

drive/{port}/{index}/sensor/ignoring

Integer

Sensor Ignore State

Indicates if the drive will ignore home/end sensors during non-homing motion.

Values:

0: Sensors Active

1: Ignoring Sensors

drive/{port}/{index}/error

JSON Array

Drive Error

Describes active error states causing a transition to non-operational.

Schema: Array of Objects

drive/{port}/{index}/temperature

Float

Drive Temperature

Temperature of the motor drive in Celsius.

Example: 35.5

drive/{port}/{index}/update-status

String

Firmware Update Status

Indicates status of ongoing firmware updates.

Values: "running", "done"

drive/{port}/{index}/update-result

JSON Object

Firmware Update Result

The result of the last update process (not retained).

Schema: See FirmwareUpdateResult below.

motor-port/{port}/detected-hardware

JSON Object

Detected Hardware

Details regarding motors detected by MMai on each port.

Schema: See DetectedMotorHardwareInfo below.


Schema Definitions

DetectedMotorHardwareInfo

Used in motor-port/{port}/detected-hardware.

Structure: Object

{
  "motor_address": { "port": 1, "index": 1 },
  "motor_type": "stepServo",
  "motor_size": "NEMA-34-68mm",
  "serial_number": 12345,
  "firmware_version": "1.2.0",
  "hardware_version": "3.0",
  "brake_present": true,
  "encoder_offset": 0,
  "valid_firmware": true
}

Field Details:

  • motor_address (Object): Contains 1-indexed port and index.

  • motor_type (String):

    • "stepServo"

    • "speedControlled"

    • "bldcServo"

    • "conveyorStepServo"

  • motor_size (String): "NEMA-34-68mm", "NEMA-34-100mm", "NEMA-34-157mm", or "UNKNOWN".

  • serial_number (Integer): Range 1 .. 9999999.

  • brake_present (Boolean): true if power-off brake is connected.

  • encoder_offset (Integer): 0 .. 255 (Used to align electrical angle).

  • valid_firmware (Boolean): true if firmware allows motion.

FirmwareUpdateResult

Used in drive/{port}/{index}/update-result.

Structure: Object

{
  "status_code": "failure",
  "message": "Failed to write file: -5 for slave 6"
}

Field Details:

  • status_code (String): "success" or "failure".

  • message (String): Description of the error (if failed).

FirmwareUpdateStatus

Used in drive/{port}/{index}/update-status.

Structure: String

Values:

  • "running"

  • "done"

MMAI IO Expander Hub

Description: This service manages all control modules connected to the MachineMotion AI (MMAI) IO expander hub.

Broker Connection: tcp://machinemotion.local:1883

Topic Summary

All topics listed below are published by the MachineMotion server.

Topic Variables:

  • {ControlPortId}: The ID of the specific control port on the controller.

  • {DeviceId}: The ID of the specific module connected to the port.

  • {InputPin}: The specific digital input pin number.

Topic

Data Type

Description & Values

control-port/{ControlPortId}/version

String

Service Version

The version of the service running on the specific control port.

Format: service_version+build_number.git_hash

.../module/{DeviceId}/available

Integer

Module Availability

Indicates if the module is currently communicating.

Values:

0: Unavailable/Offline

1: Available/Online

.../module/{DeviceId}/type

String

Module Type

Identifies the type of hardware connected.

Values:

"io-expander"

"push-button"

"power-switch"

"push-button-v2"

.../module/{DeviceId}/hw-revision

String

Hardware Revision

The revision number of the physical hardware.

Format: v{Major}.{Minor}

.../module/{DeviceId}/firmware

String

Firmware Version

The firmware version running on the module.

Format: v{Major}.{Minor}

.../digital-input/{InputPin}

Integer

Digital Input State

Reports the binary state of a specific input pin.

Values:

0: Inactive (Low)

1: Active (High)

.../digital-output

JSON Array

Digital Output States

Reports the state of all 4 digital outputs simultaneously.

Schema: Array of 4 Integers (See below).


Schema Definitions

DigitalOutput

Used in the .../digital-output topic.

Structure: Array<Integer> (Fixed length: 4 items)

Description: A JSON array representing the binary state of outputs 0 through 3.

Introduction to HTTP

Definitions

  • Client: A software application or a program such as a web browser that initiates requests to web servers.

  • Requests: the request from the client to the server specifying the URL of the resource it wishes to retrieve as well as the request method (GET, POST, PUT, DELETE).

  • Servers: A software application or a program that listens for incoming requests from clients, processes those requests, and sends back corresponding HTTP responses.

  • Response: Message sent by the server to a client. An HTTP response contains the status line, the response header and response body.

HTTP stands for Hypertext Transfer Protocol. It is an application layer protocol used for data communication on the World Wide Web. HTTP facilitates the transfer of various resources, such as HTML documents, images, videos, and other types of data, between a client (usually a web browser) and a web server.

The basic concept behind HTTP is the request-response model. When a client wants to access a resource hosted on a web server, it sends an HTTP request to the server. The server processes the request and responds with the requested resource, along with an HTTP response containing the status of the request (e.g., success, error, redirection) and additional metadata about the resource. HTTP operates on top of the TCP/IP (Transmission Control Protocol/Internet Protocol) network stack and typically uses TCP as its transport protocol.

Request Methods

as of firmware version 2.12, MachineLogic supports the HTTP methods listed below:

  • GET: The GET method is used to request data from a specified resource. It retrieves data from the server without changing anything on the server’s side. It is commonly used for fetching web pages, images, or other resources.

  • POST: The POST method is used to submit data to be processed to a specified resource. It is often used when submitting forms on web pages, sending data to a server to create new resources or update existing ones.

  • PUT: The PUT method is used to update a resource on the server. It sends the data as a representation of the resource to be updated at a specific URL.

  • DELETE: The DELETE method is used to remove a resource from the server. It sends a request to delete the specified resource.


Programming

MachineLogic’s Code-Free programming allows you to easily program your machine through its graphical interface and its low-code infrastructure. When it comes to HTTP communication, the same simple programming approach applies. To send a HTTP request from MachineLogic, use the Make HTTP Request command and select URL in the Send message to field:

Make HTTP Request Example

Example:
In the following example, we will show how to format application variables so they can be sent using a POST request from MachineLogic Code-Free programming interface. This can be used to send a log of an actuator’s position to an express server:

Step 1: create the application variables:

Figure 12: Creating application variables

Step 2: Format the application variables in json format using lambda functions:

Figure 13: Formatting variables using Lambda Functions

Step 3: Send the HTTP request:

This examples assumes a server is running on port 3169 of the user’s machine listening on the route logPositionData. The server response is encapsulated in the RESPONSE_VARIABLE_1.