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 example in MachineLogic

Wait For Instruction in MachineLogic

Send MQTT event instruction example
For more complex applications, you can also include payloads via the Variables and Functions features:
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 |
| JSON Object | Global Safety State Reports the overall safety status. Updates on change or startup. Payload Schema: Values:
|
| Integer | Safety Output Feedback Provides near-instant feedback when entering an Emergency Stop or Error state. Values:
|
| Integer | Reset State Monitors the status of the reset port. Values:
|
| Integer | Robot Input State Monitors the status of the robot input port. Values:
|
| Integer | E-Stop Input State Monitors the status of the physical E-Stop input port. Values:
|
| Integer | Safety Input State Monitors the status of the general safety input port. Values:
|
| 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 |
| Integer | Global Motion Server State Indicates if the server will accept motion/configuration requests. Values:
|
| Integer | Drive Ready Status Indicates whether a specific drive is ready to move. Values:
|
| Integer | Target Reached Indicates if the drive has reached its most recent target (speed, torque, or position). Values:
|
| Integer | Brake Status Indicates whether the drive is currently locking the brake. Values:
|
| Integer | Home Sensor Status Values: |
| Integer | End Sensor Status Values: |
| Integer | Aux Sensor A Status Values: |
| Integer | Aux Sensor B Status Values: |
| Integer | Sensor Ignore State Indicates if the drive will ignore home/end sensors during non-homing motion. Values:
|
| JSON Array | Drive Error Describes active error states causing a transition to non-operational. Schema: Array of Objects |
| Float | Drive Temperature Temperature of the motor drive in Celsius. Example: |
| String | Firmware Update Status Indicates status of ongoing firmware updates. Values: |
| JSON Object | Firmware Update Result The result of the last update process (not retained). Schema: See FirmwareUpdateResult below. |
| 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-indexedportandindex.motor_type(String):"stepServo""speedControlled""bldcServo""conveyorStepServo"
motor_size(String):"NEMA-34-68mm","NEMA-34-100mm","NEMA-34-157mm", or"UNKNOWN".serial_number(Integer): Range1..9999999.brake_present(Boolean):trueif power-off brake is connected.encoder_offset(Integer):0..255(Used to align electrical angle).valid_firmware(Boolean):trueif 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 |
| String | Service Version The version of the service running on the specific control port. Format: |
| Integer | Module Availability Indicates if the module is currently communicating. Values:
|
| String | Module Type Identifies the type of hardware connected. Values:
|
| String | Hardware Revision The revision number of the physical hardware. Format: |
| String | Firmware Version The firmware version running on the module. Format: |
| Integer | Digital Input State Reports the binary state of a specific input pin. Values:
|
| 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:
.png)
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:

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

Step 3: Send the HTTP request:
.png)
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.