# Mqtt with adafruit io

**URL:** <https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599>\
**Category:** General\
**Created:** [4 March 2019 15:34 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599 "2019-03-04T15:34:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mani2411](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mani2411](https://discourse.nodered.org/u/mani2411)\
**Post date:** [4 March 2019 15:34 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/1 "2019-03-04T15:34:37Z")

</div>

hi all,  
i embed [adafruit.io](http://adafruit.io) dashboard with mqtt node bu i don't know how to use payload data to switch led

---

<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:** [4 March 2019 15:40 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/2 "2019-03-04T15:40:16Z")

</div>

Hi @mani2411

you'll need to describe lots more about what you have working and what you have tried. You are leaving us to guess a lot about what you are doing. Are you running this on a Raspberry Pi or similar device? How have you got the LED connected?

Do you know how to control the LED at all? Once you know that, it will be a question of passing a message in the right format to the right node.

You can use the Debug node to see what messages you are getting from the MQTT node.

---

<div class="post-metadata">

**Author:** ![mani2411](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mani2411](https://discourse.nodered.org/u/mani2411)\
**Post date:** [4 March 2019 15:44 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/3 "2019-03-04T15:44:35Z")

</div>

yes i am using raspberry pi and blinked a led with inject node here is the image of configuration and debug node

 ![Screenshot%20(253)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/72570cdbac456dc51ec2487c86bf0d35eea5b1cf.png)

---

<div class="post-metadata">

**Author:** ![mani2411](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mani2411](https://discourse.nodered.org/u/mani2411)\
**Post date:** [4 March 2019 15:45 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/4 "2019-03-04T15:45:21Z")

</div>

i am passing these messages from [adafruit.io](http://adafruit.io) a web server

---

<div class="post-metadata">

**Author:** ![mani2411](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mani2411](https://discourse.nodered.org/u/mani2411)\
**Post date:** [4 March 2019 16:10 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/5 "2019-03-04T16:10:18Z")

</div>

hi please help me i really need to do this

---

<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:** [4 March 2019 16:13 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/6 "2019-03-04T16:13:45Z")

</div>

Am I understanding correctly, you have a message with payload "ON" or "OFF" and you want to use that to turn an LED on/off? Also you are able to drive the led with an inject node successfully?  
If so then the question you are asking is 'how do I convert a payload containing ON or OFF to one containing the inject values?'.  
So the first question is what values are you injecting to turn the LED on/off?

---

<div class="post-metadata">

**Author:** ![mani2411](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mani2411](https://discourse.nodered.org/u/mani2411)\
**Post date:** [4 March 2019 16:17 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/7 "2019-03-04T16:17:33Z")

</div>

YES this is the thing i want to do

---

<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:** [4 March 2019 16:19 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/8 "2019-03-04T16:19:41Z")

</div>

You didn't answer the question, what values do you need to turn the led on/off?

---

<div class="post-metadata">

**Author:** ![mani2411](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mani2411](https://discourse.nodered.org/u/mani2411)\
**Post date:** [4 March 2019 16:21 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/9 "2019-03-04T16:21:32Z")

</div>

oh sorry  
1 and 0 in numbers

---

<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:** [4 March 2019 16:23 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/10 "2019-03-04T16:23:25Z")

</div>

@mani2411

so when you get an 'OFF' payload from the MQTT node, you need to send a `0` to the GPIO node. And when you get an 'ON' payload from the MQTT node, you need to a `1` to the GPIO node.

You could use a Function node with a little bit of JavaScript to check the value of the payload and set it to the required value before passing it on.

---

<div class="post-metadata">

**Author:** ![mani2411](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mani2411](https://discourse.nodered.org/u/mani2411)\
**Post date:** [4 March 2019 16:26 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/11 "2019-03-04T16:26:56Z")

</div>

i am a newbee to this and don't know about js so i tried if loop to do so but not working but its giving error kindly assist me with function node code

---

<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:** [4 March 2019 16:29 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/12 "2019-03-04T16:29:25Z")

</div>

Again, if you shared more details on what you have tried, we can help you better.

A Function node along the lines of the following would do it.

```auto
if (msg.payload === "ON") {
   msg.payload = 1;
} else if (msg.payload === "OFF") {
   msg.payload = 0;
} else {
   // Don't recognise ON or OFF, so return nothing
   return
}
// Return the updated message
return msg;

```

---

<div class="post-metadata">

**Author:** ![mani2411](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mani2411](https://discourse.nodered.org/u/mani2411)\
**Post date:** [4 March 2019 16:32 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/13 "2019-03-04T16:32:59Z")

</div>

it worked thanks alot for help

---

<div class="post-metadata">

**Author:** ![Busganda](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@Busganda](https://discourse.nodered.org/u/Busganda)\
**Post date:** [10 June 2019 16:08 UTC](https://discourse.nodered.org/t/mqtt-with-adafruit-io/8599/14 "2019-06-10T16:08:21Z")

</div>

Hello, I'm really interested in your project. I would like to get your configuration node, so I can import it into mine...
