예제 #1
0
def sensorlistwithout():
    tablelisttemp = hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,
                                               "input",
                                               hardwaremod.HW_INFO_NAME)
    # exclude the event input
    inputeventlist = hardwaremod.searchdatalist(hardwaremod.HW_CTRL_CMD,
                                                "readinputpin",
                                                hardwaremod.HW_INFO_NAME)
    tablelist = []
    for element in tablelisttemp:
        if not element in inputeventlist:
            tablelist.append(element)
    return tablelist
예제 #2
0
def getelementlist():
	recordkey=hardwaremod.HW_INFO_IOTYPE
	recordvalue="output"	
	keytosearch=hardwaremod.HW_INFO_NAME
	datalist=hardwaremod.searchdatalist(recordkey,recordvalue,keytosearch)	
	excludewatercontrol=True
	if not excludewatercontrol:
		recordkey=hardwaremod.HW_FUNC_USEDFOR
		recordvalue="watercontrol"
		keytosearch=hardwaremod.HW_INFO_NAME
		removelist=hardwaremod.searchdatalist(recordkey,recordvalue,keytosearch)
		for element in removelist:
			datalist.remove(element)
	
	#print "elementlist= ",datalist
	return datalist
예제 #3
0
def sensorsysinfomatrix():
    # first row includes headers
    matrix = []
    row = []
    row.append("Name")
    row.append("Use")
    row.append("Unit")
    row.append("Average 24H")
    matrix.append(row)

    namelist = hardwaremod.searchdatalist(hardwaremod.HW_CTRL_CMD, "pulse",
                                          hardwaremod.HW_INFO_NAME)
    for name in namelist:
        row = []
        row.append(name)
        row.append(
            hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, name,
                                   hardwaremod.HW_FUNC_USEDFOR))
        row.append(
            hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, name,
                                   hardwaremod.HW_INFO_MEASUREUNIT))

        endtime = datetime.now()
        starttime = endtime - timedelta(days=1)
        data = []
        getActuatordbdata(name, data)
        isok, evaluateddata = EvaluateDataPeriod(
            data, starttime, endtime)  #set date interval for average

        row.append(str('%.1f' % (evaluateddata["sum"])))

        matrix.append(row)

    return matrix
예제 #4
0
def getelementlist():
	recordkey=hardwaremod.HW_INFO_IOTYPE
	recordvalue="output"	
	keytosearch=hardwaremod.HW_INFO_NAME
	datalist=hardwaremod.searchdatalist(recordkey,recordvalue,keytosearch)	
	excludewatercontrol=True
	if not excludewatercontrol:
		recordkey=hardwaremod.HW_FUNC_USEDFOR
		recordvalue="watercontrol"
		keytosearch=hardwaremod.HW_INFO_NAME
		removelist=hardwaremod.searchdatalist(recordkey,recordvalue,keytosearch)
		for element in removelist:
			datalist.remove(element)
	
	print "elementlist= ",datalist
	return datalist
예제 #5
0
def sensorsysinfomatrix():
	# first row includes headers
	matrix=[]
	row=[]
	row.append("Name")
	row.append("Use")
	row.append("Unit")
	row.append("Average 24H")	
	matrix.append(row)
	
	namelist=hardwaremod.searchdatalist(hardwaremod.HW_CTRL_CMD,"pulse",hardwaremod.HW_INFO_NAME)
	for name in namelist:
		row=[]
		row.append(name)
		row.append(hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,name,hardwaremod.HW_FUNC_USEDFOR))
		row.append(hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,name,hardwaremod.HW_INFO_MEASUREUNIT))

		endtime=datetime.now()
		starttime= endtime - timedelta(days=1)
		data=[]
		getActuatordbdata(name,data)
		evaluateddata=EvaluateDataPeriod(data,starttime,endtime)	#set date interval for average

		row.append(str('%.1f' % (evaluateddata["sum"]/1000)))

		matrix.append(row)
	
	return matrix
예제 #6
0
def getelementlist():
	recordkey=hardwaremod.HW_FUNC_USEDFOR
	recordvalue="fertilizercontrol"
	keytosearch=hardwaremod.HW_INFO_NAME
	datalist=hardwaremod.searchdatalist(recordkey,recordvalue,keytosearch)
	print "elementlist= ",datalist
	return datalist
예제 #7
0
def getelementlist():
    recordkey = hardwaremod.HW_FUNC_USEDFOR
    recordvalue = "mailcontrol"
    keytosearch = hardwaremod.HW_INFO_NAME
    datalist = hardwaremod.searchdatalist(recordkey, recordvalue, keytosearch)
    #print "elementlist= ",datalist
    return datalist
예제 #8
0
def sensorlisttriggertime():
	tablelist=hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,"input",hardwaremod.HW_INFO_NAME)
	timetriggerlist=[]
	for item in tablelist:
		timelist=hardwaremod.gettimedata(item)	
		theinterval=timelist[1] # minutes
		timetriggerlist.append(theinterval)
	return timetriggerlist
예제 #9
0
def sensorlisttriggertime():
	tablelist=hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,"input",hardwaremod.HW_INFO_NAME)
	timetriggerlist=[]
	for item in tablelist:
		timelist=hardwaremod.gettimedata(item)	
		theinterval=timelist[1] # minutes
		timetriggerlist.append(theinterval)
	return timetriggerlist
예제 #10
0
def sensorlist():
	tablelist=hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,"input",hardwaremod.HW_INFO_NAME)
	return tablelist
예제 #11
0
def mastercallback(fromscheduledtime=False):
    print("master callback")
    if fromscheduledtime:  # check if the time this function is called is the same as the expected time it should be called (solar/legal time might mess with it)
        logger.info(
            'Master scheduler call at scheduled local time, expected time %s',
            MASTERSCHEDULERTIME)
        thedateloc = datetime.now()
        timelist = hardwaremod.separatetimestringint(MASTERSCHEDULERTIME)
        masterschedtime = thedateloc.replace(hour=timelist[0],
                                             minute=timelist[1],
                                             second=timelist[2])
        secondsdifference = abs((thedateloc - masterschedtime).total_seconds())
        logger.info(
            'Master scheduler, difference between expected time and local time %d',
            secondsdifference)
        if secondsdifference > 300:  # more than 5 minutes
            logger.warning(
                'Master scheduler, difference between expected time and local time greater than 5 minutes, RESET MASTER SCHEDULER'
            )
            resetmastercallback()
            return
        # clean old data of the database (pastdays)
        logger.info('Remove data exceeding one year')
        pastdays = hardwaremod.toint(STOREPASTDAYS, 364)
        logger.info('Sensor Remove data exceeding one year')
        sensordbmod.RemoveSensorDataPeriod(pastdays)
        logger.info('Actuator Remove data exceeding one year')
        actuatordbmod.RemoveActuatorDataPeriod(pastdays)
        logger.info('Photo Remove data exceeding one year')
        hardwaremod.removephotodataperiod(pastdays)
    else:
        logger.info('Master scheduler call not coming from scheduler')

    logger.info('Scheduling main activities')

    # remove all jobs except masterscheduler
    #for job in SchedulerMod.sched.get_jobs():
    #	if job.name != "master":
    #		try:
    #			job.remove()
    #		except:
    #			logger.error('Not able to remove Job %s', job.name)

    # set the individual callback of the day

    logger.info('Start other scheduler activities - heartbeat')

    # info file dedicate call-back --------------------------------------------- (heartbeat)

    #this callback is used only for system status periodic check

    calltype = "periodic"
    global HEARTBEATINTERVAL
    interval = HEARTBEATINTERVAL
    timelist = [0, interval, 900]  # 20 indicates to start after 15 minutes
    callback = "heartbeat"
    argument = []

    setschedulercallback(calltype, timelist, argument, callback, callback)

    logger.info('Start other scheduler activities - sensor')

    # info file dedicate call-back --------------------------------------------- (sensor)

    hwnamelist = hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,
                                            "input", hardwaremod.HW_INFO_NAME)

    # GPIO input can be considered at all the aspects a binary input, therefor their stat collection are possible as any other input
    # the input should be time periodic and time should be more than one minute

    callback = "sensor"
    timeshift = 300  # after wifi activation because of possible clock adjustment
    shiftstep = 7  #seconds
    # IMPORTANT
    # the shiftstep is necessary to avoid thread collision which brings to sqlite3 db failure "database is locked"
    # this number is giving a limit to the sensor reading that should be higher than 1min
    for hwname in hwnamelist:
        calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, hwname,
                                          hardwaremod.HW_FUNC_SCHEDTYPE)
        if calltype == "periodic":  #check the input to be periodic
            timelist = hardwaremod.gettimedata(hwname)
            timelist[
                2] = timeshift  # avoid all the sensor thread to be called in the same time
            argument = []
            argument.append(hwname)
            setschedulercallback(calltype, timelist, argument, callback,
                                 hwname)
            timeshift = timeshift + shiftstep
        else:
            logger.warning(
                'The scheduler for the input %s is not set to PERIODIC, no log record of this input will be taken',
                hwname)

    logger.info('Start other scheduler activities - photo')

    #<------>
    # info file dedicate quinto call-back ----------------------------------(takephoto)
    usedfor = "photocontrol"
    callback = "photo"
    hwnamelist = hardwaremod.searchdatalist(hardwaremod.HW_FUNC_USEDFOR,
                                            usedfor, hardwaremod.HW_INFO_NAME)
    for hwname in hwnamelist:
        calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, hwname,
                                          hardwaremod.HW_FUNC_SCHEDTYPE)
        timelist = hardwaremod.gettimedata(hwname)
        argument = []
        argument.append(hwname)
        setschedulercallback(calltype, timelist, argument, callback, hwname)

    logger.info('Start other scheduler activities - mail')

    # info ne file dedicate quarto call-back ---------------------------------------(sendmail)

    usedfor = "mailcontrol"
    callback = "mail"
    hwnamelist = hardwaremod.searchdatalist(hardwaremod.HW_FUNC_USEDFOR,
                                            usedfor, hardwaremod.HW_INFO_NAME)
    for hwname in hwnamelist:
        calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, hwname,
                                          hardwaremod.HW_FUNC_SCHEDTYPE)
        timelist = hardwaremod.gettimedata(hwname)
        argument = []
        argument.append(hwname)
        setschedulercallback(calltype, timelist, argument, callback, hwname)

    # info ne file dedicate quinto call-back ---------------------------------------(lightcheck)

    # empty
    #<---->

    logger.info('Start other scheduler activities - pump')

    # info file dedicate call-back ------------------------------------------------ (waterpump)

    callback = "waterpump"

    #water schedule table
    paramlist = wateringdbmod.getparamlist()  # name of the months ordered
    elementlist = wateringdbmod.getelementlist(
    )  # pump ordered (based on "watercontrol" field)
    table = wateringdbmod.gettable(
        1
    )  # table, each row is a pump, each column is a month, value is watering time multiplieer
    table1 = wateringdbmod.gettable(
        0
    )  # table, each row is a pump, each column is a month, value is watering scheme
    table2 = wateringdbmod.gettable(
        2
    )  # table, each row is a pump, each column is a month, value is time delay

    #print paramlist
    #print elementlistly
    #print table
    paramlistdrop = advancedmod.getparamlist()  # day of the week
    elementlistdrop = advancedmod.getelementlist()  # drops ordered
    tabledrop = advancedmod.gettable(
    )  # table, each row is a schema number (drop number), each column is a weekday

    for pumpnumber in range(len(elementlist)):
        #print "number =",pumpnumber
        pumpname = elementlist[pumpnumber]
        todaydate = date.today()
        # Monday is 0 and Sunday is 6
        weekday = todaydate.weekday()
        month = todaydate.month

        try:
            waterschemanumber = table1[pumpnumber][month - 1]
            waterdropnumber = hardwaremod.toint(table[pumpnumber][month - 1],
                                                0)
            watertimedelaysec = hardwaremod.toint(
                table2[pumpnumber][month - 1], 0)
        except IndexError:
            print("EXCEPTION: index out of range")
            waterdropnumber = 0
            watertimedelaysec = 0

        if waterdropnumber > 0:
            #print " month  " , month, " drop  " , waterdropnumber
            calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,
                                              pumpname,
                                              hardwaremod.HW_FUNC_SCHEDTYPE)
            for todayevent in tabledrop[waterschemanumber - 1][weekday]:

                timelist = hardwaremod.separatetimestringint(todayevent[0])
                timelist[2] = timelist[2] + watertimedelaysec
                argument = []
                argument.append(pumpname)
                durationinseconds = hardwaremod.toint(todayevent[1],
                                                      0) * waterdropnumber
                argument.append(durationinseconds)
                for i in range(2, len(todayevent)):
                    argument.append(todayevent[i])
                if durationinseconds > 0:  #check if the duration in second is >0
                    setschedulercallback(calltype, timelist, argument,
                                         callback, pumpname)

    logger.info('Start other scheduler activities - doser')
    # info file dedicate call-back ------------------------------------------------ (pulsenutrient)

    callback = "doser"

    #fertilizer schedule table
    paramlist = fertilizerdbmod.getparamlist()  # name of the months ordered
    elementlist = fertilizerdbmod.getelementlist(
    )  # element with "fertilizercontrol field" ordered
    table = fertilizerdbmod.gettable(
        1
    )  # table, each row is a doser, each column is a month, value is number of times in a month
    table1 = fertilizerdbmod.gettable(
        0
    )  # table, each row is a doser, each column is a month, value is pulse seconds

    for dosernumber in range(len(elementlist)):
        #print "number =",dosernumber
        dosername = elementlist[dosernumber]
        calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, dosername,
                                          hardwaremod.HW_FUNC_SCHEDTYPE)
        todaydate = date.today()
        # Monday is 0 and Sunday is 6
        year = todaydate.year
        month = todaydate.month
        day = todaydate.day
        fertilizerpulsenumber = hardwaremod.toint(
            table[dosernumber][month - 1], 0)
        fertilizerpulsesecond = hardwaremod.toint(
            table1[dosernumber][month - 1], 0)
        if (fertilizerpulsenumber > 0) and (fertilizerpulsesecond > 0):
            themonthdays = 30  #approximate number of days in a month
            dayinterval = old_div(themonthdays, fertilizerpulsenumber)
            halfinterval = old_div((dayinterval + 1), 2)
            print("day=", day, " dayinterval=", dayinterval, " half=",
                  halfinterval)
            if ((day + int(halfinterval)) % int(dayinterval)) == 0:
                #timelist=hardwaremod.gettimedata("06:00:00")
                timelist = autofertilizermod.timelist(dosername)
                argument = []
                argument.append(dosername)
                argument.append(fertilizerpulsesecond)
                if (fertilizerpulsesecond
                    ) > 0:  #check if the duration in second is >0
                    setschedulercallback(calltype, timelist, argument,
                                         callback, dosername)

    logger.info('Start other scheduler activities - finish')
    return True
예제 #12
0
def gettablelist():
	tablelist=hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,"output",hardwaremod.HW_INFO_NAME)
	return tablelist
예제 #13
0
def gettablelist():
    tablelist = hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,
                                           "output", hardwaremod.HW_INFO_NAME)
    return tablelist
예제 #14
0
def sendallmail(mailtype, intromessage, bodytextlist=[]):
    usedfor = "mailcontrol"
    hwnamelist = hardwaremod.searchdatalist(hardwaremod.HW_FUNC_USEDFOR,
                                            usedfor, hardwaremod.HW_INFO_NAME)
    for hwname in hwnamelist:
        sendmail(hwname, mailtype, intromessage, bodytextlist)
예제 #15
0
def sendallmail(mailtype,intromessage,bodytextlist=[]):
	usedfor="mailcontrol"
	hwnamelist=hardwaremod.searchdatalist(hardwaremod.HW_FUNC_USEDFOR,usedfor,hardwaremod.HW_INFO_NAME)
	for hwname in hwnamelist:
		sendmail(hwname,mailtype,intromessage,bodytextlist)
예제 #16
0
# ///////////////// -- GLOBAL VARIABLES AND INIZIALIZATION --- //////////////////////////////////////////

global DBFILENAME
DBFILENAME = 'Actuatordb.db'
global TIMEFIELD
global DATAFIELD
TIMEFIELD = 'readtime'
DATAFIELD = 'data1'

# ///////////////// --- END GLOBAL VARIABLES ------

# ///////////////// -- MODULE INIZIALIZATION --- //////////////////////////////////////////

databasemod.init_db(DBFILENAME)
tablelist = hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE, "output",
                                       hardwaremod.HW_INFO_NAME)
databasemod.aligndbtable(DBFILENAME, tablelist)

# ///////////////// --- END init

#-- start DB utility--------////////////////////////////////////////////////////////////////////////////////////


def init_db():
    databasemod.init_db(DBFILENAME)


def gettablelist():
    tablelist = hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,
                                           "output", hardwaremod.HW_INFO_NAME)
    return tablelist
예제 #17
0
# ///////////////// -- GLOBAL VARIABLES AND INIZIALIZATION --- //////////////////////////////////////////

global DBFILENAME
DBFILENAME = 'Actuatordb.db'
global TIMEFIELD
global DATAFIELD
TIMEFIELD='readtime'
DATAFIELD='data1'

# ///////////////// --- END GLOBAL VARIABLES ------


# ///////////////// -- MODULE INIZIALIZATION --- //////////////////////////////////////////

databasemod.init_db(DBFILENAME)
tablelist=hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE,"output",hardwaremod.HW_INFO_NAME)
databasemod.aligndbtable(DBFILENAME, tablelist)

# ///////////////// --- END init




#-- start DB utility--------////////////////////////////////////////////////////////////////////////////////////	


def init_db():
	databasemod.init_db(DBFILENAME)


def gettablelist():
예제 #18
0
def mastercallback():
	
	# clean old data of the database (pastdays)
	logger.info('Remove data in exceed of one year')

	
	pastdays=364
	#sensordbmod.RemoveSensorDataPeriod(pastdays)
	logger.info('Sensor Remove data in exceed of one year')	
	#actuatordbmod.RemoveActuatorDataPeriod(pastdays)
	logger.info('Actuator Remove data in exceed of one year')
	#hardwaremod.removephotodataperiod(364)
	logger.info('Photo Remove data in exceed of one year')

	logger.info('Start other scheduler activities')
	
	# remove all jobs except masterscheduler
	#for job in SchedulerMod.sched.get_jobs():
	#	if job.name != "master":
	#		try:
	#			job.remove()	
	#		except:
	#			logger.error('Not able to remove Job %s', job.name)

	# set the individual callback of the day
	
	# info file dedicate call-back --------------------------------------------- (heartbeat)	
	
	#this callback is used only for system status periodic check 
	
	calltype="periodic"
	global HEARTBEATINTERVAL
	interval=HEARTBEATINTERVAL
	timelist=[0,interval,900] # 900 indicates to start after 15 minutes
	callback="heartbeat"
	argument=[]
	
	setschedulercallback(calltype,timelist,argument,callback,callback)
	
	logger.info('Start other scheduler activities - sensor')
	
	# info file dedicate call-back --------------------------------------------- (sensor)
	
	hwnamelist=sensordbmod.gettablelist()
	callback="sensor"
	timeshift=300
	shiftstep=5 #seconds	
	# IMPORTANT
	# the shiftstep is necessary to avoid thread collision which brings to sqlite3 db failure "database is locked" 
	# this number is giving a limit to the sensor reading that should be higher than 1min
	for hwname in hwnamelist:
		calltype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,hwname,hardwaremod.HW_FUNC_SCHEDTYPE)
		timelist=hardwaremod.gettimedata(hwname)
		timelist[2]=timeshift # avoid all the sensor thread to be called in the same time
		argument=[]
		argument.append(hwname)
		setschedulercallback(calltype,timelist,argument,callback,hwname)
		timeshift=timeshift+shiftstep

	logger.info('Start other scheduler activities - photo')

	#<------>
	# info file dedicate quinto call-back ----------------------------------(takephoto)
	usedfor="photocontrol"
	callback="photo"	
	hwnamelist=hardwaremod.searchdatalist(hardwaremod.HW_FUNC_USEDFOR,usedfor,hardwaremod.HW_INFO_NAME)
	for hwname in hwnamelist:
		calltype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,hwname,hardwaremod.HW_FUNC_SCHEDTYPE)
		timelist=hardwaremod.gettimedata(hwname)
		argument=[]
		argument.append(hwname)
		setschedulercallback(calltype,timelist,argument,callback,hwname)

	logger.info('Start other scheduler activities - mail')

	# info ne file dedicate quarto call-back ---------------------------------------(sendmail)
	
	usedfor="mailcontrol"
	callback="mail"	
	hwnamelist=hardwaremod.searchdatalist(hardwaremod.HW_FUNC_USEDFOR,usedfor,hardwaremod.HW_INFO_NAME)
	for hwname in hwnamelist:
		calltype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,hwname,hardwaremod.HW_FUNC_SCHEDTYPE)
		timelist=hardwaremod.gettimedata(hwname)
		argument=[]
		argument.append(hwname)
		setschedulercallback(calltype,timelist,argument,callback,hwname)



	# info ne file dedicate quinto call-back ---------------------------------------(lightcheck)

	# empty
	#<---->
	
	logger.info('Start other scheduler activities - pump')
	
	# info file dedicate call-back ------------------------------------------------ (waterpump)
	

	callback="waterpump"
	
	#water schedule table
	paramlist= wateringdbmod.getparamlist()  # name of the months ordered
	elementlist= wateringdbmod.getelementlist()  # pump ordered (based on "watercontrol" field)
	table=wateringdbmod.gettable(1)# table, each row is a pump, each column is a month, value is watering time multiplieer
	table1=wateringdbmod.gettable(0)# table, each row is a pump, each column is a month, value is watering scheme
	table2=wateringdbmod.gettable(2)# table, each row is a pump, each column is a month, value is time delay 	
	
	#print paramlist
	#print elementlistly
	#print table
	paramlistdrop= advancedmod.getparamlist() # day of the week
	elementlistdrop= advancedmod.getelementlist() # drops ordered
	tabledrop=advancedmod.gettable() # table, each row is a schema number (drop number), each column is a weekday

	for pumpnumber in range(len(elementlist)):
		#print "number =",pumpnumber
		pumpname=elementlist[pumpnumber]
		todaydate = date.today()
		# Monday is 0 and Sunday is 6
		weekday = todaydate.weekday()
		month = todaydate.month	
		
		try:					
			waterschemanumber=table1[pumpnumber][month-1]
			waterdropnumber=hardwaremod.toint(table[pumpnumber][month-1],0)
			watertimedelaysec=hardwaremod.toint(table2[pumpnumber][month-1],0)
		except IndexError:
			print "EXCEPTION: index out of range" 		
			waterdropnumber=0
			watertimedelaysec=0		
		
		if waterdropnumber>0:			
			#print " month  " , month, " drop  " , waterdropnumber
			calltype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,pumpname,hardwaremod.HW_FUNC_SCHEDTYPE)
			for todayevent in tabledrop[waterschemanumber-1][weekday]:
				
				timelist=hardwaremod.separatetimestringint(todayevent[0])
				timelist[2]=timelist[2]+watertimedelaysec
				argument=[]
				argument.append(pumpname)
				durationinseconds=hardwaremod.toint(todayevent[1],0)*waterdropnumber
				argument.append(durationinseconds)				
				for i in range(2,len(todayevent)):
						argument.append(todayevent[i])
				if durationinseconds>0: #check if the duration in second is >0
					setschedulercallback(calltype,timelist,argument,callback,pumpname)


	logger.info('Start other scheduler activities - doser')
	# info file dedicate call-back ------------------------------------------------ (pulsenutrient)
	

	callback="doser"

	
	#fertilizer schedule table
	paramlist= fertilizerdbmod.getparamlist()  # name of the months ordered
	elementlist= fertilizerdbmod.getelementlist()  # element with "fertilizercontrol field" ordered 
	table=fertilizerdbmod.gettable(1)# table, each row is a doser, each column is a month, value is number of times in a month	
	table1=fertilizerdbmod.gettable(0)# table, each row is a doser, each column is a month, value is pulse seconds	

	for dosernumber in range(len(elementlist)):
		#print "number =",dosernumber
		dosername=elementlist[dosernumber]
		calltype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,dosername,hardwaremod.HW_FUNC_SCHEDTYPE)
		todaydate = date.today()
		# Monday is 0 and Sunday is 6
		year = todaydate.year
		month = todaydate.month	
		day = todaydate.day
		fertilizerpulsenumber=hardwaremod.toint(table[dosernumber][month-1],0)
		fertilizerpulsesecond=hardwaremod.toint(table1[dosernumber][month-1],0)
		if (fertilizerpulsenumber>0) and (fertilizerpulsesecond>0):			
			themonthdays=30 #approximate number of days in a month
			dayinterval=themonthdays/fertilizerpulsenumber
			halfinterval=(dayinterval+1)/2
			print "day=" , day , " dayinterval=", dayinterval, " half=", halfinterval		
			if ((day+int(halfinterval)) % int(dayinterval)) == 0:				
				#timelist=hardwaremod.gettimedata("06:00:00")
				timelist=autofertilizermod.timelist(dosername)
				argument=[]
				argument.append(dosername)
				argument.append(fertilizerpulsesecond)
				if (fertilizerpulsesecond)>0: #check if the duration in second is >0
					setschedulercallback(calltype,timelist,argument,callback,dosername)
					
	logger.info('Start other scheduler activities - finish')
	return True
예제 #19
0
def mastercallback():

    # clean old data of the database (pastdays)

    pastdays = 364
    sensordbmod.RemoveSensorDataPeriod(pastdays)
    actuatordbmod.RemoveActuatorDataPeriod(pastdays)
    hardwaremod.removephotodataperiod(364)

    # remove all jobs except masterscheduler
    for job in SchedulerMod.sched.get_jobs():
        if job.name != "master":
            try:
                job.remove()
            except:
                logger.error('Not able to remove Job %s', job.name)

    # set the individual callback of the day

    # info file dedicate call-back --------------------------------------------- (heartbeat)

    #this callback is used only for system status periodic check

    calltype = "periodic"
    global HEARTBEATINTERVAL
    interval = HEARTBEATINTERVAL
    timelist = [0, interval, 900]  # 900 indicates to start after 15 minutes
    callback = "heartbeat"
    argument = []

    setschedulercallback(calltype, timelist, argument, callback, callback)

    # info file dedicate call-back --------------------------------------------- (sensor)

    hwnamelist = sensordbmod.gettablelist()
    callback = "sensor"
    timeshift = 300
    shiftstep = 2  #seconds
    for hwname in hwnamelist:
        calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, hwname,
                                          hardwaremod.HW_FUNC_SCHEDTYPE)
        timelist = hardwaremod.gettimedata(hwname)
        timelist[2] = timelist[
            2] + timeshift  # avoid all the sensor thread to be called in the same time
        argument = []
        argument.append(hwname)
        setschedulercallback(calltype, timelist, argument, callback, hwname)
        timeshift = timeshift + shiftstep

    #<------>
    # info file dedicate quinto call-back ----------------------------------(takephoto)
    usedfor = "photocontrol"
    callback = "photo"
    hwnamelist = hardwaremod.searchdatalist(hardwaremod.HW_FUNC_USEDFOR,
                                            usedfor, hardwaremod.HW_INFO_NAME)
    for hwname in hwnamelist:
        calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, hwname,
                                          hardwaremod.HW_FUNC_SCHEDTYPE)
        timelist = hardwaremod.gettimedata(hwname)
        argument = []
        argument.append(hwname)
        setschedulercallback(calltype, timelist, argument, callback, hwname)

    # info ne file dedicate quarto call-back ---------------------------------------(sendmail)

    usedfor = "mailcontrol"
    callback = "mail"
    hwnamelist = hardwaremod.searchdatalist(hardwaremod.HW_FUNC_USEDFOR,
                                            usedfor, hardwaremod.HW_INFO_NAME)
    for hwname in hwnamelist:
        calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, hwname,
                                          hardwaremod.HW_FUNC_SCHEDTYPE)
        timelist = hardwaremod.gettimedata(hwname)
        argument = []
        argument.append(hwname)
        setschedulercallback(calltype, timelist, argument, callback, hwname)

    # info ne file dedicate quinto call-back ---------------------------------------(lightcheck)

    # empty
    #<---->

    # info file dedicate call-back ------------------------------------------------ (waterpump)

    callback = "waterpump"

    #water schedule table
    paramlist = wateringdbmod.getparamlist()  # name of the months ordered
    elementlist = wateringdbmod.getelementlist(
    )  # pump ordered (based on "watercontrol" field)
    table = wateringdbmod.gettable(
        1
    )  # table, each row is a pump, each column is a month, value is watering time multiplieer
    table1 = wateringdbmod.gettable(
        0
    )  # table, each row is a pump, each column is a month, value is watering scheme
    table2 = wateringdbmod.gettable(
        2
    )  # table, each row is a pump, each column is a month, value is time delay

    #print paramlist
    #print elementlistly
    #print table
    paramlistdrop = advancedmod.getparamlist()  # day of the week
    elementlistdrop = advancedmod.getelementlist()  # drops ordered
    tabledrop = advancedmod.gettable(
    )  # table, each row is a schema number (drop number), each column is a weekday

    for pumpnumber in range(len(elementlist)):
        #print "number =",pumpnumber
        pumpname = elementlist[pumpnumber]
        todaydate = date.today()
        # Monday is 0 and Sunday is 6
        weekday = todaydate.weekday()
        month = todaydate.month

        try:
            waterschemanumber = table1[pumpnumber][month - 1]
            waterdropnumber = hardwaremod.toint(table[pumpnumber][month - 1],
                                                0)
            watertimedelaysec = hardwaremod.toint(
                table2[pumpnumber][month - 1], 0)
        except IndexError:
            print "EXCEPTION: index out of range"
            waterdropnumber = 0
            watertimedelaysec = 0

        if waterdropnumber > 0:
            #print " month  " , month, " drop  " , waterdropnumber
            calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,
                                              pumpname,
                                              hardwaremod.HW_FUNC_SCHEDTYPE)
            for todayevent in tabledrop[waterschemanumber - 1][weekday]:

                timelist = hardwaremod.separatetimestringint(todayevent[0])
                timelist[2] = timelist[2] + watertimedelaysec
                argument = []
                argument.append(pumpname)
                durationinseconds = hardwaremod.toint(todayevent[1],
                                                      0) * waterdropnumber
                argument.append(durationinseconds)
                for i in range(2, len(todayevent)):
                    argument.append(todayevent[i])
                if durationinseconds > 0:  #check if the duration in second is >0
                    setschedulercallback(calltype, timelist, argument,
                                         callback, pumpname)

    # info file dedicate call-back ------------------------------------------------ (pulsenutrient)

    callback = "doser"

    #fertilizer schedule table
    paramlist = fertilizerdbmod.getparamlist()  # name of the months ordered
    elementlist = fertilizerdbmod.getelementlist(
    )  # element with "fertilizercontrol field" ordered
    table = fertilizerdbmod.gettable(
        1
    )  # table, each row is a doser, each column is a month, value is number of times in a month
    table1 = fertilizerdbmod.gettable(
        0
    )  # table, each row is a doser, each column is a month, value is pulse seconds

    for dosernumber in range(len(elementlist)):
        #print "number =",dosernumber
        dosername = elementlist[dosernumber]
        calltype = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, dosername,
                                          hardwaremod.HW_FUNC_SCHEDTYPE)
        todaydate = date.today()
        # Monday is 0 and Sunday is 6
        year = todaydate.year
        month = todaydate.month
        day = todaydate.day
        fertilizerpulsenumber = hardwaremod.toint(
            table[dosernumber][month - 1], 0)
        fertilizerpulsesecond = hardwaremod.toint(
            table1[dosernumber][month - 1], 0)
        if (fertilizerpulsenumber > 0) and (fertilizerpulsesecond > 0):
            themonthdays = 30  #approximate number of days in a month
            dayinterval = themonthdays / fertilizerpulsenumber
            halfinterval = (dayinterval + 1) / 2
            print "day=", day, " dayinterval=", dayinterval, " half=", halfinterval
            if ((day + int(halfinterval)) % int(dayinterval)) == 0:
                timelist = hardwaremod.gettimedata("06:00:00")
                argument = []
                argument.append(dosername)
                argument.append(fertilizerpulsesecond)
                if (fertilizerpulsesecond
                    ) > 0:  #check if the duration in second is >0
                    setschedulercallback(calltype, timelist, argument,
                                         callback, dosername)
예제 #20
0
def sensorlist():
    tablelist = hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE, "input",
                                           hardwaremod.HW_INFO_NAME)
    return tablelist
예제 #21
0
def sensorlist():
    #tablelist=hardwaremod.searchdatalist2keys(hardwaremod.HW_INFO_IOTYPE,"input", hardwaremod.HW_CTRL_CMD, "readinputpin" ,hardwaremod.HW_INFO_NAME)
    tablelist = hardwaremod.searchdatalist(hardwaremod.HW_INFO_IOTYPE, "input",
                                           hardwaremod.HW_INFO_NAME)
    return tablelist