Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
import paho.mqtt.client as mqtt
import RPi.GPIO as GPIO
def on_connect(client, userdata, rc):
#print ("Connected with rc: " + str(rc))
def on_message(client, userdata, msg):
#print ("Topic: "+ msg.topic+"\nMessage: "+str(msg.payload))
if "green" in msg.payload:
#print(" Green on!")
GPIO.output(11, True)
#print(" Green off!")
GPIO.output(11, False)
if "yellow" in msg.payload:
#print(" Yellow on!")
GPIO.output(12, True)
#print(" Yellow off!")
GPIO.output(12, False)
if "red" in msg.payload:
#print(" Red on!")
GPIO.output(13, True)
#print(" Red off!")
GPIO.output(13, False)
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("", 1883, 60)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)

This comment has been minimized.

Copy link

ishtiyaqhu commented Aug 7, 2017

There is a small change in your, This function requires 4 arguments.
Change this:
def on_connect(client, userdata, rc):

To this:
def on_connect(client, userdata, flag, rc):


This comment has been minimized.

Copy link

smalhao commented Jul 31, 2018

Hello, username and password in mqtt dashboard app what are they? Should the phone and raspberry pi be on the same network?
best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.