How-to
How SIP text becomes MQTT on an edge PC
Short answer
Yes. An edge PC converts SIP text to MQTT by running a SIP user agent and an MQTT client library as separate processes; the translation is application code between them. The PC stays a pure MQTT client on port 1883 or 8883 with QoS 1 and a unique client ID, and never hosts a broker.
On this page
The answer: run a SIP user agent and an MQTT client library as two separate processes on the edge PC, and let application code between them parse the SIP text and republish it. Concretely, the PC registers one dedicated SIP extension with the PBX, then connects outward to the broker on port 1883 plain or 8883 with TLS, publishes at QoS 1 with a client ID unique to the PC, and never hosts a broker. Nothing in the MQTT stack converts anything: the conversion is your code, normally Python or Node-RED, sitting between two unrelated protocols.
Which hops carry the data #
Before choosing software, trace the path. Each hop fails in its own way.
| Hop | Transport and port | What stops here |
|---|---|---|
| Phone to PBX | SIP over UDP, TCP or TLS, 5060 or 5061 | Phone not registered, wrong extension, NAT drop |
| PBX to edge PC | SIP, same transports, your configured SIP port | PC extension not registered, port blocked, no route |
| SIP listener on the PC | local process | library not parsing the method that carries your text |
| PC to MQTT broker | MQTT client over TCP, 1883 plain or 8883 with TLS | broker address, credentials, topic ACL, certificate trust |
The PC is an MQTT client on the last hop and a SIP endpoint on the SIP hop. Those are two independent network roles in one box, and each needs its own reachability test. The failure mode on the MQTT hop is the same one covered in the article on why a device cannot publish MQTT to a broker on your PC.
What counts as SIP text #
SIP is the signaling protocol of RFC 3261, and it carries text in several places. The one your phone system uses decides the implementation.
| Text source | SIP mechanism | What you parse |
|---|---|---|
| Instant message from a phone | MESSAGE method of RFC 3428 | message body, sender URI, Content-Type |
| Caller name or number | INVITE headers, mainly From | header fields |
| Call state | response codes and BYE | status codes and Call-ID |
| Presence or custom events | NOTIFY body | event body |
Do not write the parser from the table alone. Capture one real call or message on the PC's network interface, read the raw SIP, and confirm which method and headers your PBX actually emits.
Choosing the software split #
Three approaches work on an edge PC. One warning first: on PyPI, the package named sip is a binding generator used with Qt, not a VoIP stack. Read the package description before installing, and pick a library that states SIP user-agent or SIP signaling support.
| Approach | SIP side | MQTT side | Fit |
|---|---|---|---|
| Node-RED only | needs a maintained SIP-capable node, verify it exists | built-in MQTT nodes, client only | fastest to wire; SIP support is the weak point |
| Python service | a user-agent library handling registration and MESSAGE or INVITE | an MQTT client library such as paho-mqtt | full control of parsing and retries; more code |
| Hybrid | Python SIP listener emitting events to a local socket or stdout | Node-RED subscribes to that feed and publishes | SIP stays in code, topic mapping stays visual |
The hybrid is the default recommendation: Node-RED owns the broker connection, reconnect behavior and topic mapping, and the small SIP listener owns registration and parsing. If you need only one event type, a single Python service with an MQTT client library is simpler to deploy. Where the MQTT-side flow logic gets nontrivial, the article on Node-RED IO data MQTT setup, which keeps publish and control paths separate, applies directly.
Building the gateway, step by step #
- Provision a dedicated SIP extension on the PBX for the edge PC, with its own credentials. Do not reuse a desk phone account: two registrations fight over the same contact.
- Confirm reachability both ways, PC to PBX on the SIP port and PBX to PC on the port where the listener registers its contact.
- Capture a sample of the text you need, a MESSAGE or an INVITE with the display name, and record the exact headers and body.
- Write the SIP listener to register, receive that event, extract the fields, and emit a structured record with sender, text, timestamp and Call-ID.
- Configure the MQTT client with the broker host, port 1883 or 8883, a client ID unique to this PC, credentials, and the TLS trust store if you use 8883.
- Choose QoS and retain per topic: QoS 1 with retain off for events, retain on for current-state topics.
- Run both processes under a service supervisor so they restart after a reboot or a dropped connection.
- Keep this workload off any process-data path on the same box, with its own log file, so a SIP library fault cannot stall control code.
Worked example: a MESSAGE becomes one MQTT publish #
Inputs, all example values for a plant alarm use case:
- the text arrives as a MESSAGE request per RFC 3428, body
Line 3 feeder tripped, sent from extension214; - the broker is at
192.168.1.60on port 8883 with TLS; - the topic scheme is
plant/<sender>/<event>, and the client ID issip-mqtt-214.
The rule in words: publish one QoS 1 message per received MESSAGE, with the topic built from the sender extension and the payload carrying the body, sender and receive timestamp.
The arithmetic is the UTF-8 payload size, which decides whether the message fits comfortably under a broker's maximum packet size. A typical broker default limit is 256 MB, so a small payload is never the constraint; what matters is the count of messages. One MESSAGE produces exactly one publish:
- topic string
plant/214/message, 17 characters, 17 bytes in UTF-8; - payload, JSON with three fields,
"sender":"214","text":"Line 3 feeder tripped","ts":"2024-05-14T08:31:02Z", about 63 bytes plus envelope; - total under 100 bytes per event.
The result: one publish of roughly 80 bytes on topic plant/214/message at QoS 1. The decision: with QoS 1 the broker acknowledges every event, so a short broker outage delays delivery instead of losing it; if you had chosen QoS 0, that same outage would drop every message sent during it, so for alarm text QoS 1 is the setting to commit to.
Verifying each hop #
- Check the PBX status page: the PC extension shows as registered with the PC's IP address.
- Send a test message to that extension and watch the SIP listener log print the parsed fields.
- From a second MQTT client, subscribe to your topic wildcard and confirm the payload arrives with the exact text and encoding.
- Break the broker connection briefly, trigger another event, and confirm the client reconnects and behaves as designed for QoS and buffering.
- Restart the PC and confirm both services come back and SIP registration renews without manual action.
What breaks this gateway in the field #
| Symptom | Mechanism | Check |
|---|---|---|
| Registration drops after minutes | expiry not renewed, or NAT mapping timed out | registration interval and keep-alive in library and PBX |
| Calls reach the PBX, PC sees nothing | wrong target extension, or firewall blocks inbound SIP | packet capture on the PC interface |
| Broker accepts the connection, no messages appear | topic ACL denies publish | broker log and the account's permissions |
| Duplicates or lost messages after reconnect | duplicate client ID kicks the other session, or QoS 0 loses data | unique client ID per device, QoS 1 for events |
Fix the duplicate-client-ID case the same way the article on MQTT client ID device versus application roles describes: one ID per process per device, never shared.
Questions asked
Does the edge PC need to run an MQTT broker for this?
No. The MQTT side is a client library such as paho-mqtt or a Node-RED MQTT out node pointed at the external broker host and port, 1883 plain or 8883 with TLS. The PC opens one outbound TCP connection per client session, so no server component, listener port or broker configuration on the PC is involved.
Where does a phone actually put the text in SIP?
An instant message arrives as a MESSAGE request defined by RFC 3428, with the text in the request body plus a Content-Type header and the sender in the From header. Caller name and number on a call arrive in the From header of an INVITE under RFC 3261. Capture one real message on the PC interface before writing the parser, because PBX implementations differ in which fields they fill.
Which QoS level should the MQTT publishes use?
Use QoS 1 for event payloads such as message text and call states, so the broker acknowledges each publish and a reconnect does not silently lose events. Set the retain flag off for events. A topic that always carries current state, such as extension registration status, can use retain on so a new subscriber reads the last value immediately.