コード例 #1
0
 def __init__(self):
     self.logMessage = LogMessage()
     self.const = Constant()
     self.processSensorData = ProcessSensorReading()
     self.processConfigFile = ProcessConfigFile()
     self.GPIOPins = GPIOPin()
     self.bus = smbus.SMBus(1)
コード例 #2
0
 def __init__(self):
     self.logMessage = LogMessage()
     self.const = Constant()
     self.sim = SIMOperations()
     self.messages = Message()
     self.processConfigFile = ProcessConfigFile()
     self.processSensorData = ProcessSensorReading()
     self.bus = smbus.SMBus(1)
コード例 #3
0
class DisplayPeriodicMessage:

    logMessage = ''
    const = ''
    processSensorData = ''
    lcd = ''

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.processSensorData = ProcessSensorReading()
        if self.const.live:
            self.lcd = RPILCD()

    def run(self):
        try:
            if self.processSensorData.checkConfigFileExist():
                while True:
                    data = self.processSensorData.getSensorData()

                    currentTime = time.strftime("%d.%m.%Y %H:%M:%S")
                    self.displayOnLcd('ILLUMINUM \nGREEN HOUSE TECH')
                    time.sleep(5)
                    self.displayOnLcd('TAITA FARM')
                    time.sleep(5)
                    self.displayOnLcd('SMART MOBILE \nFARMING')
                    time.sleep(5)
                    self.displayOnLcd('TEMP : ' + str(data[0]) + ' CELSIUS')
                    time.sleep(3)
                    self.displayOnLcd('HUM : ' + str(data[1]) + ' %')
                    time.sleep(3)
                    self.displayOnLcd('SOIL MOISTURE \n ' + str(data[2]) +
                                      ' %')
                    time.sleep(3)
                    self.displayOnLcd('IRRIGATION : ' + str(data[5]))
                    time.sleep(3)
                    self.displayOnLcd('WATER USED : ' + str(data[3]))
                    time.sleep(3)
                    self.displayOnLcd('DATE : ' + str(currentTime))
                    time.sleep(3)
            else:
                self.logMessage.log(
                    'Invalid configuration data / No file found - Display Periodic Message'
                )
                self.run()
        except:
            self.logMessage.log('Error in displaying periodic messages')
            self.run()

    # display text on LCD screen
    def displayOnLcd(self, text):
        if self.const.live:
            self.lcd.clear()
            time.sleep(1)
            self.lcd.message(text)
        else:
            print text
コード例 #4
0
 def __init__(self):
     self.logMessage = LogMessage()
     self.const = Constant()
     self.sim = SIMOperations()
     self.messages = Message()
     self.processConfigFile = ProcessConfigFile()
     self.messageFilter = MessageFilter()
     self.GPIOPins = GPIOPin()
     if self.const.live:
         self.lcd = RPILCD()
コード例 #5
0
class DisplayPeriodicMessage:

    logMessage = ''
    const = ''
    processSensorData = ''
    lcd = ''

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.processSensorData = ProcessSensorReading()
        if self.const.live:
            self.lcd = RPILCD()

    def run(self):
        try:
            if self.processSensorData.checkConfigFileExist():
                while True:
                    data = self.processSensorData.getSensorData()

                    currentTime = time.strftime("%d.%m.%Y %H:%M:%S")
                    self.displayOnLcd('ILLUMINUM \nGREEN HOUSE TECH')
                    time.sleep(5)
                    self.displayOnLcd('TAITA FARM')
                    time.sleep(5)
                    self.displayOnLcd('SMART MOBILE \nFARMING')
                    time.sleep(5)
                    self.displayOnLcd('TEMP : ' + str(data[0]) + ' CELSIUS')
                    time.sleep(3)
                    self.displayOnLcd('HUM : ' + str(data[1]) + ' %')
                    time.sleep(3)
                    self.displayOnLcd('SOIL MOISTURE \n ' + str(data[2]) + ' %')
                    time.sleep(3)
                    self.displayOnLcd('IRRIGATION : ' + str(data[5]))
                    time.sleep(3)
                    self.displayOnLcd('WATER USED : ' + str(data[3]))
                    time.sleep(3)
                    self.displayOnLcd('DATE : ' + str(currentTime))
                    time.sleep(3)
            else:
                self.logMessage.log('Invalid configuration data / No file found - Display Periodic Message')
                self.run()
        except:
            self.logMessage.log('Error in displaying periodic messages')
            self.run()

    # display text on LCD screen
    def displayOnLcd(self, text):
        if self.const.live:
            self.lcd.clear()
            time.sleep(1)
            self.lcd.message(text)
        else:
            print text
コード例 #6
0
 def __init__(self):
     self.logMessage = LogMessage()
     self.const = Constant()
     self.sim = SIMOperations()
     self.messages = Message()
     self.processConfigFile = ProcessConfigFile()
     self.processSensorData = ProcessSensorReading()
     self.bus = smbus.SMBus(1)
コード例 #7
0
 def __init__(self):
     self.logMessage = LogMessage()
     self.const = Constant()
     self.sim = SIMOperations()
     self.messages = Message()
     self.processConfigFile = ProcessConfigFile()
     self.messageFilter = MessageFilter()
     self.GPIOPins = GPIOPin()
     if self.const.live:
         self.lcd = RPILCD()
コード例 #8
0
class InstantAction:

    logMessage = ''
    const = ''
    sim = ''
    messages = ''
    messageFilter = ''
    processConfigFile = ''
    processSensorData = ''

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.sim = SIMOperations()
        self.messages = Message()
        self.processConfigFile = ProcessConfigFile()
        self.processSensorData = ProcessSensorReading()
        self.messageFilter = MessageFilter()

    def run(self):
        try:
            if self.processConfigFile.checkValuesInConfigFile():
                if self.sim.checkSIMCard():
                    while True:
                        messages = self.sim.readUnreadMessages()
                        if self.messageFilter.readCheckBalance(messages):
                            self.sim.sendSMSCheckBalance()
                            time.sleep(30)
                            lastReadMessage = self.sim.readFirstUnreadMessages(
                            )
                            message = self.messageFilter.readBalanceMessage(
                                lastReadMessage)
                            self.sim.sendSMS(message)
                            time.sleep(5)
                            self.sim.deleteReadMessages()
                        elif self.messageFilter.readUsedWater(messages):
                            # get used water
                            waterFlow = self.processSensorData.getWaterUsed()
                            currentDate = time.strftime("%d.%m.%Y,%H:%M")
                            message = 'Dear Digital Farmer, Water used is %s litres as of %s' % (
                                str(waterFlow), str(currentDate))
                            self.sim.sendSMS(message)
                            time.sleep(5)
                            self.sim.deleteReadMessages()
                else:
                    self.logMessage.log(
                        'No SIM Card detected - Instant Action')
                    self.run()
            else:
                self.logMessage.log(
                    'Invalid configuration data / No file found - Instant Action'
                )
                self.run()
        except:
            self.logMessage.log('Error in Instant Action')
            time.sleep(60)
            self.run()
コード例 #9
0
class InstantAction:

    logMessage = ''
    const = ''
    sim = ''
    messages = ''
    messageFilter = ''
    processConfigFile = ''
    processSensorData = ''

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.sim = SIMOperations()
        self.messages = Message()
        self.processConfigFile = ProcessConfigFile()
        self.processSensorData = ProcessSensorReading()
        self.messageFilter = MessageFilter()

    def run(self):
        try:
            if self.processConfigFile.checkValuesInConfigFile():
                if self.sim.checkSIMCard():
                    while True:
                        messages = self.sim.readUnreadMessages()
                        if self.messageFilter.readCheckBalance(messages):
                            self.sim.sendSMSCheckBalance()
                            time.sleep(30)
                            lastReadMessage = self.sim.readFirstUnreadMessages()
                            message = self.messageFilter.readBalanceMessage(lastReadMessage)
                            self.sim.sendSMS(message)
                            time.sleep(5)
                            self.sim.deleteReadMessages()
                        elif self.messageFilter.readUsedWater(messages):
                            # get used water
                            waterFlow = self.processSensorData.getWaterUsed()
                            currentDate = time.strftime("%d.%m.%Y,%H:%M")
                            message = 'Dear Digital Farmer, Water used is %s litres as of %s' % (str(waterFlow), str(currentDate))
                            self.sim.sendSMS(message)
                            time.sleep(5)
                            self.sim.deleteReadMessages()
                else:
                    self.logMessage.log('No SIM Card detected - Instant Action')
                    self.run()
            else:
                self.logMessage.log('Invalid configuration data / No file found - Instant Action')
                self.run()
        except:
            self.logMessage.log('Error in Instant Action')
            time.sleep(60)
            self.run()
コード例 #10
0
class Configuration:

    logMessage = ''
    const = ''
    sim = ''
    messages = ''
    messageFilter = ''
    processConfigFile = ''
    lcd = ''
    GPIOPins = ''

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.sim = SIMOperations()
        self.messages = Message()
        self.processConfigFile = ProcessConfigFile()
        self.messageFilter = MessageFilter()
        self.GPIOPins = GPIOPin()
        if self.const.live:
            self.lcd = RPILCD()

    def run(self):
        try:
            if not self.sim.checkSIMCard():
                self.logMessage.log(self.messages.ERROR_INSERT_SIM)		
                self.displayOnLcd('ERROR100.')
                time.sleep(1)
                self.displayOnLcd('Please insert\nyour SIM')
                time.sleep(1)
                self.GPIOPins.ErrorLED()
            else:		
                if not self.processConfigFile.checkValuesInConfigFile():
                    self.logMessage.log(self.messages.ERROR_CONFIG)
                    self.displayOnLcd('Hello \nDigital farmer')
                    time.sleep(3)
                    self.displayOnLcd('ILLUMINUM \nGREEN HOUSE TECH')
                    time.sleep(3)
                    self.displayOnLcd('ERROR101')
                    time.sleep(1)
                    self.displayOnLcd('Kindly\nconfigure')
                    time.sleep(1)
                    self.displayOnLcd('your system')
                    self.GPIOPins.ErrorLED()
                    self.setConfigData()
        except:
            self.logMessage.log('Error in main configuration section')
            pass

    def setConfigData(self):
        try:
            setContactNumber = False
            setLowerLimit = False
            setUpperLimit = False
            while True:
                if setContactNumber and setLowerLimit and setUpperLimit:
                    self.GPIOPins.FullyFunctionalLED()
                    break

                if not setContactNumber:
                    if self.setContactNumberToConfigFile():
                        setContactNumber = True
                        phone = self.processConfigFile.readPhoneNumber()
                        message = self.messages.SMS_SET_MOBILE % (str(phone))
                        self.sim.sendSMS(message)
                        time.sleep(1)
                        # self.sim.sendSMS(self.messages.SMS_SETUP_LOWER_LIMIT)
                        time.sleep(1)
                        self.sim.sendSMS('Kindly set up your Lower limit Setting for Soil Moisture')
                        time.sleep(1)
                        self.sim.deleteReadMessages()
                        time.sleep(1)

                elif setContactNumber and not setLowerLimit and not setUpperLimit:
                    if self.setLowerLimitToConfigFile():
                        setLowerLimit = True
                        lowerLimit = self.processConfigFile.readLowerLimit()
                        message = self.messages.SMS_CONFIRM_LOWER_LIMIT % (str(lowerLimit))
                        self.sim.sendSMS(message)
                        time.sleep(2)
                        # self.sim.sendSMS(self.messages.SMS_SETUP_UPPER_LIMIT)
                        self.sim.sendSMS('Kindly set up your Upper limit')
                        time.sleep(2)
                        self.sim.deleteReadMessages()
                        time.sleep(1)

                elif setLowerLimit and setContactNumber:
                    if setLowerLimit and self.setUpperLimitToConfigFile():
                        setUpperLimit = True
                        upperLimit = self.processConfigFile.readUpperLimit()
                        message = self.messages.SMS_CONFIRM_UPPER_LIMIT % (str(upperLimit))
                        self.sim.sendSMS(message)
                        time.sleep(2)
                        # self.sim.sendSMS(self.messages.SMS_CONGRATULATIONS)
                        self.sim.sendSMS('CONGRATULATIONS! You have now set up your Smart Mobile Farm')
                        time.sleep(1)
                        self.sim.deleteReadMessages()
                        time.sleep(1)
        except:
            self.logMessage.log('Error in setting configuration')
            pass
        return True

    def setContactNumberToConfigFile(self):
        status = False
        try:
            messages = self.sim.readUnreadMessages()
            contactNumber = self.messageFilter.readContactNumber(messages)
            if contactNumber:
                self.logMessage.log('Contact number found : ' + str(contactNumber))
                self.processConfigFile.updateContactNumber(contactNumber)
                status = True
        except:
            self.logMessage.log('Error in setting contact number')
            pass
        return status

    def setLowerLimitToConfigFile(self):
        status = False
        try:
            messages = self.sim.readUnreadMessages()
            lowerLimit = self.messageFilter.readLowerLimit(messages)
            if lowerLimit:
                self.logMessage.log('lower limit found : ' + str(lowerLimit))
                self.processConfigFile.updateLowerLimitNumber(str(lowerLimit))
                status = True
        except:
            self.logMessage.log('Error in setting lower limit')
            pass
        return status

    def setUpperLimitToConfigFile(self):
        status = False
        try:
            messages = self.sim.readUnreadMessages()
            upperLimit = self.messageFilter.readUpperLimit(messages)
            if upperLimit:
                self.logMessage.log('upper limit found : ' + str(upperLimit))
                self.processConfigFile.updateUpperLimitNumber(str(upperLimit))
                status = True
        except:
            self.logMessage.log('Error in setting upper limit')
            pass
        return status

    # display text on LCD screen
    def displayOnLcd(self, text):
        if self.const.live:
            self.lcd.clear()
            self.lcd.message(text)
        else:
            print text
コード例 #11
0
class Configuration:

    logMessage = ''
    const = ''
    sim = ''
    messages = ''
    messageFilter = ''
    processConfigFile = ''
    lcd = ''
    GPIOPins = ''

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.sim = SIMOperations()
        self.messages = Message()
        self.processConfigFile = ProcessConfigFile()
        self.messageFilter = MessageFilter()
        self.GPIOPins = GPIOPin()
        if self.const.live:
            self.lcd = RPILCD()

    def run(self):
        try:
            if not self.sim.checkSIMCard():
                self.logMessage.log(self.messages.ERROR_INSERT_SIM)
                self.displayOnLcd('ERROR100.')
                time.sleep(1)
                self.displayOnLcd('Please insert\nyour SIM')
                time.sleep(1)
                self.GPIOPins.ErrorLED()
            else:
                if not self.processConfigFile.checkValuesInConfigFile():
                    self.logMessage.log(self.messages.ERROR_CONFIG)
                    self.displayOnLcd('Hello \nDigital farmer')
                    time.sleep(3)
                    self.displayOnLcd('ILLUMINUM \nGREEN HOUSE TECH')
                    time.sleep(3)
                    self.displayOnLcd('ERROR101')
                    time.sleep(1)
                    self.displayOnLcd('Kindly\nconfigure')
                    time.sleep(1)
                    self.displayOnLcd('your system')
                    self.GPIOPins.ErrorLED()
                    self.setConfigData()
        except:
            self.logMessage.log('Error in main configuration section')
            pass

    def setConfigData(self):
        try:
            setContactNumber = False
            setLowerLimit = False
            setUpperLimit = False
            while True:
                if setContactNumber and setLowerLimit and setUpperLimit:
                    self.GPIOPins.FullyFunctionalLED()
                    break

                if not setContactNumber:
                    if self.setContactNumberToConfigFile():
                        setContactNumber = True
                        phone = self.processConfigFile.readPhoneNumber()
                        message = self.messages.SMS_SET_MOBILE % (str(phone))
                        self.sim.sendSMS(message)
                        time.sleep(1)
                        # self.sim.sendSMS(self.messages.SMS_SETUP_LOWER_LIMIT)
                        time.sleep(1)
                        self.sim.sendSMS(
                            'Kindly set up your Lower limit Setting for Soil Moisture'
                        )
                        time.sleep(1)
                        self.sim.deleteReadMessages()
                        time.sleep(1)

                elif setContactNumber and not setLowerLimit and not setUpperLimit:
                    if self.setLowerLimitToConfigFile():
                        setLowerLimit = True
                        lowerLimit = self.processConfigFile.readLowerLimit()
                        message = self.messages.SMS_CONFIRM_LOWER_LIMIT % (
                            str(lowerLimit))
                        self.sim.sendSMS(message)
                        time.sleep(2)
                        # self.sim.sendSMS(self.messages.SMS_SETUP_UPPER_LIMIT)
                        self.sim.sendSMS('Kindly set up your Upper limit')
                        time.sleep(2)
                        self.sim.deleteReadMessages()
                        time.sleep(1)

                elif setLowerLimit and setContactNumber:
                    if setLowerLimit and self.setUpperLimitToConfigFile():
                        setUpperLimit = True
                        upperLimit = self.processConfigFile.readUpperLimit()
                        message = self.messages.SMS_CONFIRM_UPPER_LIMIT % (
                            str(upperLimit))
                        self.sim.sendSMS(message)
                        time.sleep(2)
                        # self.sim.sendSMS(self.messages.SMS_CONGRATULATIONS)
                        self.sim.sendSMS(
                            'CONGRATULATIONS! You have now set up your Smart Mobile Farm'
                        )
                        time.sleep(1)
                        self.sim.deleteReadMessages()
                        time.sleep(1)
        except:
            self.logMessage.log('Error in setting configuration')
            pass
        return True

    def setContactNumberToConfigFile(self):
        status = False
        try:
            messages = self.sim.readUnreadMessages()
            contactNumber = self.messageFilter.readContactNumber(messages)
            if contactNumber:
                self.logMessage.log('Contact number found : ' +
                                    str(contactNumber))
                self.processConfigFile.updateContactNumber(contactNumber)
                status = True
        except:
            self.logMessage.log('Error in setting contact number')
            pass
        return status

    def setLowerLimitToConfigFile(self):
        status = False
        try:
            messages = self.sim.readUnreadMessages()
            lowerLimit = self.messageFilter.readLowerLimit(messages)
            if lowerLimit:
                self.logMessage.log('lower limit found : ' + str(lowerLimit))
                self.processConfigFile.updateLowerLimitNumber(str(lowerLimit))
                status = True
        except:
            self.logMessage.log('Error in setting lower limit')
            pass
        return status

    def setUpperLimitToConfigFile(self):
        status = False
        try:
            messages = self.sim.readUnreadMessages()
            upperLimit = self.messageFilter.readUpperLimit(messages)
            if upperLimit:
                self.logMessage.log('upper limit found : ' + str(upperLimit))
                self.processConfigFile.updateUpperLimitNumber(str(upperLimit))
                status = True
        except:
            self.logMessage.log('Error in setting upper limit')
            pass
        return status

    # display text on LCD screen
    def displayOnLcd(self, text):
        if self.const.live:
            self.lcd.clear()
            self.lcd.message(text)
        else:
            print text
コード例 #12
0
 def __init__(self):
     self.logMessage = LogMessage()
     self.const = Constant()
     self.processSensorData = ProcessSensorReading()
     if self.const.live:
         self.lcd = RPILCD()
コード例 #13
0
 def __init__(self):
     self.logMessage = LogMessage()
     self.const = Constant()
     self.processSensorData = ProcessSensorReading()
     if self.const.live:
         self.lcd = RPILCD()
コード例 #14
0
class DailyReport:

    logMessage = ''
    const = ''
    sim = ''
    messages = ''
    processSensorData = ''
    processConfigFile = ''
    bus = ''
    address = 0x04

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.sim = SIMOperations()
        self.messages = Message()
        self.processConfigFile = ProcessConfigFile()
        self.processSensorData = ProcessSensorReading()
        self.bus = smbus.SMBus(1)

    def run(self):
        try:
            if self.sim.checkSIMCard():
                if self.processConfigFile.checkValuesInConfigFile():
                    data = self.processSensorData.getSensorData()
                    if len(data) > 0:
                        currentTime = time.strftime("%d.%m.%Y %H:%M:%S")
                        message1 = 'Dear Digital Farmer, here is your farm’s status;'
                        message2 = 'Device ID: %s \n Temperature: %s \n Humidity: %s ' % (
                            'SMF001', str(data[0]), str(data[1]))
                        message3 = 'Soil Moisture: %s \n Liters of water irrigated: %s ' % (
                            str(data[2]), str(data[3]))
                        message4 = 'State of Valve: %s \n Battery voltage: %s \n Date and Time: %s' % (
                            str(data[5]), str(data[4]), str(currentTime))
                        self.sim.sendSMS(message1)
                        time.sleep(2)
                        self.sim.sendSMS(message2)
                        time.sleep(2)
                        self.sim.sendSMS(message3)
                        time.sleep(2)
                        self.sim.sendSMS(message4)
                        self.logMessage.log(
                            'Running daily schedule : (message : ' +
                            str(message1) + str(message2) + str(message3) +
                            str(message4) + ' )')
                        self.processSensorData.updateWaterUsed('0')
                        # send alert to arduino to reset water usage value
                        self.writeNumber(self.const.SENSOR_CODE_WATER_RESET)
                        time.sleep(1)
                        water = self.readNumber()
                        self.processSensorData.updateWaterUsed(water)
                    else:
                        self.logMessage.log('No sensor data saved')
                else:
                    self.logMessage.log(
                        'Invalid configuration data / No file found - Daily report'
                    )
            else:
                self.logMessage.log(
                    'Error No SIM Card detected - Daily report')
        except:
            self.logMessage.log('Error in Daily Report')

    def writeNumber(self, value):
        try:
            self.bus.write_byte(self.address, value)
        except:
            pass
        return -1

    def readNumber(self):
        number = 0
        try:
            number = self.bus.read_byte(self.address)
        except:
            pass
        return number
コード例 #15
0
class ReadSensorData:

    logMessage = ''
    const = ''
    processSensorData = ''
    processConfigFile = ''
    GPIOPins = ''
    bus = ''
    address = 0x04

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.processSensorData = ProcessSensorReading()
        self.processConfigFile = ProcessConfigFile()
        self.GPIOPins = GPIOPin()
        self.bus = smbus.SMBus(1)

    def run(self):
        try:
            if self.processConfigFile.checkValuesInConfigFile():
                self.i2cRead()
            else:
                self.logMessage.log('Invalid configuration data / No file found - Read Sensor Data')
                time.sleep(40)
                self.run()
        except:
            self.logMessage.log('Error on reading sensor data frequently')
            time.sleep(40)
            self.run()

    def i2cRead(self):
        try:
            while True:

                self.writeNumber(self.const.SENSOR_CODE_TEMPERATURE)
                time.sleep(1)
                temperature = self.readNumber()
                self.processSensorData.updateTemperature(str(temperature))

                self.writeNumber(self.const.SENSOR_CODE_HUMIDITY)
                time.sleep(1)
                humidity = self.readNumber()
                self.processSensorData.updateHumidity(str(humidity))

                self.writeNumber(self.const.SENSOR_CODE_MOISTURE)
                time.sleep(1)
                moisture = self.readNumber()		
                self.processSensorData.updateMoisture(str(moisture))

                self.writeNumber(self.const.SENSOR_CODE_WATER)
                time.sleep(1)
                water = self.readNumber()		
                self.processSensorData.updateWaterUsed(str(water))

                self.writeNumber(self.const.SENSOR_CODE_BATTERY)
                time.sleep(1)
                battery = self.readNumber()
                self.processSensorData.updateBattery(str(battery))

                # power valve based on soil moisture
                self.checkSoilMoisture(moisture)
        except:
            self.logMessage.log('Error on sending request to Arduino - Read Sensor Data')
            pass

    def checkSoilMoisture(self, moisture):
        try:
            if moisture > 0:
                lowerLimit = self.processConfigFile.readLowerLimit()
                higherLimit = self.processConfigFile.readUpperLimit()
                if moisture < lowerLimit:
                    self.GPIOPins.powerOnValve()
                    self.processSensorData.updateStateOfValve('ON')
                elif moisture > higherLimit:
                    self.GPIOPins.powerOffValve()
                    self.processSensorData.updateStateOfValve('OFF')
        except:
            self.logMessage.log('Error on checking soil moisture - Read Sensor Data')
            pass

    def writeNumber(self, value):
        try:
            self.bus.write_byte(self.address, value)
        except:
            pass
        return -1

    def readNumber(self):
        number = 0
        try:
            number = self.bus.read_byte(self.address)
        except:
            pass
        return number
コード例 #16
0
class DailyReport:

    logMessage = ''
    const = ''
    sim = ''
    messages = ''
    processSensorData = ''
    processConfigFile = ''
    bus = ''
    address = 0x04

    def __init__(self):
        self.logMessage = LogMessage()
        self.const = Constant()
        self.sim = SIMOperations()
        self.messages = Message()
        self.processConfigFile = ProcessConfigFile()
        self.processSensorData = ProcessSensorReading()
        self.bus = smbus.SMBus(1)

    def run(self):
        try:
            if self.sim.checkSIMCard():
                if self.processConfigFile.checkValuesInConfigFile():
                    data = self.processSensorData.getSensorData()
                    if len(data) > 0:
                        currentTime = time.strftime("%d.%m.%Y %H:%M:%S")
                        message1 = 'Dear Digital Farmer, here is your farm’s status;'
                        message2 = 'Device ID: %s \n Temperature: %s \n Humidity: %s ' % ('SMF001', str(data[0]), str(data[1]))
                        message3 = 'Soil Moisture: %s \n Liters of water irrigated: %s ' % (str(data[2]), str(data[3]))
                        message4 = 'State of Valve: %s \n Battery voltage: %s \n Date and Time: %s' % (str(data[5]), str(data[4]), str(currentTime))
                        self.sim.sendSMS(message1)
                        time.sleep(2)
                        self.sim.sendSMS(message2)
                        time.sleep(2)
                        self.sim.sendSMS(message3)
                        time.sleep(2)
                        self.sim.sendSMS(message4)
                        self.logMessage.log('Running daily schedule : (message : ' + str(message1) + str(message2) + str(message3) + str(message4) + ' )')
                        self.processSensorData.updateWaterUsed('0')
                        # send alert to arduino to reset water usage value
                        self.writeNumber(self.const.SENSOR_CODE_WATER_RESET)
                        time.sleep(1)
                        water = self.readNumber()
                        self.processSensorData.updateWaterUsed(water)
                    else:
                        self.logMessage.log('No sensor data saved')
                else:
                    self.logMessage.log('Invalid configuration data / No file found - Daily report')
            else:
                self.logMessage.log('Error No SIM Card detected - Daily report')
        except:
            self.logMessage.log('Error in Daily Report')

    def writeNumber(self, value):
        try:
            self.bus.write_byte(self.address, value)
        except:
            pass
        return -1

    def readNumber(self):
        number = 0
        try:
            number = self.bus.read_byte(self.address)
        except:
            pass
        return number