Exemple #1
0
    def __init__(self, clockPin, dataPin, strobePin, activateDisplay,
                 intensity):
        self.clockPin = clockPin
        self.dataPin = dataPin
        self.strobePin = strobePin

        #  all the pins are outputs
        self.gpioDataPin = onionGpio.OnionGpio(self.dataPin)
        status = self.gpioDataPin.setOutputDirection(0)

        self.gpioClockPin = onionGpio.OnionGpio(self.clockPin)
        status = self.gpioClockPin.setOutputDirection(0)

        self.gpioStrobePin = onionGpio.OnionGpio(self.strobePin)
        status = self.gpioStrobePin.setOutputDirection(0)

        #  init them all in a known state
        status = self.gpioClockPin.setValue(offVal)
        status = self.gpioDataPin.setValue(offVal)
        status = self.gpioStrobePin.setValue(offVal)

        #  send the init commands
        #print("send init")
        self.sendCommand(DATA_WRITE_INCR_ADDR)
        self.setupDisplay(activateDisplay, intensity)

        self.strobeSelect()
        self.send(ADDRSET)
        for i in range(0, 16):
            self.send(0x00)

        self.strobeDeselect()
Exemple #2
0
def setUpGPIOSubsystem():
    global sensorLeftDoor
    global sensorRightDoor
    # ensure our i2c pins are set for gpio
    needConfigUse = modeI2C()
    if needConfigUse == True:
        setPinsModeGPIO()
    # now set pin directions
    sensorLeftDoor = onionGpio.OnionGpio(doorPin(door_name_left))
    sensorLeftDoor.setInputDirection()
    sensorRightDoor = onionGpio.OnionGpio(doorPin(door_name_right))
    sensorRightDoor.setInputDirection()
Exemple #3
0
def main():

    # Blue
    gpioObjBlue = onionGpio.OnionGpio(BLUE_LED)
    status = gpioObjBlue.setOutputDirection(0)
    status = gpioObjBlue.setValue(offVal)

    # Green
    gpioObjGreen = onionGpio.OnionGpio(GREEN_LED)
    status = gpioObjGreen.setOutputDirection(0)
    status = gpioObjGreen.setValue(offVal)

    # Red
    gpioObjRed = onionGpio.OnionGpio(RED_LED)
    status = gpioObjRed.setOutputDirection(0)
    status = gpioObjRed.setValue(offVal)

    #print("Call segmentDisplay")
    segmentDisplay = TM1638(CLK, DIO, STROBE_0, True, 7)
    segmentDisplay.clearDisplay()
    for i in range(0, 8):
        segmentDisplay.setLED(i, LED_COLOR_NONE)

    buttons = 0
    while (True):
        try:
            buttons = segmentDisplay.getButtons()
            if buttons != 0:
                print("buttons = {0:2x}".format(buttons))

                status = gpioObjGreen.setValue(onVal)
                status = gpioObjRed.setValue(offVal)
                status = gpioObjBlue.setValue(offVal)

                segmentDisplay.clearDisplay()

                for i in range(0, 8):
                    if (buttons & 1):
                        segmentDisplay.setLED(i, LED_COLOR_RED)
                        segmentDisplay.setDisplayDigit(i, i, 1)
                    else:
                        segmentDisplay.setLED(i, LED_COLOR_GREEN)

                    #  go the the bit for the next button
                    buttons >>= 1
            else:
                buttons = 0

        except KeyboardInterrupt:
            print("Keyboard interrupt, exiting")
            status = gpioObjGreen.setValue(offVal)
            quit()
Exemple #4
0
def init_gpio_output(element, pin):
    """Initialize the gpio."""
    if element == "led":
        global gpio_led
        gpio_led = onionGpio.OnionGpio(pin)
        # set to output direction with zero (LOW) being the default value
        gpio_led.setOutputDirection(0)
    else:
        global gpio_buzzer
        gpio_buzzer = onionGpio.OnionGpio(pin)
        # set to output direction with zero (LOW) being the default value
        gpio_buzzer.setOutputDirection(0)

    return True
Exemple #5
0
    def __init__(self, loadPin, clockEnablePin, clockPin, dataPin, numberPISO = 1):
        self._loadPin = onionGpio.OnionGpio(loadPin)
        self._clockEnablePin = onionGpio.OnionGpio(clockEnablePin)
        self._clockPin = onionGpio.OnionGpio(clockPin)
        self._dataPin = onionGpio.OnionGpio(dataPin)
        self._dataWidth = numberPISO * 8
        
        self._loadPin.setOutputDirection(0)
        self._clockEnablePin.setOutputDirection(0)
        self._clockPin.setOutputDirection(0)
        self._dataPin.setInputDirection()

        self._clockPin.setValue(0)
        self._loadPin.setValue(1)
Exemple #6
0
def loop():
    """ Main loop running the bot """
    # Initialize the light sensor. Note that the Gpio library
    # returns strings...
    sensorpin = CFG.get("cfg", "light_sensor_pin")
    sensor = onionGpio.OnionGpio(int(sensorpin))
    status = int(sensor.setInputDirection())
    # Check sensor status
    if status == 0:
        print "Sensor ok"
    if status == -1:
        print "Error"
        return 1

    # Get the refresh interval from Config
    refresh_interval = float(CFG.get("cfg", "refresh_interval"))

    while status == 0:
        lights = int(sensor.getValue())
        # TODO: Implement projector current sensing
        projector = 0
        timestamp = time.time()
        data = json.dumps({'device':DEVICE_NAME, "lights":lights, 'timestamp':timestamp})
        senddata("Something", data)
        time.sleep(refresh_interval)
def _configure_output(pin: int, device: str, bus):
    """
    Configure the node as an output. Takes in a pin to access, and a string which is what was
    passed in at the command line.
    """
    if device in ('pi', 'jetson'):
        # as with configure_input, we can use pigpio for both
        return_output = _GenericOutputPin(bus, pin)
        return_output.set_low_func = (
            lambda: return_output.configured_pinbus_object.write(
                int(pin), pigpio.LOW))
        return_output.set_high_func = (
            lambda: return_output.configured_pinbus_object.write(
                int(pin), pigpio.HIGH))
        return return_output

    if device == 'beaglebone':
        return _GenericOutputPin(
            lambda: BBGPIO.setup(pin, BBGPIO.OUT),
            lambda: BBGPIO.output(pin, BBGPIO.LOW),
            lambda: BBGPIO.output(pin, BBGPIO.HIGH),
        )

    if device == 'onion':
        return_output = _GenericOutputPin(onionGpio.OnionGpio(pin), pin)
        return_output.configured_pinbus_object.setOutputDirection()
        return_output.set_low_func = lambda: return_output.configured_pinbus_object.setValue(
            0)
        return_output.set_high_func = lambda: return_output.configured_pinbus_object.setValue(
            1)
        return return_output

    if device == 'generic':
        # todo: as above
        os.system('echo ' + str(pin) + ' > /sys/class/gpio/export')
        os.system('echo out > /sys/class/gpio/gpio' + str(pin) + '/direction')

        return _GenericOutputPin(
            None,
            pin,
            set_low_=lambda: os.system('echo 0 > /sys/class/gpio/gpio' + str(
                pin) + '/value'),
            set_high_=lambda: os.system('echo 1 > /sys/class/gpio/gpio' + str(
                pin) + '/value'))

    if device == 'simulated':
        return _GenericOutputPin(
            None,
            pin,
            set_high_=(lambda: print("[simulated] high!")),
            set_low_=(lambda: print("[simulated] low!")))

    raise RuntimeError('Device was invalid: ' + device)
class sevenSegment:
    digitMap = {
    "0": "00111111",
    "1": "00000110",
    "2": "01011011",
    "3": "01001111",
    "4": "01100110",
    "5": "01101101",
    "6": "01111101",
    "7": "00000111",
    "8": "01111111",
    "9": "01101111",
    "a": "01110111",
    "b": "01111100",
    "c": "10011100",
    "d": "01111010",
    "e": "10011110",
    "f": "10001110",
    "off": "00000000",
    "-": "01000000"
    }

	#Initializes the GPIO objects based on the pin numbers
	def __init__(self, dPin):
		self.shiftReg = registerClass.shiftRegister(1,2,3)
        for i in range (0,4):
    		self.digitPin[i] = onionGpio.OnionGpio(dPin[i])
    		self.digitPin[i].setOutputDirection(1)


	def showDigit(self, d, character):
		self.digitPin[d].setValue(0)
		self.shiftReg.outputBits(self.digitMap[character])
		self.digit[d].setValue(1)


	def clear(self):
		self.shiftReg.clear();
        for i in range (0,4):
    		self.digitPin[i] = onionGpio.OnionGpio(dPin[i])
Exemple #9
0
    def MFRC522_Init(self):
        # GPIO.output(self.NRSTPD, 1)
        gpioRst = onionGpio.OnionGpio(self.NRSTPD)
        gpioRst.setOutputDirection(1)

        self.MFRC522_Reset()

        self.Write_MFRC522(self.TModeReg, 0x8D)
        self.Write_MFRC522(self.TPrescalerReg, 0x3E)
        self.Write_MFRC522(self.TReloadRegL, 30)
        self.Write_MFRC522(self.TReloadRegH, 0)

        self.Write_MFRC522(self.TxAutoReg, 0x40)
        self.Write_MFRC522(self.ModeReg, 0x3D)
        self.AntennaOn()
		def __init__(self, digitOne, digitTwo, digitThree, digitFour):
			self.shiftReg = registerClass.shiftRegister(1,2,3)
			self.digitOne = onionGpio.OnionGpio(digitOne)
			self.digitTwo = onionGpio.OnionGpio(digitTwo)
			self.digitThree = onionGpio.OnionGpio(digitThree)
			self.digitFour = onionGpio.OnionGpio(digitFour)


			self.a = "01110111"
			self.b = "00111110"
			self.c = "10011100"
			self.d = "01111010"
			self.e = "10011110"
			self.f = "10001110"
			self.zero = "00111111"
			self.one = "00000110"
			self.two = "01011011"
			self.three = "01001111"
			self.four = "01100110"
			self.five = "01101101"
			self.six = "01111101"
			self.seven = "00000111"
			self.eight = "01111111"
			self.nine = "01101111"
def dht_read(type, pin, humidity, temperature):
	#validate imputs for temp and humid and then set to 0
	if humidity is None || temperature is None:
		print("DHT Arguement Error")
		return DHT_ERROR_ARGUEMENT
	temperature = -255.0
	humidity = -255.0

	#initialize GPIO pin
	dhtGpio = onionGpio.OnionGpio(pin)
	status = dhtGpio.setOutputDirection(0)
	
	#Store the count that each DHT bit pulse is low and high.
	#Make sure array is initialized to start at zero.
	pulseCounts[DHT_PULSES*2] = {0}
Exemple #12
0
class ST7735(object):
    """Representation of an ST7735 TFT LCD."""

    def __init__(self, dc, spi, rst=None, gpio=None, width=ST7735_TFTWIDTH,
        height=ST7735_TFTHEIGHT):
        """Create an instance of the display using SPI communication.  Must
        provide the GPIO pin number for the D/C pin and the SPI driver.  Can
        optionally provide the GPIO pin number for the reset pin as the rst
        parameter.
        """
        self._dc = dc
        self._rst = rst
        self._spi = spi
        self._gpio = gpio
        self.width = width
        self.height = height
        #In onion the gpio is controlled using
        #different object for each pin, we define
        #_gpiodc and _gpiorst for that
        self._gpiodc = GPIO.OnionGpio(dc)
	    try:
            self._gpiodc._freeGpio()
	    except IOError:
	        print "Already freed dc"
        if rst is not None:
            self._gpiorst = GPIO.OnionGpio(rst)
	    #try:
            #    self._gpiorst._freeGpio()
	    #except IOError:
	    #    print "Already freed rst"
        # Set DC as output.
        self._gpiodc.setOutputDirection(0)
        # Setup reset as output (if provided).
        if rst is not None:
            self._gpiorst.setOutputDirection(0)
        # Set SPI to mode 0, MSB first.
        spi.mode = 0
        spi.speed = SPI_CLOCK_HZ
        spi.lsbfirst = False
        #spi.set_bit_order(SPI.MSBFIRST)
        #spi.set_clock_hz(SPI_CLOCK_HZ)
        # Create an image buffer.
        self.buffer = Image.new('RGB', (width, height))
Exemple #13
0
def main():
    HOST_MAC_ADDRESS = wf.getMACString()
    print("Device MAC address: " + HOST_MAC_ADDRESS)

    # Connect for sending:

    AMQPPubTopic = AMQPClient.topicGenerator(HOST_MAC_ADDRESS, "0001",
                                             "lightManager", "pub")
    print("Pub topic", AMQPSendTopic_lightManager)
    AMQPClient.declareTopic(AMQPSendTopic_lightManager)

    # For receiving:
    AMQPRcvTopic_lightManager = AMQPClient.topicGenerator(
        HOST_MAC_ADDRESS, "0001", "lightManager", "sub")
    AMQPClient.declareTopic(AMQPRcvTopic_lightManager)
    AMQPClient.startSubcribe(AMQPReceiveMessageCallback,
                             AMQPRcvTopic_lightManager)

    gpioNum = 16
    gpioObj = onionGpio.OnionGpio(gpioNum)

    status = gpioObj.setOutputDirection(0)
    if status == 0:
        print('GPIO%d set to output,' % (gpioNum))
    else:
        print('FAILED: GPIO%d set to output ,' % (gpioNum))

    value = gpioObj.getValue()
    print('Initial value: %d' % (int(value)))

    while True:
        try:
            if (int(value) != int(gpioObj.getValue())):
                value = gpioObj.getValue()
                print('Value is changed: %d' % (int(value)))
                if int(value) == 0:
                    message = js.jsonSimpleGenerate("state", "0")
                else:
                    message = js.jsonSimpleGenerate("state", "1")
                AMQPClient.publishMessage(AMQPPubTopic, message)
            time.sleep(1)
        except Exception as e:
            print("Failed to run Humidifier Process: exception={})".format(e))
Exemple #14
0
    def __init__(self, dc, spi, rst=None, gpio=None, width=ST7735_TFTWIDTH,
        height=ST7735_TFTHEIGHT):
        """Create an instance of the display using SPI communication.  Must
        provide the GPIO pin number for the D/C pin and the SPI driver.  Can
        optionally provide the GPIO pin number for the reset pin as the rst
        parameter.
        """
        self._dc = dc
        self._rst = rst
        self._spi = spi
        self._gpio = gpio
        self.width = width
        self.height = height
        #In onion the gpio is controlled using
        #different object for each pin, we define
        #_gpiodc and _gpiorst for that
        self._gpiodc = GPIO.OnionGpio(dc)
	    try:
            self._gpiodc._freeGpio()
	    except IOError:
	        print "Already freed dc"
Exemple #15
0
    def __init__(self, dev='/dev/spidev0.0', spd=1000000):

        self.val = 0

        # spi.openSPI(device=dev,speed=spd)

        ### modify any SPI settings as required
        self.spi = onionSpi.OnionSpi(1, 32766)
        self.spi.sck = 7
        self.spi.mosi = 8
        self.spi.miso = 9
        self.spi.cs = 6
        # self.spi.csHigh  = 1

        ### register the device
        self.spi.registerDevice()
        self.spi.setupDevice()

        print 'SPI CS GPIO:   %d' % (self.spi.cs)
        print 'SPI SCK GPIO:  %d' % (self.spi.sck)
        print 'SPI MISO GPIO: %d' % (self.spi.miso)
        print 'SPI MOSI GPIO: %d' % (self.spi.mosi)

        print 'SPI Speed: %d Hz (%d kHz)' % (self.spi.speed,
                                             self.spi.speed / 1000)
        print 'Mode: %d, Mode Bits: 0x%x, CS-High: %d' % (
            self.spi.mode, self.spi.modeBits, self.spi.csHigh)

        print 'Check success %d' % (self.spi.checkDevice())

        # GPIO.setmode(GPIO.BOARD)

        # GPIO.setup(22, GPIO.OUT)
        # GPIO.output(self.NRSTPD, 1)
        gpioRst = onionGpio.OnionGpio(self.NRSTPD)
        gpioRst.setOutputDirection(1)

        self.MFRC522_Init()
Exemple #16
0
def main():

    onVal = 0
    offVal = 1

    # The omega2 expansion board rgb leds

    # Blue
    gpioObjBlue = onionGpio.OnionGpio(BLUE_LED)
    status = gpioObjBlue.setOutputDirection(0)
    status = gpioObjBlue.setValue(offVal)

    # Green
    gpioObjGreen = onionGpio.OnionGpio(GREEN_LED)
    status = gpioObjGreen.setOutputDirection(0)
    status = gpioObjGreen.setValue(offVal)

    # Red
    gpioObjRed = onionGpio.OnionGpio(RED_LED)
    status = gpioObjRed.setOutputDirection(0)
    status = gpioObjRed.setValue(offVal)

    segmentDisplay = TM1638(CLK, DIO, STROBE_0, True, 7)
    segmentDisplay.clearDisplay()
    for i in range(0, 8):
        segmentDisplay.setLED(i, LED_COLOR_NONE)

    led = 0
    while (True):
        if led > 255:
            led = 0
        try:
            """ onionGpio.setValue is kind of slow so I commented these out
            status = gpioObjRed.setValue(offVal)
            status = gpioObjGreen.setValue(offVal)
            status = gpioObjBlue.setValue(offVal)
	    if led & 1:
                status = gpioObjRed.setValue(onVal)
	    if led&2:
                status = gpioObjGreen.setValue(onVal)
	    if led&4:
                status = gpioObjBlue.setValue(onVal)
            """

            j = led & 7
            for i in range(7, -1, -1):
                k = 7 - i
                if led & (1 << i):
                    #print(i," goes red")
                    segmentDisplay.setLED(k, LED_COLOR_RED)
                    segmentDisplay.setDisplayDigit(k, k, 0)
                else:
                    #print(i," goes green")
                    segmentDisplay.setLED(k, LED_COLOR_GREEN)
                    segmentDisplay.clearDisplayDigit(k, 0)

        except KeyboardInterrupt:
            # I have a script to clear up any Resource Busy problems.
            # It outputs error messages but appears to work
            """
	    echo 18 > /sys/class/gpio/unexport
	    echo 0 > /sys/class/gpio/unexport
	    echo 1 > /sys/class/gpio/unexport
	    """

            print("Keyboard interrupt, exiting")
            status = gpioObjBlue.setValue(offVal)
            quit()
        led += 1
oneWireGpio = 11


def strTemp(sensor):
    value = sensor.readValue()
    print("T= " + str(value) + " C")


#I/O and PWM set up
os.system('omega2-ctrl gpiomux set uart1 gpio')
os.system('omega2-ctrl gpiomux set pwm0 pwm')
LampPin = 1
FoggerPin = 45
StirPin = 15
LampObj = onionGpio.OnionGpio(LampPin)
StirObj = onionGpio.OnionGpio(StirPin)
FoggerObj = onionGpio.OnionGpio(FoggerPin)

#1-Wire Init
if not oneWire.setupOneWire(str(oneWireGpio)):
    print("Kernel mdule could not be inserted. Try again!")
sensorAddress = oneWire.scanOneAddress()
sensor = TemperatureSensor("oneWire", {
    "address": sensorAddress,
    "gpio": oneWireGpio
})
if not sensor.ready:
    print("Sensore was not set up correctly.")

os.system('onion pwm 0 0 1000')
Exemple #18
0
import onionGpio

gpio0 = onionGpio.OnionGpio(18)
val = int(gpio0.getValue())
print(val)
Exemple #19
0
#!/usr/bin/python
import onionGpio
import time

print "STK01-blink.py started"

sleepTime = 0.5
# create a GPIO object
gpio0 = onionGpio.OnionGpio(0)
# set the output direction with zero(LOW) being the default value
gpio0.setOutputDirection(0)
ledValue = 1
while 1:
    gpio0.setValue(ledValue)
    if ledValue == 1:
        ledValue = 0
    else:
        ledValue = 1
    time.sleep(sleepTime)

print "STK01-blink.py ended"
Exemple #20
0
#!/usr/bin/python
#autor: Lidia
import sys
import signal
import onionGpio

# importamos archivo phython en donde realizamos la consulta del estado de la variable de estado del switch en la DB
from Conexion import*
from Conexion1 import*

#Creamos objetos tipo GPIOS en este caso usaremos los pines 1 y 2.
#
gpioObj = onionGpio.OnionGpio(1)
gpioObj1 = onionGpio.OnionGpio(2)


#Se inicializan los GPIO como salidas  en estado bajo
#
status  = gpioObj.setOutputDirection(0)
status1 = gpioObj1.setOutputDirection(0)


# Definimos la funcion procesa en donde recibe como parametro el estado del switch
def procesa(respuesta):
    print respuesta

    if respuesta:
        # si el swith esta encendido seteamos el gpio en estado alto
        status  = gpioObj.setValue(1)

    else:
Exemple #21
0
 def __init__(self, dataPin, serialClock, registerClock):
     self.ser = onionGpio.OnionGpio(dataPin)
     self.srclk = onionGpio.OnionGpio(serialClock)
     self.rclk = onionGpio.OnionGpio(registerClock)
     self.setup()
Exemple #22
0
import json
import time
import urllib3
import onionGpio

gpio0 = onionGpio.OnionGpio(0)
gpio1 = onionGpio.OnionGpio(1)

gpio0.setOutputDirection(0)
gpio1.setOutputDirection(0)


def check_weather(city='berlin'):
    http = urllib3.PoolManager()
    r = http.request(
        'GET', 'https://forecast-weather-us.herokuapp.com/api/weather/' + city)
    json_data = json.loads(r.data)
    print json_data['temperature']
    return json_data['temperature']


temperature = check_weather()

while 1:
    current = check_weather()

    if current <= temperature:
        gpio0.setValue(1)
        gpio1.setValue(0)
        temperature = current
    else:
# define pins
GREEN_PIN = 0
AMBER_PIN = 1
RED_PIN = 2

# define states
ON = 1
OFF = 0

# durations for each light
redTime = 5
amberTime = 3
greenTime = 5

# instantiate gpio objects
red = onionGpio.OnionGpio(RED_PIN)
amber = onionGpio.OnionGpio(AMBER_PIN)
green = onionGpio.OnionGpio(GREEN_PIN)

# initialize to output
red.setOutputDirection(OFF)
amber.setOutputDirection(OFF)
green.setOutputDirection(OFF)


# functions for switching lights
def setSignal(color):
    if color == "red":
        red.setValue(ON)
        amber.setValue(OFF)
        green.setValue(OFF)
from flask import Flask
import time
import onionGpio

rfid = onionGpio.OnionGpio(0)
qr = onionGpio.OnionGpio(1)

print("QR gpio mode :: " + qr.getDirection())
print("RFID gpio mode :: " + rfid.getDirection())

app = Flask(__name__)


@app.route("/rfidDoorOpen")
def openRFIDDoor():
    rfid.setValue(1)
    time.sleep(1)
    rfid.setValue(0)
    return "200"


@app.route("/qrDoorOpen")
def openQRDoor():
    qr.setValue(1)
    time.sleep(1)
    qr.setValue(0)
    return "200"


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=9999)
#!/usr/bin/env python

import time
import onionGpio
import paho.mqtt.publish as publish

#initializing gpio and setting direction
gpio1 = onionGpio.OnionGpio(1)
gpio1.setInputDirection()

#start of loop to detect motion
while True:

    #conerting to string for boolean comparison
    value = str(gpio1.getValue())

    if (value == "1"):
        print "Motion Detected"
        publish.single("enter_topic_here",
                       "ON",
                       hostname="enter_ip",
                       port=1883)
        time.sleep(5)
        publish.single("enter_topic_here",
                       "OFF",
                       hostname="enter_ip",
                       port=1883)

    time.sleep(0.1)
Exemple #26
0
import time
import onionGpio

gpio19 = onionGpio.OnionGpio(19)

status = gpio19.setInputDirection()

count = 0

while True:
    value = gpio19.getValue()

    print(value)

    time.sleep(0.5)
    #
    #if(value == '1\n'):
    #	count += 1
    #	print(count)
## EXAMPLE CODE
# Set a GPIO to output, and alternate the output between LOW and HIGH every 5 seconds

import time
import onionGpio

gpioNum = 1
gpioObj = onionGpio.OnionGpio(gpioNum)

# set to output
status = gpioObj.setOutputDirection(0)  # initialize the GPIO to 0 (LOW)

# alternate the value
loop = 1
value = 0
while loop == 1:
    # reverse the value
    if value == 0:
        value = 1
    else:
        value = 0

    # set the new value
    status = gpioObj.setValue(value)
    print 'GPIO%d set to: %d' % (gpioNum, value)

    time.sleep(5)
Exemple #28
0
import onionGpio

pin = 14

print '> Instantiating gpio object'
gpio14 = onionGpio.OnionGpio(pin)
print ''

print '> Set direction to input... '
ret = gpio14.setInputDirection()
print '    returned %d' % ret

print '> Get direction: ',
direction = gpio14.getDirection()
print direction

print '> Read value: ',
val = gpio14.getValue()
print val

raw_input('Ready to test output?')

print '> Set direction to output... '
ret = gpio14.setOutputDirection()
print '    returned %d' % ret

print '> Get direction: ',
direction = gpio14.getDirection()
print direction

print '> Read value: ',
import datetime
import time, json
import onionGpio  # See Library: https://github.com/OnionIoT/onion-gpio
import threading
from losantmqtt import Device
import paho.mqtt.client as mqtt  #import the client1

ledPin = 0  # GPIO 0
buttonPin = 1  # GPIO 1
ledPin1 = 3
lightStatus = 1
lightStatus1 = 0
st = ""
led = onionGpio.OnionGpio(ledPin)
led1 = onionGpio.OnionGpio(ledPin1)
led.setOutputDirection(0)  # make LED output and init to 0
led1.setOutputDirection(0)
led1.setValue(1)
led.setValue(1)
broker_address = "iot.eclipse.org"
port = 1883
print("creating new instance")


def on_publish(client, userdata, result):  #create function for callback
    print("data published \n")
    pass


#client1= paho.Client("control1")
client = mqtt.Client("akrdClient1")
import math
import onionGpio
import time
import json
import httplib
#from OmegaExpansion import onionI2C

#///////////////////////////////PAQUETES/////////////////////////////////////////
#//CONFIGURACION DEL ARREGLO(Tcomp,Tvent,Tdesc,Fdesc(horas),t_aire,t_refrig,Delta_t)
#//VARIABLES DE CONTROL

gpio15 = onionGpio.OnionGpio(15)  #compresor
gpio16 = onionGpio.OnionGpio(16)  #Ventilador
gpio17 = onionGpio.OnionGpio(17)  #Resistencia
ret1 = gpio15.setOutputDirection(0)
ret2 = gpio16.setOutputDirection(0)
ret3 = gpio17.setOutputDirection(0)
#///////////////VARIABLES PARA TIEMPO////////////////////////////////////////////
segundos = 0
minutos = 0
horas = 0
horas_2 = 0
#/////////////////VARIABLES PARA LEER TEMPERATURA////////////////////////////////
T1 = False
T2 = False
temp1 = 0
temp2 = 0
termistor = 0

BAN_1 = 0
BAN_2 = 0