Ejemplo n.º 1
0
    def monitorCurrent(self, intent_message, hermes, device, maxCurrent):
        while True:
            try:
                current_low = instrument.read_register(0x0001,
                                                       0,
                                                       functioncode=4,
                                                       signed=False)
                current_high = instrument.read_register(0x0002,
                                                        0,
                                                        functioncode=4,
                                                        signed=False)
                current = (current_high << 8 | current_low)
                if current > maxCurrent:
                    reply = "Max Current Reached. Turning " + str(
                        device) + " off"
                    gpio.setDigital(relayPin, 1)
                    hermes.publish_start_session_notification(
                        intent_message.site_id, reply, "snips_power_app")
                    hermes.publish_end_session(intent_message.session_id,
                                               reply)
                    break

            except ValueError:
                pass
            except IOError:
                pass
Ejemplo n.º 2
0
 def play(self, delay, repeat):
     for i in range(repeat):
         if self._stop_flag:
             return
         gpio.setDigital(self._buzzer_pin, 'OFF')
         time.sleep(delay)
         gpio.setDigital(self._buzzer_pin, 'ON')
         time.sleep(delay)
Ejemplo n.º 3
0
    def buzz(self, frequency, length):

        if (frequency == 0):
            time.sleep(length)
            return
        # in physics, the period (sec/cyc) is the inverse of the frequency (cyc/sec)
        period = 1.0 / frequency
        delayValue = period / 2  # calcuate the time for half of the wave
        # the number of waves to produce is the duration times the frequency
        numCycles = int(length * frequency)

        # start a loop from 0 to the variable "cycles" calculated above
        for i in range(numCycles):
            gpio.setDigital(self._buzzer_pin, 'ON')  # set buzzer_pin to high
            time.sleep(delayValue)  # wait with buzzer_pin high
            gpio.setDigital(self._buzzer_pin, 'OFF')  # set buzzer_pin to low
            time.sleep(delayValue)  # wait with buzzer_pin low
    def turnOff_callback(self, hermes, intent_message):

        hermes.publish_end_session(intent_message.session_id, "")
        print ('[Received] intent: {}'.format(intent_message.intent.intent_name))

        device = None
        if intent_message.slots:
            device = intent_message.slots.deviceName.first().value
            # check if valid
            if device not in availableDevice:
                device = None

        if device is None:
            reply = "No device specified"
        else:
            reply = "Turning "+str(device) + " off"
            gpio.setDigital(relayPin,1)
        hermes.publish_start_session_notification(intent_message.site_id, reply,"snips_power_app")
        hermes.publish_end_session(intent_message.session_id, reply)
    def reading_sonic(self):
        gpio.setDigital(self.TRIG, 'ON')
        # GPIO.output(self.TRIG, True)
        time.sleep(0.00001)
        gpio.setDigital(self.TRIG, 'OFF')
        # GPIO.output(self.TRIG, False)
        print(gpio.getDigital(self.ECHO))

        while gpio.getDigital(self.ECHO) == 0:
            signaloff = time.time()

        while gpio.getDigital(self.ECHO) == 1:
            signalon = time.time()

        timepassed = signalon - signaloff
        distance = timepassed * 17000
        # GPIO.cleanup()
        print('distance is: ', distance)
        return distance
Ejemplo n.º 6
0
    def _make_sound(self):
        # First try for the not so important song
        try:
            # construct to set stop flag
            self._active_buzzer_beep = ActiveAlarmBeep(self._PIN_BEEP)
            # quiet song
            self._passive_buzzer_melody = BuzzerSong(self._PIN_SONG)
            self._passive_buzzer_melody.setup()
            # start the selected song
            self._passive_buzzer_melody.select_song(self._selected_song)
            get_logger(__name__).info(f'Passive Buzzer alarm was successful')
        except:
            get_logger(__name__).error(
                f'Critical error in _melody @ passiv buzzer')
            logging.exception('Critical error in _melody @ passiv buzzer')
        finally:
            gpio.setDigital(self._PIN_SONG, 'OFF')

        # Second try in case the passive buzzer fails
        try:
            self._active_buzzer_beep.play(1, 90)
            get_logger(__name__).info(
                f'Active Buzzer BEEP LOUD alarm was successful')
        except:
            get_logger(__name__).error(
                f'Critical error in play @ ActiveAlarmBeep')
            logging.exception('Critical error in play @ ActiveAlarmBeep')
        finally:
            # Reset the beep flag
            gpio.setDigital(self._PIN_BEEP, 'ON')
            gpio.setDigital(self._PIN_SONG, 'OFF')

        # display the time
        sleep(5)
        self._broker.publish('alarm-button-stop', 'voice-triggered')
Ejemplo n.º 7
0
def motorSpeedLeft(direction, speed):
    if direction == 1:  ## FORWARD!
        gpio.setDigital(6, 'ON')  #Drive forward: ON
        gpio.setDigital(4, 'OFF')  #Drive backwards: OFF

    elif direction == 0:  #BACKWARDS!!
        gpio.setDigital(6, 'OFF')  #Drive forward: OFF
        gpio.setDigital(4, 'ON')  #Drive backwards: ON

    if speed < 0:
        speed = 0
    if speed > 100:
        speed = 100

    gpio.setPWM({
        "pin": 8,
        "percentage": speed,
        "frequency": 1000,
    })
Ejemplo n.º 8
0
 def close(self):
     gpio.setDigital(self._buzzer_pin, "OFF")  # Set the pin to off
import time
ser = serial.Serial()
ser.port='/dev/ttyUSB2'
ser.baudrate=115200
ser.open()
ser.write("\r\n\r\n".encode()) # Hit enter a few times to wake the printer
time.sleep(2)   # Wait for printer to initialize
ser.flushInput()
##3D Printer



relayPin = 0
gpio.setFunction(relayPin, 'DIGITAL')
gpio.setMode(relayPin, "output")
gpio.setDigital(relayPin,1)


MQTT_IP_ADDR = "localhost"
MQTT_PORT = 1883
MQTT_ADDR = "{}:{}".format(MQTT_IP_ADDR, str(MQTT_PORT))

availableDevice = ['printer']

class snips_power_app(object):
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except :
            self.config = None
Ejemplo n.º 10
0
 def close(self):
     gpio.setDigital(self._buzzer_pin, "ON")
Ejemplo n.º 11
0
 def setup(self):
     gpio.setFunction(self._buzzer_pin, 'DIGITAL')
     gpio.setMode(self._buzzer_pin, 'output')
     gpio.setDigital(self._buzzer_pin, "ON")
Ejemplo n.º 12
0
 def close(self):
     if self._thread_buzzer_flag != None:
         self._thread_buzzer_flag.set()
     # Make sure there is no power on the pin after closing
     gpio.setDigital(self._PIN_BEEP, 'ON')
     gpio.setDigital(self._PIN_SONG, 'OFF')