# Using input MQTT node to execute command

**URL:** <https://discourse.nodered.org/t/using-input-mqtt-node-to-execute-command/10527>\
**Category:** General\
**Created:** [25 April 2019 07:46 UTC](https://discourse.nodered.org/t/using-input-mqtt-node-to-execute-command/10527 "2019-04-25T07:46:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SilverMecer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/silvermecer/32/7898_2.png) [@SilverMecer](https://discourse.nodered.org/u/SilverMecer)\
**Post date:** [25 April 2019 07:46 UTC](https://discourse.nodered.org/t/using-input-mqtt-node-to-execute-command/10527/1 "2019-04-25T07:46:04Z")

</div>

Hi

I have quick question not sure if this possible. I have a output MQTT node on my remote server that send messages per topic to my RPi's remotely. The RPi's do receive the messages. My question is when the RPi receive the message is it possible to execute a command from the received MQTT message?

Thank you

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 April 2019 07:51 UTC](https://discourse.nodered.org/t/using-input-mqtt-node-to-execute-command/10527/2 "2019-04-25T07:51:10Z")

</div>

yes - look at the exec node...

but be very careful here - you are now letting a remote device send potential random commands into your pi. so a) secure them, and the mqtt broker in the middle, b) don't just pass on the command - do verify it, sanitise it, restrict it to only setting parameters or something.

---

<div class="post-metadata">

**Author:** ![SilverMecer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/silvermecer/32/7898_2.png) [@SilverMecer](https://discourse.nodered.org/u/SilverMecer)\
**Post date:** [25 April 2019 08:05 UTC](https://discourse.nodered.org/t/using-input-mqtt-node-to-execute-command/10527/3 "2019-04-25T08:05:19Z")

</div>

Hi

Thank you for the response, yes what I want to do is that output mqtt will send a spesific command to the exec node. The node must only respond when that command is received.

I will take look and let you know.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cd6df3da1b33b7469007e634a1dd73bcbe47f4f8.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 April 2019 11:00 UTC](https://discourse.nodered.org/t/using-input-mqtt-node-to-execute-command/10527/4 "2019-04-25T11:00:33Z")

</div>

the way your flow looks in the image, nothing will happen when you get a `mqtt-in` msg. If the idea is that depending on the message/topic coming in, you want one of those `exex` nodes to run, you might try connecting the `mqtt-in` node to a switch node and based on the results, send it to one of the other nodes.

---

<div class="post-metadata">

**Author:** ![SilverMecer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/silvermecer/32/7898_2.png) [@SilverMecer](https://discourse.nodered.org/u/SilverMecer)\
**Post date:** [25 April 2019 11:24 UTC](https://discourse.nodered.org/t/using-input-mqtt-node-to-execute-command/10527/5 "2019-04-25T11:24:51Z")

</div>

Thank you very much will try it. Very new to Node Red. First project.

---

<div class="post-metadata">

**Author:** ![SilverMecer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/silvermecer/32/7898_2.png) [@SilverMecer](https://discourse.nodered.org/u/SilverMecer)\
**Post date:** [25 April 2019 14:02 UTC](https://discourse.nodered.org/t/using-input-mqtt-node-to-execute-command/10527/6 "2019-04-25T14:02:29Z")

</div>

Thank you it worked as expected 😄
