Created
February 13, 2017 05:29
-
-
Save yeffrimic/2ddcca058d24214427f616856de04ff3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paho.mqtt.client as mqtt | |
# El callback para cuando el cliente reciva un Connack de respuesta del servidor. | |
def on_connect(client, userdata, flags, rc): | |
print("Conectado con el siguiente codigo "+str(rc)) | |
#Suscribirse dentro de On_connect signidica que si perdemos la conexion | |
#y nos reconectamos la suscripcion se renovara. | |
client.subscribe(MQTT_topicSub) | |
# The callback for when a PUBLISH message is received from the server. | |
def on_message(client, userdata, msg): | |
print(msg.topic+" "+str(msg.payload)) | |
MQTT_broker = "127.0.0.1" | |
MQTT_username = "" | |
MQTT_password = "" | |
MQTT_topicSub = "/a" #<---topico al que te vas a suscribir | |
MQTT_topicAlive = "/a"#topico al que le vas a decir que ya estas conectad | |
MQTT_port = 1883 | |
MQTT_clientID = "conectado "# | |
client = mqtt.Client(MQTT_clientID, clean_session=True, userdata=None, protocol="MQTTv311", transport="tcp") | |
client.on_connect = on_connect | |
client.on_message = on_message | |
client.username_pw_set(MQTT_username,MQTT_password ) | |
client.connect(MQTT_broker, MQTT_port, 60) | |
client.publish(MQTT_topicAlive,MQTT_clientID, qos=0, retain=False) | |
# | |
while 1: | |
mensaje= raw_input('mensaje: ') | |
client.publish("candidatas", mensaje, qos=0, retain=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment