# Haas CNC to MQTT

> PLCGateway reads Haas mills and lathes through their built-in Machine Data Collection (Q commands) and publishes status, parts, cycle times and spindle values to your MQTT broker.

Haas controls answer Q commands on a TCP port once Machine Data Collection is switched on with Setting 143. The answers are comma-separated text made for a terminal, not for an IoT platform. PLCGateway sends the commands cyclically, turns the answers into typed tags and publishes each one as an MQTT topic with value, quality and timestamp.

Nothing is installed on the machine: the gateway runs on a PC, a Linux computer or an ARM device in the same network and reads many machines at once.

- **Source:** [Haas machine data collection](https://plcgateway.com/protocols/haas.md) (`haas_q`)
- **Connection:** TCP · port of Setting 143
- **Target:** [MQTT](https://plcgateway.com/integrations.md)
- **Writing:** yes
- **Included in:** PLCGateway Connect, PLCGateway SCADA, PLCGateway Embedded

## Set it up in five steps

1. On the machine set Setting 143 (Machine Data Collection) to a TCP port, for example 5051.
2. Add a Haas device with the IP address and the port.
3. Create the tags for status, program, parts and spindle.
4. Open Gateway → MQTT, enter the broker address, port and login, switch on TLS if the broker requires it, and choose the base topic.
5. Choose publishing on change or at an interval and the JSON or plain-value format, then check the topics with mosquitto_sub or in your platform.

## Example: topics and payloads

A device with the id vf2 and these tags is published as shown below; the lines are what mosquitto_sub -v prints. Names and values are examples.

| Tag | Address | Example value |
|---|---|---|
| `Running` | `running` | true |
| `Status` | `status` | BUSY |
| `Parts` | `parts` | 352 |
| `SpindleRpm` | `spindle_rpm` | 7500 rpm |
| `LastCycle` | `last_cycle` | 184 s |

**MQTT topics and payloads**

```
plcgateway/status online
plcgateway/vf2/Running {"q":"GOOD","t":1794465246839,"v":true}
plcgateway/vf2/Status {"q":"GOOD","t":1794465246839,"v":"BUSY"}
plcgateway/vf2/Parts {"q":"GOOD","t":1794465246839,"v":352}
plcgateway/vf2/SpindleRpm {"q":"GOOD","t":1794465246839,"u":"rpm","v":7500}
plcgateway/vf2/LastCycle {"q":"GOOD","t":1794465246839,"u":"s","v":184}
```

Topic: base topic / device id / tag name. The JSON payload carries the value (v), the quality (q), the timestamp in milliseconds (t) and the unit (u).

## The MQTT publisher in PLCGateway

PLCGateway publishes every tag to your MQTT broker – Mosquitto, EMQX, HiveMQ, AWS IoT Core or a cloud platform behind a bridge – so IT systems subscribe to topics instead of polling the controller. It speaks MQTT 3.1.1 over TCP or TLS, with user name and password.

Values are sent when they change or at a fixed interval, as JSON with quality and timestamp or as the bare value. A retained status topic with a last will tells subscribers whether the gateway is online.

- One topic per tag: base topic / device / tag, with a base topic of your choice
- QoS 0 or 1, retained messages, birth message and last will
- Optional writing: a value published to the tag's /set topic is written to the controller
- Messages are queued while the broker is unreachable and sent after the reconnect

![MQTT publisher settings: broker, TLS, base topic, publish mode and payload format](https://plcgateway.com/assets/img/shots/mqtt-1400.webp)

## Controllers and devices

- [Haas machine data collection](https://plcgateway.com/protocols/haas.md)
- [Haas Automation](https://plcgateway.com/controllers/haas.md)

## Questions and answers

### Which Haas controls can be read?

Machines with the Next Generation Control (NGC) and Classic controls that offer Machine Data Collection over Ethernet. NGC machines can also be read through MTConnect.

### Which data arrives on the broker?

Status and running state, alarm, running program, part counter, last and previous cycle time, power-on and motion time, tool changes and current tool, spindle speed and load, positions and any macro variable.

### Why do program and part count not change while a cycle runs?

While a program is running, the control answers the status query only with BUSY. PLCGateway keeps the last program and part count until the machine reports them again, so subscribers always have a valid value.

## Related solutions

- [Haas CNC to OPC UA](https://plcgateway.com/solutions/haas-to-opc-ua.md)
- [Haas CNC OEE](https://plcgateway.com/solutions/haas-oee.md)
- [FANUC FOCAS to MQTT](https://plcgateway.com/solutions/fanuc-focas-to-mqtt.md)
- [MTConnect to MQTT](https://plcgateway.com/solutions/mtconnect-to-mqtt.md)
- [Siemens S7 to MQTT](https://plcgateway.com/solutions/siemens-s7-to-mqtt.md)
- [Modbus to MQTT](https://plcgateway.com/solutions/modbus-to-mqtt.md)
- [All protocols](https://plcgateway.com/protocols.md)

_Product and model names are trademarks of their owners. They are named only to show which equipment the drivers communicate with; PLCGateway is not affiliated with these companies._

---
Source: https://plcgateway.com/solutions/haas-to-mqtt
