예제 #1
0
 def evaluate(self):
     if self.__mustTurnOnFence():
         self.on()
         ulogging.info('Fence - electrified')
     elif self.__mustTurnOffFence():
         self.off()
         ulogging.info('Fence - not electrified')
예제 #2
0
 def __evaluateLight(self, name: str, light: PCA9554Relay, fromTime: str,
                     toTime: str):
     if self.__mustTurnOnLight(light, fromTime, toTime):
         light.on()
         ulogging.info('LightControl - {} - on'.format(name))
     elif self.__mustTurnOffLight(light, fromTime, toTime):
         light.off()
         ulogging.info('LightControl - {} - off'.format(name))
예제 #3
0
 def _otaUpdate():
     ulogging.info('Checking for Updates...')
     from .ota_updater import OTAUpdater
     otaUpdater = OTAUpdater('https://github.com/rdehuyss/chicken-shed-mgr',
                             github_src_dir='src',
                             main_dir='app',
                             secrets_file="secrets.py")
     otaUpdater.install_update_if_available()
     del (otaUpdater)
예제 #4
0
    def close(self):
        ulogging.info('DoorOpener - Closing door')

        self.__stopMovement()

        self._hasClosedForToday = True
        self._relayClose.on()
        self._timer = Timer(3)
        self._timer.init(period=50000, mode=Timer.ONE_SHOT, callback=self.__stopClose)
예제 #5
0
 def open(self):
     ulogging.info('DoorOpener - Opening door')
     self._isOpen = True
     
     self.__stopMovement()
     
     self._relayOpen.on()
     self._timer = Timer(3)
     self._timer.init(period=50000, mode=Timer.ONE_SHOT, callback=self.__stopOpen)
예제 #6
0
 def _updateTimeUsingNTP():
     ulogging.info('Updating time...')
     import machine, utime
     from ..hardware.components.ds3231 import DS3231
     rtc = machine.RTC()
     rtc.ntp_sync(server="0.be.pool.ntp.org",
                  tz="CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00")
     ds3231 = DS3231(machine.I2C(freq=400000, sda=21, scl=22))
     ds3231.save_time()
     ulogging.info("Updated time to {}".format(
         utime.strftime('%H:%M:%S', utime.localtime())))
예제 #7
0
 def toggle(self):
     self._toggleTime = self._kippenstal.currentTime
     if self._light1.isOff():
         self._light1.on()
         self._light2.on()
         ulogging.info(
             'LightControl - Lights Toggled Manually - Light 1 & 2 - on')
     else:
         self._light1.off()
         self._light2.off()
         ulogging.info(
             'LightControl - Lights Toggled Manually - Light 1 & 2 - off')
예제 #8
0
    def _sendLogsToGithubGist():
        import os
        if not 'logs.log' in os.listdir():
            return

        ulogging.info('Sending logs to GitHub Gist...')
        import app.secrets as secrets
        from .ota_logger import OTALogger
        o = OTALogger(secrets.GIST_ID, secrets.GIST_ACCESS_TOKEN)
        succeeded = o.log_to_gist('logs.log')
        if succeeded:
            ulogging.info('Sending logs to GitHub Gist succeeded...')
            os.remove('logs.log')
        else:
            ulogging.warn('Sending logs to GitHub Gist failed...')
예제 #9
0
    def _connectToWifi():
        import utime, network, app.secrets as secrets
        from app.utils.httpclient import HttpClient
        ulogging.info('Connecting to WIFI')

        sta_if = network.WLAN(network.STA_IF)
        sta_if.active(True)
        sta_if.connect(secrets.WIFI_SSID, secrets.WIFI_PASSWORD)

        startTime = utime.time()
        while not sta_if.isconnected():
            if startTime + 45 < utime.time():
                break

            utime.sleep(2)
            sta_if.connect(secrets.WIFI_SSID, secrets.WIFI_PASSWORD)
        ulogging.info('Connected to WIFI')
예제 #10
0
    def updateIfNecessary():
        import machine, os
        try:
            with open('.updateRequested', "r") as updateRequested:
                pass

            try:
                os.remove('.updateRequested')
                ulogging.info('Update requested...')
                UpdateUtils._connectToWifi()
                UpdateUtils._updateTimeUsingNTP()
                UpdateUtils._otaUpdate()
                UpdateUtils._sendLogsToGithubGist()
                ulogging.info('Updates finished, will reboot')
            except BaseException as error:
                print(error)
                ulogging.error('Error updating: ' + str(error))
            machine.reset()

        except BaseException as error:
            print(error)
            ulogging.info('No update needed')
            pass
예제 #11
0
 def __stopClose(self, timer):
     self.__stopMovement()
     self._isOpen = False
     ulogging.info('DoorOpener - Door closed')
예제 #12
0
 def __stopOpen(self, timer):
     self.__stopMovement()
     ulogging.info('DoorOpener - Door opened')
예제 #13
0
 def stop(self):
     self.isRunning = False
     ulogging.info('Kippenstal Mgr stopped')
예제 #14
0
 def start(self):
     self.isRunning = True
     ulogging.info('Kippenstal Mgr started')
예제 #15
0
 def off(self):
     self._light1.off()
     self._light2.off()
     ulogging.info(
         'LightControl - Lights Tested Manually - Light 1 & 2 - off')