def printValues():
    degrees = hdc1000.readTemperature()
    humidity = hdc1000.readHumidity()
    print 'Temp             = {0:0.3f} deg C'.format(degrees)
    print 'Humidity         = {0:0.2f} %'.format(humidity)

    if (config.Sunlight_Present == True):
        ################
        SunlightVisible = Sunlight_Sensor.readVisible()
        SunlightIR = Sunlight_Sensor.readIR()
        SunlightUV = Sunlight_Sensor.readUV()
        SunlightUVIndex = SunlightUV / 100.0
        print 'Sunlight Visible:  ' + str(SunlightVisible)
        print 'Sunlight IR:       ' + str(SunlightIR)
        print 'Sunlight UV Index: ' + str(SunlightUVIndex)
        ################pass
    #ultrasonicRanger.getAndPrint()
    print("Plant #1 Moisture = {}").format(state.Moisture_Humidity)
    #         if (config.ADS1115_Present):
    #             GPIO.output(config.moisturePower, GPIO.HIGH)
    #             Moisture_Humidity   = ads1115.readADCSingleEnded(config.moistureADPin, gain, sps)/7 # AIN0 wired to AirQuality Sensor
    #             GPIO.output(config.moisturePower, GPIO.LOW)
    #
    #             Moisture_Humidity = Moisture_Humidity / 7.0
    #             if (Moisture_Humidity >100):
    #                 Moisture_Humidity = 100;
    #             print "Moisture Humidity = %0.2f" % (Moisture_Humidity)

    sensor_value = AirQualitySensorLibrary.readAirQualitySensor(ads1115)

    sensorList = AirQualitySensorLibrary.interpretAirQualitySensor(
        sensor_value)
    print "Sensor Value=%i --> %s  | %i" % (sensor_value, sensorList[0],
                                            sensorList[1])

    tankPercentFull = ultrasonicRanger.returnPercentFull()
    print("Percentage water inside tank: {}%".fomat(tankPercentFull))

    print('------')
Пример #2
0
def updateState():

  if (config.DEBUG):
      print "Attempt UpdateStateLock acquired"
  UpdateStateLock.acquire()
  if (config.DEBUG):
      print "UpdateStateLock acquired"


  # catch Exceptions and MAKE SURE THE LOCK is released!
  try:
    if (state.SGS_State == state.SGS_States.Monitor):  
            state.SGS_State =state.SGS_States.Sampling
            if (config.USEBLYNK):
                updateBlynk.blynkStatusUpdate()
	    if (config.DEBUG):
            	print "----------------- "
            	print "Update State"
            	print "----------------- "
            if (config.Sunlight_Present == True):
        			if (config.DEBUG):
                                	print " Sunlight Vi/state.Sunlight_IR/UV Sensor"
            else:
        			if (config.DEBUG):
                                	print " Sunlight Vi/state.Sunlight_IR/UV Sensor Not Present"
            if (config.DEBUG):
            	print "----------------- "
    
            if (config.Sunlight_Present == True):
                    ################
                    state.Sunlight_Vis = SI1145Lux.SI1145_VIS_to_Lux(Sunlight_Sensor.readVisible())
                    state.Sunlight_IR = SI1145Lux.SI1145_IR_to_Lux(Sunlight_Sensor.readIR())
                    state.Sunlight_UV = Sunlight_Sensor.readUV()
                    state.Sunlight_UVIndex = state.Sunlight_UV / 100.0

            	    if (config.DEBUG):
                    	print 'Sunlight Visible:  ' + str(state.Sunlight_Vis)
                    	print 'Sunlight state.Sunlight_IR:       ' + str(state.Sunlight_IR)
                    	print 'Sunlight UV Index (RAW): ' + str(state.Sunlight_UV)
                    	print 'Sunlight UV Index: ' + str(state.Sunlight_UVIndex)
                    ################
    
    
            if (config.ADS1115_Present):
                state.Moisture_Humidity  = extendedPlants.readExtendedMoisture(1, None, ads1115, None, None) 
                state.Moisture_Humidity_Array[0] =  state.Moisture_Humidity 

                for i in range(2,config.plant_number+1):     
                    state.Moisture_Humidity_Array[i-1] = extendedPlants.readExtendedMoisture(i,GDE_Ext1, ads1115_ext1, GDE_Ext2, ads1115_ext2)

                if (config.DEBUG):
                    print ("From Moisture Array")
                    for i in range(0,config.plant_number):     
                        print "plant #%i: Moisture: %0.2f" % (i+1, state.Moisture_Humidity_Array[i])
                    print ("From RAW Moisture Array")
                    for i in range(0,config.plant_number):     
                        print "plant #%i: Moisture: %0.2f" % (i+1, state.Raw_Moisture_Humidity_Array[i])

                state.AirQuality_Sensor_Value =  AirQualitySensorLibrary.readAirQualitySensor(ads1115)
    
                sensorList = AirQualitySensorLibrary.interpretAirQualitySensor(state.AirQuality_Sensor_Value)
            	if (config.DEBUG):
                	print "Sensor Value=%i --> %s  | %i"% (state.AirQuality_Sensor_Value, sensorList[0], sensorList[1])

                state.AirQuality_Sensor_Number = sensorList[1] 
                state.AirQuality_Sensor_Text = sensorList[0] 

            # update water Level
            percentFull = ultrasonicRanger.returnPercentFull()
            # check for abort
            if (percentFull < 0.0):
                if (config.DEBUG):
                    print "---->Bad Measurement from Ultrasonic Sensor for Tank Level"
                # leave the previous value
            else:
                state.Tank_Percentage_Full = percentFull
        
            if (state.Tank_Percentage_Full > config.Tank_Pump_Level):
                state.Pump_Water_Full = True
            else:
                state.Pump_Water_Full = False

            # read temp humidity
   
            if (config.hdc1000_Present):
                state.Temperature= hdc1000.readTemperature()
                state.Humidity = hdc1000.readHumidity()
    
           	if (config.DEBUG):
            		print 'Temp             = {0:0.3f} deg C'.format(state.Temperature)
            		print 'Humidity         = {0:0.2f} %'.format(state.Humidity)
    
            state.SGS_State =state.SGS_States.Monitor
            if (config.USEBLYNK):
                updateBlynk.blynkStatusUpdate()

            if (config.USE_MQTT):
                try:
                    updateMqtt.updateMqtt(
                        moisture=state.Moisture_Humidity,
                        temperature=util.returnTemperatureCF(state.Temperature),
                        humidity=state.Humidity,
                        air_quality=state.AirQuality_Sensor_Value,
                        light=state.Sunlight_Vis
                    )
                except Exception as e:
                    print('Could not publish to MQTT: ' + e.message)
          

            if (config.OLED_Present) and (state.SGS_State == state.SGS_States.Monitor) :


                    if (config.DEBUG):
                          print "Attempt OLEDLock acquired"
		    OLEDLock.acquire()
                    if (config.DEBUG):
                          print "OLEDLock acquired"
                    Scroll_SSD1306.addLineOLED(display,  ("----------"))
                    Scroll_SSD1306.addLineOLED(display,  ("Plant #1 Moisture = \t%0.2f %%")%(state.Moisture_Humidity))
                    Scroll_SSD1306.addLineOLED(display,  ("Temperature = \t%0.2f %s")%(util.returnTemperatureCF(state.Temperature), util.returnTemperatureCFUnit()))
                    Scroll_SSD1306.addLineOLED(display,  ("Humidity =\t%0.2f %%")%(state.Humidity))
                    Scroll_SSD1306.addLineOLED(display,  ("Air Qual = %d/%s")%(state.AirQuality_Sensor_Value, state.AirQuality_Sensor_Text))
                    Scroll_SSD1306.addLineOLED(display,  ("Sunlight = \t%0.2f Lux")%(state.Sunlight_Vis))
                    # Now display other plants
                    if (config.plant_number >1):
                        # print 2-4
                        time.sleep(2.0)
                        Scroll_SSD1306.addLineOLED(display,  ("----------"))
                        Scroll_SSD1306.addLineOLED(display,  ("Plant #2 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[1]))
                        Scroll_SSD1306.addLineOLED(display,  ("Plant #3 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[2]))
                        Scroll_SSD1306.addLineOLED(display,  ("Plant #4 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[3]))
                        Scroll_SSD1306.addLineOLED(display,  ("Plant #5 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[4]))
                        if (config.plant_number >5):
                            time.sleep(2.0)
                            Scroll_SSD1306.addLineOLED(display,  ("----------"))
                            Scroll_SSD1306.addLineOLED(display,  ("Plant #6 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[5]))
                            Scroll_SSD1306.addLineOLED(display,  ("Plant #7 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[6]))
                            Scroll_SSD1306.addLineOLED(display,  ("Plant #8 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[7]))
                            Scroll_SSD1306.addLineOLED(display,  ("Plant #9 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[8]))
                        
                    if (config.DEBUG):
                        print "Attempt OLEDLock released"
		    OLEDLock.release()
                    if (config.DEBUG):
 
                        print "OLEDLock released"

  except Exception as e:
    if (config.DEBUG):
        print "Exception Raised in Update State"
    print e 
    traceback.print_exc(file=sys.stdout)
  finally:
    pass 
  if (config.DEBUG):
    print "Attempt UpdateStateLock released"
  UpdateStateLock.release()
  if (config.DEBUG):
          print "UpdateStateLock released"
          print ">>>>>>>>>>>>>>"
          print "Exiting Update State"
          print ">>>>>>>>>>>>>>"

  if (config.USEBLYNK):
     updateBlynk.blynkStateUpdate()
Пример #3
0
# determine if device present
try:
       value = ads1115.readRaw(0, gain, sps) # AIN0 wired to AirQuality Sensor
       time.sleep(1.0)
       value = ads1115.readRaw(0, gain, sps) # AIN0 wired to AirQuality Sensor

       config.ADS1115_Present = True

except TypeError as e:
       config.ADS1115_Present = False

###############
#Ultrasonic Level Teset
###############

percentFull = ultrasonicRanger.returnPercentFull()
# check for abort
if (percentFull < 0.0):
    if (config.DEBUG):
        print "---->Bad Measurement from Ultrasonic Sensor for Tank Level"
    config.UltrasonicLevel_Present = False
else:
    config.UltrasonicLevel_Present = True


import SDL_Pi_GroveDigitalExtender
###############
#Grove Digital Extender Ext1 setup
###############
GDE_Ext1 = None
try: