Mqtt with adafruit io

#1

hi all,
i embed adafruit.io dashboard with mqtt node bu i don't know how to use payload data to switch led

0 Likes

#2

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.

0 Likes

#3

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

0 Likes

#4

i am passing these messages from adafruit.io a web server

0 Likes

#5

hi please help me i really need to do this

0 Likes

#6

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?

0 Likes

#7

YES this is the thing i want to do

0 Likes

#8

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

0 Likes

#9

oh sorry
1 and 0 in numbers

0 Likes

#10

@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.

0 Likes

#11

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

0 Likes

#12

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.

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;
0 Likes

#13

it worked thanks alot for help

0 Likes