# Dahua Palette Topic extraction

**URL:** <https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473>\
**Category:** General\
**Created:** [12 September 2019 16:52 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473 "2019-09-12T16:52:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike829](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mike829/32/11676_2.png) [@mike829](https://discourse.nodered.org/u/mike829)\
**Post date:** [12 September 2019 16:52 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473/1 "2019-09-12T16:52:09Z")

</div>

Hello Everybody,

I am testing the Dahua Palette for node-red.

I receive the following debug message:

12/9/2019, 18:46:42node: 27808558.5ae2ea  
VideoMotion/1/Stop : msg.payload : string[4]  
"Stop"  
12/9/2019, 18:46:51node: 27808558.5ae2ea  
VideoMotion/1/Start : msg.payload : string[5]  
"Start"

The data should be:  
TOPIC VideoMotion/1/Stop or VideoMotion/1/Start  
PAYLOAD STOP or START

If I have n.4 video channels I will have Videomotion/0...3

My question is: what is the right way to obtain n.8 outputs? I tried to edit function palette but I am not able to undertsand how to extract the topic and then the payload....

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 September 2019 17:10 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473/2 "2019-09-12T17:10:41Z")

</div>

Set the debug node to “complete msg object”

---

<div class="post-metadata">

**Author:** ![mike829](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mike829/32/11676_2.png) [@mike829](https://discourse.nodered.org/u/mike829)\
**Post date:** [12 September 2019 17:58 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473/3 "2019-09-12T17:58:44Z")

</div>

12/9/2019, 19:43:15[node: 27808558.5ae2ea](http://192.168.1.10:1880/#)VideoMotion/1/Stop : msg : Object

{ topic: "VideoMotion/1/Stop", payload: "Stop", index: "1", code: "VideoMotion", \_msgid: "2b871991.556fb6" }

---

<div class="post-metadata">

**Author:** ![mike829](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mike829/32/11676_2.png) [@mike829](https://discourse.nodered.org/u/mike829)\
**Post date:** [12 September 2019 18:44 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473/4 "2019-09-12T18:44:28Z")

</div>

I'd like to extract only the topic.

If topic is VideoMotion/1/Stop send msg.payload cam2 motion stop

If topic is VideoMotion/1/Start send msg.payload cam2 motion start

If topic is VideoMotion/0/Stop send msg.payload cam1 motion stop

If topic is VideoMotion/0/Stop send msg.payload cam1 motion stop

I don't know how to write the code to read the topic

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [12 September 2019 18:54 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473/5 "2019-09-12T18:54:19Z")

</div>

`msg.topic`

You cand do the initial `if` bit with a switch node (not the dashboard one)

Probably also reading the page in the docs about "working with messages"

---

<div class="post-metadata">

**Author:** ![mike829](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mike829/32/11676_2.png) [@mike829](https://discourse.nodered.org/u/mike829)\
**Post date:** [12 September 2019 21:10 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473/6 "2019-09-12T21:10:46Z")

</div>

Ok, I red the page "working with messages" and I compile the following code:

```auto

var newMsg = { topic: msg.topic, payload: msg.payload, index: msg.index, code: msg.code };
var topic=msg.topic;
var msg1 = {payload:"0"};
var msg2 = {payload:"1"};
if (msg.topic=="Videomotion/1/Stop"){
return msg1; 
}
if (msg.topic=="Videomotion/1/Start"){
    return msg2;
}

```

It seems works... What do you think?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 September 2019 21:42 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473/7 "2019-09-12T21:42:08Z")

</div>

What is the `var newMsg` for ?

Looks overcomplicated to me, why not using a switch node instead ?

```auto
[{"id":"a8102671.cb1ee","type":"inject","z":"7307521d.db778c","name":"Videomotion/1/Stop","topic":"Videomotion/1/Stop","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":314,"y":224,"wires":[["7ca00b6a.aa8754"]]},{"id":"7ca00b6a.aa8754","type":"switch","z":"7307521d.db778c","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Videomotion/1/Stop","vt":"str"},{"t":"eq","v":"Videomotion/1/Start","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":498,"y":252,"wires":[["39726e74.e0f3d2"],["b596218.1e882e"]]},{"id":"39726e74.e0f3d2","type":"change","z":"7307521d.db778c","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":638,"y":224,"wires":[["fa706fc.e7c379"]]},{"id":"a31cbdc6.a144","type":"inject","z":"7307521d.db778c","name":"Videomotion/1/Start","topic":"Videomotion/1/Start","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":314,"y":280,"wires":[["7ca00b6a.aa8754"]]},{"id":"b596218.1e882e","type":"change","z":"7307521d.db778c","name":"1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":638,"y":280,"wires":[["e28bd41d.ab15c"]]},{"id":"fa706fc.e7c379","type":"debug","z":"7307521d.db778c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":798,"y":224,"wires":[]},{"id":"e28bd41d.ab15c","type":"debug","z":"7307521d.db778c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":798,"y":280,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![mike829](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mike829/32/11676_2.png) [@mike829](https://discourse.nodered.org/u/mike829)\
**Post date:** [13 September 2019 08:59 UTC](https://discourse.nodered.org/t/dahua-palette-topic-extraction/15473/8 "2019-09-13T08:59:44Z")

</div>

> [@bakman2](#):
>
> What is the `var newMsg` for ?

It is a note, I evaluated to use payload, index and code to develop some function.

Thanks for the suggestion.
