@@ -0,0 +1,2920 @@
+#!/usr/bin/python%0A%0Aimport paho.mqtt.client as paho%0Aimport signal%0Aimport sys%0Aimport time%0A%0Afrom threading import Thread%0Afrom upm import pyupm_grove as grove%0Afrom upm import pyupm_biss0001 as grovemotion%0A%0Aluxes = grove.GroveLight(0)%0Amotion = grovemotion.BISS0001(6)%0Aopening = grove.GroveButton(4)%0Aswitch = grove.GroveRelay(2)%0A%0Amqttserver = %22iot.eclipse.org%22%0Amqttport = 1883%0A%0A# Sensor Luxes%0A%0Adef functionSensorLuxesData():%0A    value = luxes.value()%0A    print %22Publish Sensor Luxes Data: We got %25s!%22 %25 value%0A    return value%0A%0Adef functionSensorLuxes():%0A    mqttclient = paho.Client()%0A    mqttclient.connect(mqttserver, mqttport, 60)%0A    while True:%0A        data = functionSensorLuxesData()%0A        topic = %22cochinitapibil/vinagre/sensor/luxes%22%0A        mqttclient.publish(topic, data)%0A        time.sleep(1)%0A%0A# Binary Sensor Motion%0A        %0Adef functionBinarySensorMotionData():%0A    value = motion.value()%0A    if value:%0A        value = 1%0A    else:%0A        value = 0%0A    print %22Publish Binary Sensor Motion Data: We got %25s!%22 %25 value%0A    return value%0A%0Adef functionBinarySensorMotion():%0A    mqttclient = paho.Client()%0A    mqttclient.connect(mqttserver, mqttport, 60)%0A    while True:%0A        data = functionBinarySensorMotionData()%0A        topic = %22cochinitapibil/vinagre/binarysensor/motion%22%0A        mqttclient.publish(topic, data)%0A        time.sleep(1)%0A%0A# Binary Sensor Opening%0A%0Adef functionBinarySensorOpeningData():%0A    value = opening.value()%0A    print %22Publish Binary Sensor Opening Data: We got %25s!%22 %25 value%0A    return value%0A%0Adef functionBinarySensorOpening():%0A    mqttclient = paho.Client()%0A    mqttclient.connect(mqttserver, mqttport, 60)%0A    while True:%0A        data = functionBinarySensorOpeningData()%0A        topic = %22cochinitapibil/vinagre/binarysensor/opening%22%0A        mqttclient.publish(topic, data)%0A        time.sleep(1)%0A%0A# Switch%0A%0Adef functionSwitchData(mosq, obj, msg):%0A    print %22Subscribe Actuator Data: We received %25s!%22 %25 msg.payload%0A    if msg.payload == %221%22:%0A        switch.on()%0A    elif msg.payload == %220%22:%0A        switch.off()%0A%0Adef functionSwitch():%0A    mqttclient = paho.Client()%0A    mqttclient.on_message = functionSwitchData%0A    mqttclient.connect(mqttserver, mqttport, 60)%0A    mqttclient.subscribe(%22cochinitapibil/vinagre/switch%22, 0)%0A    while mqttclient.loop() == 0:%0A        pass%0A        %0Adef functionSignalHandler(signal, frame):%0A    sys.exit(0)%0A%0Aif __name__ == '__main__':%0A%0A    signal.signal(signal.SIGINT, functionSignalHandler)%0A%0A    sensorluxes = Thread(target=functionSensorLuxes)%0A    sensorluxes.start()%0A%0A    binarysensormotion = Thread(target=functionBinarySensorMotion)%0A    binarysensormotion.start()%0A%0A    binarysensoropening = Thread(target=functionBinarySensorOpening)%0A    binarysensoropening.start()%0A%0A    switch = Thread(target=functionSwitch)%0A    switch.start()%0A%0A    print %22IoT Solution Architect: From The Device To A Cloud Platform%22%0A%0A    while True:%0A        time.sleep(5)%0A%0A# End of File%0A

Create vinagre.py