Exemplo n.º 1
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)
Exemplo n.º 2
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()
Exemplo n.º 3
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)
Exemplo n.º 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()
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 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()
Exemplo n.º 10
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()