# BMP180 sensor to MQTT get multiple values

**URL:** <https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528>\
**Category:** General\
**Created:** [23 March 2020 18:43 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528 "2020-03-23T18:43:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 18:43 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/1 "2020-03-23T18:43:09Z")

</div>

As the topic states, I have a simple (to soon be more complex) need to consume MQTT data from sensors into node-red. I have successfully used mosquito and paho in a python script to create 2 separate MQTT messages from the sensor. I have successfully consumed these MQTT messages into node-red and built corresponding gauges/graphs. However my end goal is to write the data to a mysql DB, which I have also successfully set up getting insert to the DB for a single message. What I need is a single line insert into the table which will contain all the measurements/messages rather than just one measurement at a time.

Now for the ask...the BMP108 outputs temp and humidity, I have concatenated these two values into a string and can output that as a message containing both measurements. But when I get to node-red, I am unable to take the single topic with 2 messages and split out the data. I have tried the json convert and switch, but cannot seem to get the incoming two data point message to be split. I suspect it is in the structure of the data being sent via MQTT.

Info:  
From python MQTT publish of temperature (working):  
client = mqtt.Client()\*\*  
client.connect("localhost",1883,60)  
client.publish("bmp180\_temp", temperature);

Same for python MQTT publish of pressure (working):  
client.publish("bmp180\_temp", pressure);

However with the string created in python script to send both temperature and pressure by using in python:  
msgs = temperature, pressure and client.publish ("bmp180\_all", msgs), my raspberry pi terminal print(msgs) now shows (_the correct temp_, _the current pressure_) I cannot seem to parse this out via node red.

Any assistance would be greatly appreciated

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [23 March 2020 19:40 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/2 "2020-03-23T19:40:07Z")

</div>

What exactly does the msg.payload look like that carries your data? If it's in your description someplace I've missed it.

---

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 20:10 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/3 "2020-03-23T20:10:39Z")

</div>

The msg.payload that is generated from the working (single data point) MQTT is:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59848b8d77a7c31c8fcb84399ea1c2940f5da9b0.png)

For the payload that I am configuring for the multiple data point I have tried multiple different strings of which I cannot seem to parse any successfully.

---

<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:** [23 March 2020 20:24 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/4 "2020-03-23T20:24:31Z")

</div>

Don't join them as a string, join them as key/value pairs then you can use them in your query.

---

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 20:37 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/5 "2020-03-23T20:37:43Z")

</div>

OK...may I ask how to do so?

I have the temperature value and the pressure value, each currently published separately, which works. To simplify I have been experimenting with a simple mosquitto\_pub to try different outputs...for instance:

mosquitto\_pub -t "bmp180\_temp" -m 74.12,88.99

How would I make the key value pairs out of the 74.12 and 88.99?

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [23 March 2020 20:39 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/6 "2020-03-23T20:39:33Z")

</div>

Are you doing this in node red or mosquitto? If you are doing this in node red what does your flow look like so far?

---

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 20:49 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/7 "2020-03-23T20:49:46Z")

</div>

I am gathering the data on my pi and crafting the mosquito topic and data there using paho in a Python script to generate the MQTT message. I am using the python script to do calibrations and set the frequency of the sent data, node-red is subscribed to this topic.

I can craft the MQTT message in different means prior to node-red reception, so that is what I am trying to manipulate. My hope is that with a properly crafted MQTT message I can then use the split or other node to break the needed data out of the concatenated message which has two data points.  
The screen shot that I posted above is obviously the single data point received message

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [23 March 2020 21:15 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/8 "2020-03-23T21:15:44Z")

</div>

I would say when you establish what your MQTT data looks like maybe we can help. As it is we are chasing a moving target. You have a single data point and yet are trying to parse data. Nail down the data format for us and get a minimal flow together so we have something to work with.

---

<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:** [23 March 2020 21:18 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/9 "2020-03-23T21:18:57Z")

</div>

> [@Tomadoggy](#):
>
> mosquitto\_pub -t "bmp180\_temp" -m 74.12,88.99

`mosquitto_pub -t "bmp_temp" -m '{"temp": 74.12, "hum": 88.99}'`  
and in the MQTT In node in node red select the output as Parsed JSON which convert that JSON string into a javascript object

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [23 March 2020 21:22 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/10 "2020-03-23T21:22:44Z")

</div>

There ya go. Straight from the wizard's keyboard. Colin's about as good as they come.

---

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 21:32 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/11 "2020-03-23T21:32:11Z")

</div>

OK, simple flow created, Mosquitto\_pub as described above, here is the output  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cdd46ee7b9dc6ff06b65913af6368d8b2117ca29.png)

Now how can I take the two "objects" and direct the proper one to each dashboard gauge? Split?

Thanks to both of you so far, very grateful!

---

<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:** [23 March 2020 21:41 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/12 "2020-03-23T21:41:08Z")

</div>

No need to split, you can tell the dashboard node to pickup msg.payload.temp (or .hum) by putting in the `Value format` field  
`{{payload.temp}}`

---

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 22:00 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/13 "2020-03-23T22:00:03Z")

</div>

That worked wonderfully... as long as I am using the pi terminal to generate the message using mosquito:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b50606021cb7dd9d690804dd2e63ebefb2edafd0.png)

However I seem to be unable to translate that mosquitto message format into something that works via paho in my python script. Using paho: client.publish With "bmp\_temp" as the topic, how can I construct the message format so I get the 2 data points into node red as the objects generated? I have tried a number of different formats, none of which send out the same message as using the mosquitto\_pub command.

---

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 22:03 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/14 "2020-03-23T22:03:14Z")

</div>

Also, perhaps just as a curiosity but may be related...when using the node-red mqtt in, what effect does adding " /# " to the topic name result in?

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [23 March 2020 22:08 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/15 "2020-03-23T22:08:02Z")

</div>

the pound symbol # means subscribe to all topics., so if it's behind a name it would subscribe to all topics below that name, such as testing/# would subscribe to testing/one testing/maybe testing/hello and so on.

---

<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:** [23 March 2020 22:09 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/16 "2020-03-23T22:09:22Z")

</div>

How are you publishing it at the moment. It is only a string with the values embedded.

If you use some/topic/# then that will give you all topics starting with some/topic/, such as some/topic/x/q. Have a good read through this series for the lowdown on MQTT. It starts with the basic concepts and goes on the more meaty stuff.  
[https://www.hivemq.com/blog/mqtt-essentials-part-1-introducing-mqtt/](https://www.hivemq.com/blog/mqtt-essentials-part-1-introducing-mqtt/)

---

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 22:10 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/17 "2020-03-23T22:10:43Z")

</div>

Thank you, I will do the reading...hopefully can find the proper paho formatting to get the desired result.  
Cheers!

---

<div class="post-metadata">

**Author:** ![Tomadoggy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomadoggy/32/34065_2.png) [@Tomadoggy](https://discourse.nodered.org/u/Tomadoggy)\
**Post date:** [23 March 2020 22:13 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/18 "2020-03-23T22:13:21Z")

</div>

Currently in the script as:

msgs = {"temp: temperature, "hum": humidity} Where temperature is the value from the sensor previously defined and working, and humidity is the value from the sensor

Then:  
client.publish("bmp.temp", msgs)

But this is not working

---

<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:** [23 March 2020 22:14 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/19 "2020-03-23T22:14:05Z")

</div>

Your last problem is nothing to do with mqtt it is a python question on how to buld a string containing `{"temp": temperature, "hum": humidity}`. I don't know much python so don't know the answer to that, but I am sure it is a trivial problem.

---

<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:** [23 March 2020 22:18 UTC](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528/20 "2020-03-23T22:18:07Z")

</div>

> [@Tomadoggy](#):
>
> msgs = {"temp: temperature, "hum": humidity}

You have a missing ", but I doubt if that is valid python even so, but you need a python user to tell you how to do it (or google).

[Next page](https://discourse.nodered.org/t/bmp180-sensor-to-mqtt-get-multiple-values/23528.md?page=2)
