# I have a question. Sensor data classification

**URL:** <https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270>\
**Category:** General\
**Created:** [25 May 2020 15:52 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270 "2020-05-25T15:52:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)\
**Post date:** [25 May 2020 15:52 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/1 "2020-05-25T15:52:57Z")

</div>

![2020-05-26-004321_1824x984_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/dbdf1997f972f44984b70d57284998734ae932e0.png)

As shown in the photo above, i2c succeeded in fetching data values. The problem is that it is difficult to distinguish the payload values. For example, in the first case it is ph, in the second case it is temperature and in the third case it is a co2 sensor.

The problem is trying to load the data in the same way as the sensor hat. And I am planning to make it in dashboard form, but JavaScript is very difficult. Please ask for help.

[{"id":"6458ef98.82df1","type":"tab","label":"플로우 1","disabled":false,"info":""},{"id":"541e2113.16012","type":"inject","z":"6458ef98.82df1","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":330,"y":260,"wires":[["3b1a27be.913388"]]},{"id":"3b1a27be.913388","type":"exec","z":"6458ef98.82df1","command":"/usr/bin/python /home/pi/i2c.py","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"","x":630,"y":120,"wires":[["5d2f163e.903a68"],,]},{"id":"5d2f163e.903a68","type":"debug","z":"6458ef98.82df1","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":930,"y":60,"wires":}]

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 May 2020 16:19 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/2 "2020-05-25T16:19:56Z")

</div>

Use a function to split the string on `:`

Put part [0] into msg.topic and part [1] into msg.payload.

E.g.

```auto
var parts = msg.payload.split(":")
msg.topic = parts[0].trim();
msg.payload = parts[1].trim();
return msg;

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 May 2020 16:20 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/3 "2020-05-25T16:20:47Z")

</div>

Ps, in order to make code more readable and importable it is important to post it between two sets of three backticks - ``` - see this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

Please edit your first post.

---

<div class="post-metadata">

**Author:** ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)\
**Post date:** [25 May 2020 16:29 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/4 "2020-05-25T16:29:13Z")

</div>

thank you for the reply. I used the split function, but there was a problem that the problem was divided into 6 pieces of 3 data. As I said before: I split with a string, but it is divided into 6 instead of 3. Is it possible with 3 data? I will go home and test it tomorrow.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 May 2020 16:32 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/5 "2020-05-25T16:32:03Z")

</div>

Based on the screen shot of 3 messages, each containing 1 colon `:` that function will split the value and make 3 unique messages each with an identifiable topic and correct value.

You can then place a switch node after and direct the 3 messages down their own path/wire.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [25 May 2020 16:46 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/6 "2020-05-25T16:46:59Z")

</div>

Isn't that 3 string arrays of colon separated string values?

Edit: nevermind it's the string length. I'm tired. 😄

---

<div class="post-metadata">

**Author:** ![Athurian](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Athurian](https://discourse.nodered.org/u/Athurian)\
**Post date:** [25 May 2020 16:59 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/7 "2020-05-25T16:59:12Z")

</div>

Let's try it first. For reference, there is no topic. In other words, the payload itself comes out like this at pH 99: 0000. Actually, I modified it in the Python code to get the data value.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 May 2020 17:05 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/8 "2020-05-25T17:05:01Z")

</div>

> [@Athurian](#):
>
> For reference, there is no topic

There will be when you try the function i wrote

> [@Athurian](#):
>
> In other words, the payload itself comes out like this at pH 99: 0000

I can see that...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/e/9ede9a81b405561b85dbce5adc4ffb9a80757c35.png)

as I said 3 messages, each with a single colon...

> [@Steve-Mcl](#):
>
> Based on the screen shot of 3 messages, each containing 1 colon `:` that function will split the value and make 3 unique messages each with an identifiable topic and correct value.

there for...

`"pH 99: 0.000".split(":")` will return a 2 part array of `["pH 99", " 0.000"]`  
then

```auto
msg.topic = parts[0].trim(); 
msg.payload = parts[1].trim();
return msg;

```

will make a msg WITH a topic and the corresponding payload!

and this will happen for every subsequent message - making unique messages with thier own topic and own payload.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 May 2020 17:09 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/9 "2020-05-25T17:09:53Z")

</div>

I will finish with saying, if you sent (from your python output) standard JSON instead of this made up format, it would have been a simple case of sending the payload through a JSON node.

So while the function above will work - its not ideal (because of the data format)

I you want to do this better, then send JSON out from the python.

e.g. send `{ "topic" : "pH 99", "payload": 0 }` then send it through a `JSON` node - job done, no string splitting.

---

<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:** [25 May 2020 19:52 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/10 "2020-05-25T19:52:51Z")

</div>

Absolutely +lots on @Steve-Mcl's suggestion. If you have control of the python then change to code to pass a JSON string. Then you can feed that through a JSON node and you will immediately have it as a javascript object.

---

<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:** [8 June 2020 19:52 UTC](https://discourse.nodered.org/t/i-have-a-question-sensor-data-classification/27270/11 "2020-06-08T19:52:55Z")

</div>

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