Example #1
0
 def read(self):
     try:
         values = {}
         values["flow"] = self.board.read_flow_sensor()
         values["sound"] = self.board.read_sound_sensor()
         Tools.log(str(values))
         self.sensor_buffer["flow"].append(values["flow"])
         self.sensor_buffer["sound"].append(values["sound"])
     except IOError, e:
         Tools.log("I/O Error reading sensors. Exception: %s" % str(e), 1)
Example #2
0
 def read_once(self):
     try:
         values = {}
         #values['ultrasonic'] = self.board.read_ultrasonic_ranger()
         #values['dht'] = self.board.read_dht()
         Tools.log(str(values))
         #self.sensor_buffer["temp"].append(float(values['dht'][0]))
         #self.sensor_buffer["humidity"].append(int(values['dht'][1]))
         #self.sensor_buffer["ultrasonic"].append(values['ultrasonic'])
     except IOError, e:
         Tools.log('I/O Error reading sensors. Exception: %s' % str(e),1)
Example #3
0
 def read_once(self):
     try:
         values = {}
         values["ultrasonic"] = self.board.read_ultrasonic_ranger()
         values["dht"] = self.board.read_dht()
         Tools.log(str(values))
         self.sensor_buffer["temp"].append(int(values["dht"][0]))
         self.sensor_buffer["humidity"].append(int(values["dht"][1]))
         self.sensor_buffer["ultrasonic"].append(values["ultrasonic"])
     except IOError, e:
         Tools.log("I/O Error reading sensors. Exception: %s" % str(e), 1)
Example #4
0
 def read(self):
     try:
         values = {}
         #values['flow'] = self.board.read_flow_sensor()
         values['sound'] = self.board.read_sound_sensor()
         values['temp'] = float(self.board.read_temp_sensor())
         Tools.log(str(values))
         #self.sensor_buffer["flow"].append(values['flow'])
         #self.sensor_buffer["sbsid"].append("SBS001")
         self.sensor_buffer["sound"].append(values['sound'])
         self.sensor_buffer["temp"].append(values['temp'])
     except IOError, e:
         Tools.log('I/O Error reading sensors. Exception: %s' % str(e),1)
Example #5
0
 def setRGB(self, r,g,b):
     try:
         self.bus.write_byte_data(DISPLAY_RGB_ADDR,0,0)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR,1,0)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR,0x08,0xaa)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR,4,r)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR,3,g)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR,2,b)
         self.errorCount = 0
     except IOError:
         Tools.log("Error writing to RGB Screen",1)
         self.errorCount += 1
         if (self.errorCount<5):
             self.clear()
             self.setRGB(r,g,b)
Example #6
0
 def setRGB(self, r, g, b):
     try:
         self.bus.write_byte_data(DISPLAY_RGB_ADDR, 0, 0)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR, 1, 0)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR, 0x08, 0xaa)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR, 4, r)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR, 3, g)
         self.bus.write_byte_data(DISPLAY_RGB_ADDR, 2, b)
         self.errorCount = 0
     except IOError:
         Tools.log("Error writing to RGB Screen", 1)
         self.errorCount += 1
         if (rgbErrorCount < 5):
             self.clear()
             self.setRGB(r, g, b)
Example #7
0
    def __init__(self, pins, thresholds):
        super(RaspPi, self).__init__(pins, thresholds, "RPi")

        self.flow_sensor = GroveFlowSensor(self.pins['sensors']['flow-sensor'])
        self.sound_sensor = SoundSensor(self.pins['sensors']['sound-sensor'],
                                        self.thresholds['sound'])
        self.ultrasonic_ranger = UltraSonicRanger(
            self.pins['sensors']['ultrasonic-ranger'],
            self.thresholds['ultrasonic'])
        self.lcd = GroveRGB()
        self.buttons = {}
        self.leds = {}

        if (pins):
            for button in pins['buttons']:
                if pins['buttons'][button] > 0:
                    self.buttons[button] = GroveButton(pins['buttons'][button],
                                                       button)

            for led in pins['led']:
                if (pins['led'][led] > 0):
                    self.leds[led] = GroveLED(pins['led'][led], led)

        self.print_to_screen('Simple Beer \n Service 4.0', RGB['orange'])
        for c in range(0, 255):
            self.lcd.setRGB(c, 255 - c, 0)
            time.sleep(0.01)
            self.lcd.setRGB(0, 255, 0)

        self.print_to_screen('IP Address: \n ' + Tools.get_ip_address(),
                             [0, 128, 64])
        time.sleep(10)
Example #8
0
    def __init__(self, pins, thresholds):
        super(RaspPi,self).__init__(pins, thresholds, "RPi")

        self.flow_sensor = GroveFlowSensor(self.pins['sensors']['flow-sensor'])
        self.sound_sensor = SoundSensor(self.pins['sensors']['sound-sensor'], self.thresholds['sound'])
        self.ultrasonic_ranger = UltraSonicRanger(self.pins['sensors']['ultrasonic-ranger'], self.thresholds['ultrasonic'])
        self.lcd = GroveRGB()
        self.buttons = {}
        self.leds = {}

        if (pins):
            for button in pins['buttons']:
                if pins['buttons'][button]>0:
                    self.buttons[button] = GroveButton(pins['buttons'][button],button)

            for led in pins['led']:
                if (pins['led'][led]>0):
                    self.leds[led] = GroveLED(pins['led'][led],led)

        self.print_to_screen('Simple Beer \n Service 4.0', RGB['orange'])
        for c in range(0,255):
            self.lcd.setRGB(c,255-c,0)
            time.sleep(0.01)
            self.lcd.setRGB(0,255,0)

        self.print_to_screen('IP Address: \n '+Tools.get_ip_address(), [0,128,64])
        time.sleep(10)
Example #9
0
    def send(self, data):

        # NOTE:
        # Depending on the version of python / OS (https://bugs.python.org/issue21246) you may
        # run in to issues making requests to HTTPS endpoint, hence we are using pycurl library here

        # Commented out to showcase how to make a request via urllib2
        #payload = json.dumps(data)
        #req = urllib2.Request(url, payload)
        #req.add_header('Content-Type', 'application/json')
        #try:
        #    r = urllib2.urlopen(req)
        #    response = r.read()
        #    return response
        #except Exception, e:
        #    print "error sending data to %s" % url, e
        #    return


        #Send request using pycurl
        c = pycurl.Curl()
        c.setopt(c.URL, self.url)
        body = json.dumps(data)

        Tools.log('Payload: %s' % data)
        Tools.log('URL: %s' % c.URL)

        try:
            c.setopt(pycurl.HTTPHEADER, [('x-api-key: %s' % self.apiKey), 'Content-Type: %s' % self.contentType])
            c.setopt(c.POSTFIELDS,  body)
            c.perform()

            response_code = c.getinfo(c.RESPONSE_CODE)
            if (response_code==200):
                Tools.log('Successful Post [%f].' % c.getinfo(c.TOTAL_TIME),2)
            else:
                Tools.log('Error writing to AWS. Response code: %i ' % response_code,2)

        except Exception, e:
            Tools.log('Error writing to AWS: %s' % e,1)
            pass
Example #10
0
 def get_sensor_data(self):
     Tools.log("Buffer:" + str(self.sensor_buffer))
     try:
         sensor_data = {"sensors": {}, "recordTimestamp": {}}
         sensor_data["sensors"]["flow"] = sum(self.sensor_buffer["flow"])
         sensor_data["sensors"]["sound"] = statistics.median(self.sensor_buffer["sound"])
         sensor_data["sensors"]["ultrasonic"] = statistics.median(self.sensor_buffer["ultrasonic"])
         sensor_data["sensors"]["temp"] = statistics.mean(self.sensor_buffer["temp"])
         sensor_data["sensors"]["humidity"] = statistics.mean(self.sensor_buffer["humidity"])
         sensor_data["recordTimestamp"] = Tools.now_int_epoch()
         Tools.log("Data to send:" + str(sensor_data))
         GLOBALS["errorCount"] -= 0.5
     except Exception, e:
         Tools.log("Error caculating data: %s" % str(e), 1)
Example #11
0
 def get_sensor_data(self):
     Tools.log("Buffer:"+str(self.sensor_buffer))
     try:
         sensor_data = { 'sbsid': {}, 'sensors': {}, 'recordTimestamp': {} }
         sensor_data['sbsid'] = "SBS001"
         #sensor_data['sensors']['flow'] = sum(self.sensor_buffer['flow'])
         sensor_data['sensors']['sound'] = statistics.mean(self.sensor_buffer['sound'])
         #sensor_data['sensors']['ultrasonic'] = statistics.median(self.sensor_buffer['ultrasonic'])
         sensor_data['sensors']['temp'] = statistics.mean(self.sensor_buffer['temp'])
         #sensor_data['sensors']['humidity'] = statistics.mean(self.sensor_buffer['humidity'])
         sensor_data['recordTimestamp'] = Tools.now_int_epoch()
         Tools.log("Data to send:"+str(sensor_data))
         GLOBALS['errorCount'] -= 0.5
     except Exception, e:
         Tools.log('Error caculating data: %s' % str(e),1)
    def __init__(self, pins, thresholds):
        super(LegacyRaspPi,self).__init__(pins, thresholds, "RPi")
        GPIO.cleanup()
        GPIO.setmode(GPIO.BOARD)
        self.flow_sensor = LegacyFlowSensor(self.pins['sensors']['flow-sensor'])
        self.sound_sensor = LegacySoundSensor(self.pins['sensors']['sound-sensor'], self.thresholds['sound'])
        self.leds = {}
        self.buttons = {}

#        for button in pins['buttons']:
#            if pins['buttons'][button]>0:
#                self.buttons[button] = GroveButton(pins['buttons'][button], button)

        for led in pins['led']:
            if (pins['led'][led]>0):
                self.leds[led] = LegacyLED(pins['led'][led], led)

        self.print_to_screen('Simple Beer \n Service 4.0', RGB['orange'])
        self.print_to_screen('IP Address: \n '+Tools.get_ip_address(), [0,128,64])
        time.sleep(10)
Example #13
0
    def __init__(self, pins, thresholds):
        super(LegacyRaspPi, self).__init__(pins, thresholds, "RPi")
        GPIO.cleanup()
        GPIO.setmode(GPIO.BOARD)
        self.flow_sensor = LegacyFlowSensor(
            self.pins['sensors']['flow-sensor'])
        self.sound_sensor = LegacySoundSensor(
            self.pins['sensors']['sound-sensor'], self.thresholds['sound'])
        self.leds = {}
        self.buttons = {}

        #        for button in pins['buttons']:
        #            if pins['buttons'][button]>0:
        #                self.buttons[button] = GroveButton(pins['buttons'][button], button)

        for led in pins['led']:
            if (pins['led'][led] > 0):
                self.leds[led] = LegacyLED(pins['led'][led], led)

        self.print_to_screen('Simple Beer \n Service 4.0', RGB['orange'])
        self.print_to_screen('IP Address: \n ' + Tools.get_ip_address(),
                             [0, 128, 64])
        time.sleep(10)
Example #14
0
 def reset_wifi(self):
     Tools.log("reset_wifi: check for button, default false.", 3)
     return False
Example #15
0
 def __init__(self, pins, thresholds, type):
     self.pins = pins
     self.type = type
     self.thresholds = thresholds
     Tools.log('Simple Beer Service 4.0',2)
     Tools.log('IP Address: %s' % Tools.get_ip_address(),2)
Example #16
0
 def print_to_screen(self,message,rgb):
     Tools.log("%s | %s" % (message,rgb),3)
 def reset_wifi(self):
     Tools.log("Reset Wifi")
Example #18
0
 def getAndClear(self):
     record = self.get_sensor_data()
     self.clear_buffer()
     Tools.log("Buffer cleared.")
     return record
Example #19
0
 def blink(self,led):
     Tools.log("%s blinking..." % led,3)
Example #20
0
            pass

    # Collect the values from the sensors on the board.
    @gen.coroutine
    def read(self):
        try:
            values = {}
            values["flow"] = self.board.read_flow_sensor()
            values["sound"] = self.board.read_sound_sensor()
            Tools.log(str(values))
            self.sensor_buffer["flow"].append(values["flow"])
            self.sensor_buffer["sound"].append(values["sound"])
        except IOError, e:
            Tools.log("I/O Error reading sensors. Exception: %s" % str(e), 1)
        except Exception, e:
            Tools.log("Error reading sensors: %s" % str(e), 1)
            pass

    def get_sensor_data(self):
        Tools.log("Buffer:" + str(self.sensor_buffer))
        try:
            sensor_data = {"sensors": {}, "recordTimestamp": {}}
            sensor_data["sensors"]["flow"] = sum(self.sensor_buffer["flow"])
            sensor_data["sensors"]["sound"] = statistics.median(self.sensor_buffer["sound"])
            sensor_data["sensors"]["ultrasonic"] = statistics.median(self.sensor_buffer["ultrasonic"])
            sensor_data["sensors"]["temp"] = statistics.mean(self.sensor_buffer["temp"])
            sensor_data["sensors"]["humidity"] = statistics.mean(self.sensor_buffer["humidity"])
            sensor_data["recordTimestamp"] = Tools.now_int_epoch()
            Tools.log("Data to send:" + str(sensor_data))
            GLOBALS["errorCount"] -= 0.5
        except Exception, e:
Example #21
0
 def print_to_screen(self, message, rgb):
     Tools.log(message)
Example #22
0
 def reset_wifi(self):
     Tools.log("Reset Wifi")
Example #23
0
 def __init__(self, pins, thresholds, type):
     self.pins = pins
     self.type = type
     self.thresholds = thresholds
     Tools.log('Simple Beer Service 4.0', 2)
     Tools.log('IP Address: %s' % Tools.get_ip_address(), 2)
 def turn_off_led(self, led):
     Tools.log("%s light off" % led, 3)
 def blink(self, led):
     Tools.log("%s blinking..." % led, 3)
Example #26
0
 def __init__(self, pin, name):
     super(LegacyLED, self).__init__(pin, name)
     Tools.log("Init pin at " + str(self.pin))
     GPIO.setup(self.pin, GPIO.OUT)
 def clear(self):
     Tools.log("Board cleared.", 3)
Example #28
0
 def turn_on_led(self,led):
     Tools.log("%s light on" % led,3)
 def turn_on_led(self, led):
     Tools.log("%s light on" % led, 3)
Example #30
0
 def turn_off_led(self,led):
     Tools.log("%s light off" % led,3)
Example #31
0
    @gen.coroutine
    def read(self):
        try:
            values = {}
            #values['flow'] = self.board.read_flow_sensor()
            values['sound'] = self.board.read_sound_sensor()
            values['temp'] = float(self.board.read_temp_sensor())
            Tools.log(str(values))
            #self.sensor_buffer["flow"].append(values['flow'])
            #self.sensor_buffer["sbsid"].append("SBS001")
            self.sensor_buffer["sound"].append(values['sound'])
            self.sensor_buffer["temp"].append(values['temp'])
        except IOError, e:
            Tools.log('I/O Error reading sensors. Exception: %s' % str(e),1)
        except Exception, e:
            Tools.log('Error reading sensors: %s' % str(e),1)
            pass

    def get_sensor_data(self):
        Tools.log("Buffer:"+str(self.sensor_buffer))
        try:
            sensor_data = { 'sbsid': {}, 'sensors': {}, 'recordTimestamp': {} }
            sensor_data['sbsid'] = "SBS001"
            #sensor_data['sensors']['flow'] = sum(self.sensor_buffer['flow'])
            sensor_data['sensors']['sound'] = statistics.mean(self.sensor_buffer['sound'])
            #sensor_data['sensors']['ultrasonic'] = statistics.median(self.sensor_buffer['ultrasonic'])
            sensor_data['sensors']['temp'] = statistics.mean(self.sensor_buffer['temp'])
            #sensor_data['sensors']['humidity'] = statistics.mean(self.sensor_buffer['humidity'])
            sensor_data['recordTimestamp'] = Tools.now_int_epoch()
            Tools.log("Data to send:"+str(sensor_data))
            GLOBALS['errorCount'] -= 0.5
Example #32
0
 def clear(self):
     Tools.log("Board cleared.",3)
 def reset_wifi(self):
     Tools.log("reset_wifi: check for button, default false.", 3)
     return False
Example #34
0
 def __init__(self, pins, thresholds, type):
     self.pins = pins
     self.type = type
     self.thresholds = thresholds
     Tools.log("Simple Home Monitor v1", 2)
     Tools.log("IP Address: %s" % Tools.get_ip_address(), 2)
 def print_to_screen(self, message, rgb):
     Tools.log("%s | %s" % (message, rgb), 3)
 def print_to_screen(self, message, rgb):
     Tools.log(message);
Example #37
0
 def __init__(self, pin, name):
     super(LegacyLED,self).__init__(pin, name)
     Tools.log("Init pin at "+str(self.pin))
     GPIO.setup(self.pin, GPIO.OUT)
Example #38
0
 def __init__(self, pin, name):
     self.pin = pin
     self.name = name.capitalize()
     Tools.log("Initialized %s at pin %i" % (name, pin), 2)
Example #39
0
 def __init__(self, pin, name):
     self.pin = pin
     self.name = name.capitalize()
     Tools.log("Initialized %s at pin %i" % (name, pin), 2)