# MQTT problems. (nodes, messages and python)

**URL:** https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715
**Category:** General
**Created:** [5 June 2021 03:27 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715 "2021-06-05T03:27:45Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [5 June 2021 03:27 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/1 "2021-06-05T03:27:46Z")

</div>

(How has to become this complicated?)

I have a python script running and I added this line:  
`client.publish("alarm_clock/oops",text)`

I then have an `MQTT IN` node and set it so:

```auto
[{"id":"20f5e9bf.b0c9f6","type":"mqtt in","z":"eff5d6e6.236338","name":"","topic":"alarm_clock/received","qos":"2","datatype":"auto","broker":"9e83409.d55cfc","nl":false,"rap":false,"x":2200,"y":1520,"wires":[["dd14cb9.4e59838"]]},{"id":"9e83409.d55cfc","type":"mqtt-broker","name":"Local Host","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

```

I see the messages clearly in a `debug` node (eg):

`13:20:14@6,1`

So in that spirit I add another line:

`client.publish("alarm_clock/next","OK")`

I then create another `MQTT IN` node and set it as so:

```auto
[{"id":"7af3c479.02f0ac","type":"mqtt in","z":"eff5d6e6.236338","d":true,"name":"","topic":"alarm_clock/next","qos":"2","datatype":"utf8","broker":"9e83409.d55cfc","nl":false,"rap":false,"x":960,"y":1310,"wires":[["931ebc46.313478","6e6d67af.fec578"]]},{"id":"9e83409.d55cfc","type":"mqtt-broker","name":"Local Host","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

```

**Excuse the fact it is disabled**

I stick a `debug` node onto it and wait.

```auto
{"topic":"ERROR_REPORT/Alarm_Clock/LCD message handling flow/alarm_clock/next","payload":"OK","qos":0,"retain":false,"_topic":"alarm_clock/next","_msgid":"b190ae41.af86f","error":{"message":"Unexpected token O in JSON at position 0","source":{"id":"6e6d67af.fec578","type":"json","count":1}}}

```

Where's the elephant?

I can't understand what is _wrong_ with this.

It happily accepts the stuff I am sending back with `text` - which isn't a JSON structure as far as I know.

Yet, when I want to send back a simple `OK`.... It spits the dummy.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [5 June 2021 06:41 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/2 "2021-06-05T06:41:12Z")

</div>

After my normal _Bashing head against wall_ it has started to behave itself.

Partly because I removed the JSON node. But I didn't put one there originally as the one which works doesn't have one.

I put one there in an attempt to _obey the rules of MQTT_.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 June 2021 08:22 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/3 "2021-06-05T08:22:38Z")

</div>

> [@Trying\_to\_learn](#):
>
> I put one there in an attempt to _obey the rules of MQTT_ .

What rule of MQTT were you trying to obey?

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [5 June 2021 08:24 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/4 "2021-06-05T08:24:07Z")

</div>

So rather than having to put everything into the `payload` part of the message.

At the sending end, it gets the entire `msg` structure and puts it into a new `msg.payload` structure.

I'm still not sure it does work.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 June 2021 08:38 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/5 "2021-06-05T08:38:40Z")

</div>

I still don't understand what rule of MQTT you were trying to obey.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [5 June 2021 12:11 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/6 "2021-06-05T12:11:09Z")

</div>

@Colin Andrew is refering to the fact the MQTT nodes only publish `msg.payload` and not the full `msg` object.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 June 2021 13:03 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/7 "2021-06-05T13:03:52Z")

</div>

Ah, some strange new use of the word 'rule' with which I am unfamiliar.

Thanks.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [6 June 2021 00:32 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/8 "2021-06-06T00:32:35Z")

</div>

It is my failure to understand English vocabulary.

I called it a 'rule' as it has to be obeyed if you want to send complicated (not the right word maybe) messages.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [20 June 2021 00:32 UTC](https://discourse.nodered.org/t/mqtt-problems-nodes-messages-and-python/46715/9 "2021-06-20T00:32:38Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
