Beispiel #1
0
def initializeSGSPart3():

        if (config.SWDEBUG):
            if (config.USEBLYNK):
                print("Blynk Status=", updateBlynk.blynkSGSAppOnline())
                updateBlynk.blynkAlarmUpdate();
    
        state.Last_Event = "SGS Started:"+time.strftime("%Y-%m-%d %H:%M:%S")
    
        if (config.USEBLYNK):
            updateBlynk.blynkEventUpdate()
    
        if (config.OLED_Present):
            if (config.LOCKDEBUG):
                 print("Attempt OLEDLock acquired")
            OLEDLock.acquire()
            if (config.LOCKDEBUG):
                 print("OLEDLock acquired")
    	# display logo
            image = Image.open('SmartPlantPiSquare128x64.ppm').convert('1')
    
            display.image(image)
            display.display()
            time.sleep(3.0)
            display.clear()
    
            Scroll_SSD1306.addLineOLED(display,  ("    Welcome to "))
            Scroll_SSD1306.addLineOLED(display,  ("   Smart Garden "))
            if (config.LOCKDEBUG):
                 print("Attempt OLEDLock released")
            OLEDLock.release()
            if (config.LOCKDEBUG):
                 print("OLEDLock released")
    
        
         
        
        # initialize variables
        #
        state.Pump_Water_Full = False
        
                
    
        checkAndWater()
        checkForAlarms()
Beispiel #2
0
def displayActiveAlarms():

        # do not do this during update state

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

	# display Alarm
        if (config.DEBUG):
		print "Display Alarms"
    	if ((config.OLED_Present == True) and (state.SGS_State == state.SGS_States.Monitor)):

                if (config.DEBUG):
                      print "Attempt OLEDLock acquired"
        	OLEDLock.acquire()
                if (config.DEBUG):
                      print "OLEDLock acquired"
		
        	state.SGS_State =state.SGS_States.Alarm
                if (config.USEPUBNUB):
                    publishStatusToPubNub()
                if (config.USEBLYNK):
                    updateBlynk.blynkStatusUpdate()
		# initialize 
		list = startAlarmStatementDisplay(display)
		# Flash white screen w/Alarm in middle
		displayAlarmStatementOLEDDisplay(list, "ALARM!",lengthofline=13)
                time.sleep(0.25)
		# wait 2 seconds
		finishAlarmStatementDisplay(list)

		# display alarms, one per screen on black screen
		list = startAlarmStatementDisplay(display)


                state.Is_Alarm_MoistureFault = False
    		
                for i in range(0,config.plant_number):
                    if (state.Moisture_Humidity_Array[i] <= state.Alarm_Moisture_Sensor_Fault):
        		if (config.DEBUG):
                            print "Plant #{:d}---->Moisture Sensor Fault".format(i+1)
                        displayAlarmOLEDDisplay(list, "#{:d}MS FLT!".format(i), 10)
                        state.Is_Alarm_MoistureFault = True
                        time.sleep(0.25)

		if (state.Alarm_Temperature >= state.Temperature):
        		if (config.DEBUG):
				print "---->Temperature Alarm!"
			displayAlarmOLEDDisplay(list, "Low Temp", 10)
		  	time.sleep(0.25)

		if (state.Alarm_Moisture >= state.Moisture_Humidity):
			displayAlarmOLEDDisplay(list, "Plant Dry", 14)
		  	time.sleep(0.25)

		if (state.Alarm_Water  == True ):
			if (state.Pump_Water_Full == False):
				displayAlarmOLEDDisplay(list, "No Water", 12)
			        time.sleep(0.25)

		if (state.Alarm_Air_Quality <  state.AirQuality_Sensor_Value):
			displayAlarmOLEDDisplay(list, "Air Quality", 14)
			time.sleep(0.25)


		finishAlarmStatementDisplay(list)


		# Flash white to end
		list = startAlarmStatementDisplay(display)
		# Flash white screen w/Alarm in middle
		displayAlarmStatementOLEDDisplay(list, "ALARM!",lengthofline=15)
		time.sleep(1.0)
		# wait 1 seconds
		finishAlarmStatementDisplay(list)

        	state.SGS_State = state.SGS_States.Monitor
                if (config.USEBLYNK):
                    updateBlynk.blynkStatusUpdate()

                if (config.USEPUBNUB):
                    publishStatusToPubNub()

                if (config.DEBUG):
                    print "Attempt OLEDLock released"
        	OLEDLock.release()
                if (config.DEBUG):
                    print "OLEDLock released"

		if (state.Alarm_Active == False):   # it has been disabled
                        if (config.USEPUBNUB):
			    publishAlarmToPubNub("deactivated")
                        if (config.USEBLYNK):
                            updateBlynk.blynkAlarmUpdate()    
        if (config.DEBUG):
          print "DA-Attempt UpdateStateLock released"
        UpdateStateLock.release()
        if (config.DEBUG):
          print "DA-UpdateStateLock released"
Beispiel #3
0
def checkForAlarms():

	# check to see alarm
        if (config.DEBUG):
		print "checking for alarm"
                if (state.Alarm_Active == True):
                    print "Alarm_Active = True"
                else:
                    print "Alarm_Active = False"
        # initialize 
        list = startAlarmStatementDisplay(display)

        lastAlarm = state.Alarm_Active
	if (state.Alarm_Active == True):
		activeAlarm = False
                state.Is_Alarm_MoistureFault = False
    		
                for i in range(0,config.plant_number):
                    if (state.Moisture_Humidity_Array[i] <= state.Alarm_Moisture_Sensor_Fault):
        		if (config.DEBUG):
                            print "Plant #{:d}---->Moisture Sensor Fault".format(i+1)
                        displayAlarmOLEDDisplay(list, "#{:d}MS FLT!".format(i), 10)
                        state.Is_Alarm_MoistureFault = True
        	
                
                if (state.Alarm_Air_Quality < state.AirQuality_Sensor_Value):
                    if (config.DEBUG):
			print "state.Alarm_Air_Quality=", state.Alarm_Air_Quality
			print "state.AirQuality_Sensor_Value", state.AirQuality_Sensor_Value
                    state.Is_Alarm_AirQuality = True
	            activeAlarm = True
                else:
                    state.Is_Alarm_AirQuality = False

		if (state.Alarm_Temperature >= state.Temperature):
        	    if (config.DEBUG):
			print "---->Low Temperature Alarm!"
	            activeAlarm = True
                    state.Is_Alarm_Temperature = True
                else:
                    state.Is_Alarm_Temperature = False

                state.Is_Alarm_Moisture = False
                for i in range(0,config.plant_number):
                    if (state.Moisture_Humidity_Array[i] <= state.Alarm_Moisture):
        		if (config.DEBUG):
                            print "Plant #{:d}---->Moisture Low Alarm".format(i+1)
                        state.Is_Alarm_Moisture = True
		        activeAlarm = True

		if (state.Alarm_Water  == True ):
		    if (state.Pump_Water_Full == False):
        		if (config.DEBUG):
		        	print "---->Water Empty Alarm!"
			activeAlarm = True
                        state.Is_Alarm_Water = True
                else:
                    state.Is_Alarm_Water = False
		

        	if (config.DEBUG):
			print "activeAlarm = ", activeAlarm		
		if (activeAlarm == True):
                    # hold for display
                    displayActiveAlarms()
                    state.Last_Event = "Alarm Active: "+time.strftime("%Y-%m-%d %H:%M:%S")
                    # release display
                else:
                    print "lastAlarm=", lastAlarm
                    print "activeAlarm=", activeAlarm
                    if (state.Alarm_Last_State != activeAlarm):
                        state.Last_Event = "Alarm Ended: "+time.strftime("%Y-%m-%d %H:%M:%S")
                    else:
                        state.Last_Event = "SGS Running: "+time.strftime("%Y-%m-%d %H:%M:%S")
               
                if (config.USEPUBNUB):
                    publishEventToPubNub()
                if (config.USEBLYNK):
                    updateBlynk.blynkEventUpdate()
		
                if (config.USEPUBNUB): 
	            publishAlarmToPubNub("")
                if (config.USEBLYNK):
                    updateBlynk.blynkAlarmUpdate()    
Beispiel #4
0
    if (config.USEBLYNK):
        updateBlynk.blynkInit()
	
	
    # start scheduler
    scheduler.start()
    print "-----------------"
    print "Scheduled Jobs" 
    print "-----------------"
    scheduler.print_jobs()
    print "-----------------"
    
    if (config.DEBUG):
        if (config.USEBLYNK):
            print "Blynk Status=", updateBlynk.blynkSGSAppOnline()
            updateBlynk.blynkAlarmUpdate();

    state.Last_Event = "SGS Started:"+time.strftime("%Y-%m-%d %H:%M:%S")

    if (config.USEPUBNUB):
        publishEventToPubNub()
    if (config.USEBLYNK):
        updateBlynk.blynkEventUpdate()

    if (config.OLED_Present):
        if (config.DEBUG):
             print "Attempt OLEDLock acquired"
        OLEDLock.acquire()
        if (config.DEBUG):
             print "OLEDLock acquired"
	# display logo